create_react_agent with structured output ignores last agent message #4318
Closed
adamlundqvist
started this conversation in
Ideas
Replies: 2 comments 5 replies
-
@adamlundqvist that has already been resolved in the most recent versions - please update to the latest version of we'll make sure to bundle the latest version in |
Beta Was this translation helpful? Give feedback.
3 replies
-
This may cause the problem: Prefix can not work with json mode. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I like the create_react_agent because it is simple to get to a first draft when building agent. Now that it provides structured output, it is even more valuable.
But I can't understand why the generate_structured_response in the agent ignores the last message from the react agent. This seems counter productive as the agent typically should return the summary of its work in the last message. The current implementation ignores that summary and (at least for my view of agents) makes the structured output unusable.
Here the related code from create_react_agent:
def generate_structured_response(
state: StateSchema, config: RunnableConfig
) -> StateSchema:
# NOTE: we exclude the last message because there is enough information
# for the LLM to generate the structured response
messages = _get_state_value(state, "messages")[:-1]
structured_response_schema = response_format
if isinstance(response_format, tuple):
system_prompt, structured_response_schema = response_format
messages = [SystemMessage(content=system_prompt)] + list(messages)
It would imho be a significant improvement to not ignore the last message from the agent.
Beta Was this translation helpful? Give feedback.
All reactions