This advanced section extends the existing materials/agents.md reference with an exercise on tool-assisted chain-of-thought planning and structured agent decision-making.
reasoning context.web_search, math_calc, db_query).from agents import Agent, Tool
# 1. define tools
@Tool
def web_search(query: str) -> str:
# use provider SDK, return top-summary
return external_search(query)
@Tool
def calculator(expression: str) -> str:
return str(eval(expression))
# 2. agent instructions
agent = Agent(
name="chain_of_thought_agent",
model="gpt-4o",
instructions="""
You are an assistant that uses explicit step-by-step reasoning. Always include a reasoning section with numbered steps. When invoking tools, annotate your decision.
Use this structure:
1. Thought:
2. Action:
3. Observation:
4. ...
5. Final Answer:
""",
tools=[web_search, calculator],
)
# 3. request
prompt = "Plan a 3-step strategy to improve local library attendance using data and budget estimates."
result = agent.run(prompt)
print(result)
agents_advanced.py implementation