
/root/code. We’ll:
- Start with a compact agent implementation that calls a single
check_calendartool. - Modify the system prompt to require Thought/Observation lines (the ReAct style).
- Add a second tool (
search_contacts) and show a multi-step interaction. - Summarize best practices and include a tool reference table.
1) Minimal agent that calls a single tool
Createreact_agent.py with this simple agent loop that supports one tool: check_calendar(day). The model may call the tool, and the agent dispatches to the local function and appends the tool result back into the conversation. At this stage, the model does not reveal its chain-of-thought.
check_calendar and return a final answer, but its internal reasoning will be hidden.
Example console output (chain-of-thought not visible):
2) Make the model reveal its reasoning: add a ReAct system prompt
To force the model to expose its internal loop, replace the simple system prompt with explicit ReAct instructions that require the model to write aThought: line before each tool call and an Observation: line after every tool result.
Update the messages list as shown:
check_calendar tool. The model will produce a visible Thought line, a tool call, and an Observation line before the final answer. Example illustrative output:
3) Add a second tool for multi-step tasks
Next, implementsearch_contacts(name) and extend the tools list and dispatch logic so the agent can perform multi-step workflows that require both tools (e.g., check calendar then look up a contact).
Add the contact-search function and extend tools:
while True loop to handle both function names:
4) Tool reference (quick lookup)
Note: When documenting parameter examples or small JSON objects in tables, keep them inline code as shown above so MDX doesn’t mis-parse them.
5) Best practices and tips
- Always include clear tool descriptions (name, parameters, required fields) so the model understands available actions.
- Append tool results as
role: "tool"messages so the model can observe outcomes and continue reasoning. - Use the ReAct system prompt pattern for transparent multi-step reasoning:
- Thought: state your reasoning
- [tool_call] run the tool
- Observation: report the tool’s output
- Repeat until confident to answer
- Use ReAct for debugging and audits: it makes decision steps explicit and easier to verify.
Summary
- ReAct exposes model reasoning in the agent loop using Thought → Act → Observation → (repeat).
- Add function/tool descriptions to the agent (so the model knows what it can call).
- Append tool results as
role: "tool"conversation messages so the model can observe and continue reasoning. - The ReAct pattern is especially helpful for debugging multi-step agent behavior.
- ReAct paper: https://arxiv.org/abs/2210.03629
- OpenAI function calling & agents guide: https://platform.openai.com/docs/guides/gpt/function-calling
Use the ReAct system prompt whenever you want the model to make its intermediate reasoning and tool usage explicit. This is especially helpful for debugging multi-step agent behavior.