Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

dbschmigelski
Copy link
Member

Description

A customer brought up the following concern regarding using structured_output on an agent.

If I use the alternate method, first go through one agent loop using result = agent(user_message)  and then agent.structured_output(<pydantic model>, result) , then there are 2 problems -
Won’t passing the result again as a “prompt” pollute the context window?
{ignore problem 2}

Adding the prompt to the conversation history seems like a bug. We are indicating that we want a particular message structured, but we never add the result to the conversation history.

So, we can either not append or we can add the result of the structuring after it is complete. I am biased towards the former. This is because structured output is not an action taken by the agent. Rather, it is more similar to a utility function for the user to format the result of an agent invocation. The structuring of the output is not itself an invocation in the same sense - especially since it is making a model request with only a single, non-user defined, tool.

Documentation PR

No documentation updates needed after inspecting https://strandsagents.com/latest/documentation/docs/user-guide/concepts/agents/structured-output/

Type of Change

Bug fix

Testing

How have you tested the change? Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

  • I ran hatch run prepare

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@dbschmigelski dbschmigelski merged commit adac26f into strands-agents:main Aug 8, 2025
12 checks passed
@jwhitecl
Copy link

Hey! I think this change broke my application. The interaction pattern I was using looks like this:

agent = Agent(...)
judge = Agent(...)

# This agent makes a number of tool calls to produce the output, and is passed some information in the prompt
output = agent.structured_output(...)
# This is just a summary - actual prompting is more involved
eval_result = judge.structured_output("evaluate this: " + output) 

output("Fix the output with this feedback: " + eval_result)

Now that no conversation history is maintained when using structured output, the agent has no record of the previous output. I'm questioning whether its the right thing to really store no message history here.

dbschmigelski added a commit to dbavro19/sdk-python that referenced this pull request Aug 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants