Skip to content

Conversation

@jsibbison-square
Copy link
Contributor

Scenario

When using structured output in a recipe and the agent completes its reply without calling the final_output tool. The agent will immediately be triggered to try again until it does call the final_output tool.

Problem

When this scenario occurs we create a user message telling the agent to call the final_output tool. This is yielded from the agent loop so users see it. However the problem was that this message was not being added to the messages vector, therefore the agent never saw this correctional guidance.

This can result in the agent repeating its mistake multiple times or taking entirely different trajectories rather than immediately fixing itself and calling the final_output tool on the next turn.

Fix

Append the correction message to messages vector so agent loop sees it on next turn.

I've also updated the tool prompt a little but cannot tell if has helped.

Steps to reproduce

Non deterministic.

I've found o3 model with a recipe that tells it to output markdown manages to make it not do the tool call maybe 25% of the time which is enough to demonstrate the issue. Attached the recipe, you should notice it fixing itself on the next turn.

output_fail.txt

@jsibbison-square jsibbison-square marked this pull request as ready for review September 16, 2025 12:52
@alexhancock alexhancock self-requested a review September 16, 2025 16:40
@jsibbison-square jsibbison-square merged commit 7f51e07 into main Sep 16, 2025
11 checks passed
@jsibbison-square jsibbison-square deleted the jsibbison-20250916-final_output_last_text branch September 16, 2025 21:53
@alexhancock alexhancock mentioned this pull request Sep 23, 2025
HikaruEgashira pushed a commit to HikaruEgashira/goose that referenced this pull request Oct 3, 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