mirror of
https://github.com/langchain-ai/langserve.git
synced 2026-07-18 10:54:29 -04:00
Bug: AgentExecutor configurable does not propagate configuration from agent. #86
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @eyurtsev on GitHub (Jan 5, 2024).
Originally assigned to: @eyurtsev on GitHub.
Users reasonably expect that when an agent is configurable, then the configuration information is properly propagated via the Agent Executor. However, this is not the case at the moment.
Bug is shown here: https://github.com/langchain-ai/langserve/pull/376
Needs to be fixed in langchain.
Original issue here: https://github.com/langchain-ai/langserve/issues/314
@Sinnaeve commented on GitHub (Jun 6, 2024):
Will this be fixed ? There is no new activity so I'm not sure if an alternative exist for configurable_fields with agent.
Currently using langchain.version='0.2.1',
I basically want to configure the prompt at runtime so I can update the promps uses by the model without re-deploying the app.
Concretely during per_req_config, I get the prompt template from an api (with cache) and use a configurable field to pass it to the agent.
It works with a chain like that:
But i doesn't work with an agent
with an agent created with:
it doesn't work.
the solution proposed in https://github.com/langchain-ai/langserve/blob/main/examples/configurable_agent_executor/server.py doesn't seems to work either for this.
Is there an alternative way to do this I didn't see ?, or maybe agent aren't relevant now and have equivalent in langgraph that works with config fields ?
I could make it work in a notebook, but the change I needed to make were quite complicated:
There is a first issue that is the prompt.partial called in create_sql_agent break the configurable field.
an example of .partial calls is:
This first issue is easy to fix I just modify create_sql_agent to do after the part where it does .partial calls
But then there is a second issue, which is that AgentExecutor and RunnableMultiActionAgent pass the callbacks field of the config but not the configurable field when making the chain calls.
For example if we do
astreamAgentExecutorIteratorobject passing field from the config like callbacks, metadata... but not configurable. Then it iter throughAgentExecutorIteratorAgentExecutorIterator.__aiter__is called which will callself.agent_executor._aiter_next_stepagain without the configurable field that it doesn't have.AgentExecutor._aiter_next_stepis called which callsself.agent.aplanagain without the config even so it pass the callbacksRunnableMultiActionAgent.aplanis called, which callsself.runnable.astreamhererunnable.astreamcan take a config field but onlyconfig={"callbacks": callbacks}is given. it would work by giving{"callbacks": callbacks, "configurable":configurable}but we didn't pass the configurable field.So this second issue of configurable field not passed is more problematic to me. I can patched all those function to pass configurable field with minimal code but it seems complicated to maintain as they will probably change in te future again.
And I have to patch many functions. For the agent.astream endpoint here I have to patch:
AgentExecutor.astreamAgentExecutorIterator.__aiter__AgentExecutor._aiter_next_stepRunnableMultiActionAgent.aplanbut then for non async version I need to change:
AgentExecutor.streamAgentExecutorIterator.__iter__AgentExecutor._iter_next_stepRunnableMultiActionAgent.planand for invoke I have to additionally change:
AgentExecutor.invokeAgentExecutor._calls(+ async versions for ainvoke)