You stream the answer to the user.
Only after the stream ends do you notice the model actually wanted to call a tool.
- AKeep streaming, and if a tool call shows up afterwards, append its result to the text already shown and let the user read the combined answer
- BRead the stream’s stop reason and handle the tool turn BEFORE treating any text as the final answer
- CRaise max_tokens so the model finishes its thought
- DAlways make a separate non-streaming call first to decide about tools
Answer: B
Read the stream’s stop reason and handle the tool turn BEFORE treating any text as the final answer
Why
A stream is not the answer, it is a transcript of a turn that has an outcome. The stop reason is that outcome; a doubled call pays twice for information the first stream already carried.
More on Way of the Agent
- Course programThe first three modules are free: start in the browser or the app, no card needed.
- Library: guides, skills and promptsReady prompt templates, grouped into collections.
- AI ChroniclesSourced stories from the history of AI.
- ConceptsPlain-language explainers of agent engineering.
- Learn AI agentsApps and courses for learning AI agents, compared honestly.
Real situations from building agents - with the answer and why.
Solve a new one every day on the Path