from opperai.agent import Agent, Hooks, tool
hooks = Hooks(
on_agent_start=lambda ctx: print(f'-> {ctx["agent"]}: {ctx["input"]}'),
on_tool_start=lambda ctx: print(f' tool {ctx["name"]}({ctx["input"]})'),
on_tool_end=lambda ctx: print(f' -> {ctx["output"]} ({ctx["duration_ms"]:.0f}ms)'),
on_agent_end=lambda ctx: print(
f'<- done in {ctx["result"].meta.iterations} iterations'
if ctx.get("result") else f'<- failed: {ctx.get("error")}'
),
)
agent = Agent(name="city-expert", instructions="...", tools=[lookup_city], hooks=hooks)