change return of LLMChain.run/2 - breaking change #170
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
LLMChain.run/2
%LLMChain{last_message: last_message}
%LLMChain{exchanged_messages: exchanged_messages}
.This is a breaking change. Let's cover why this is being done and how to adapt to it.
Why the change
Before this change, an
LLMChain
'srun
function returned{:ok, updated_chain, last_message}
.When an assistant (ie LLM) issues a ToolCall and when
run
is in the mode:until_success
or:while_need_response
, theLLMChain
will automatically execute the function and return the result as a new Message back to the LLM. This works great!The problem comes when an application needs to keep track of all the messages being exchanged during a run operation. That can be done by using callbacks and sending and receiving messages, but that's far from ideal. It makes more sense to have access to that information directly after the
run
operation completes.What this change does
This PR changes the returned type to
{:ok, updated_chain}
.The
last_message
is available inupdated_chain.last_message
. This cleans up the return API.This change also adds
%LLMChain{exchanged_messages: exchanged_messages}
,orupdated_chain.exchanged_messages
which is a list of all the messages exchanged between the application and the LLM during the execution of therun
function.This breaks the return contract for the
run
function.How to adapt to this change
To adapt to this, if the application isn't using the
last_message
in{:ok, updated_chain, _last_message}
, then delete the third position in the tuple. Ex:{:ok, updated_chain}
.Access to the
last_message
is available on theupdated_chain
.NOTE: that the
updated_chain
now includesupdated_chain.exchanged_messages
which can also be used.