Skip to main content

Build an Agent

Use the Agentor class to initialize an Agent providing the name, instructions, and tools. You can run the Agent with the run method or stream the response with the stream method.
GetWeatherTool() reads a free WeatherAPI.com key from WEATHER_API_KEY, and raises if it is not set.

Connect to a tool

Agents has access to tools to perform tasks and get information from the world.
Learn more about LLM tool use here.
You can define your own tools or use the ones provided by Celesto AI ToolHub.

Stream the response

You can stream the response from the Agent with the stream method.
Each event is a JSON object with the following fields:
  • type: always run_item_stream_event.
  • message: text — a tool’s return value, or the agent’s answer.
  • tool_action: name and type for a tool call (tool_called) or its result (tool_output).
  • chunk: reserved, always null.
  • reasoning: reserved, always null.
  • raw_event: reserved, always null.
stream_chat streams steps, not tokens. For token-by-token text, see token-level streaming.

Tracing and observability

Agentor supports tracing out of the box. Traces capture agent runs and tool calls so you can inspect them in Celesto.
1

Set your Celesto API key

Add your Celesto API key to the environment.
2

Enable tracing

Choose the setup that fits your workflow.
After you run the agent, open the Celesto dashboard to view the trace.

Troubleshooting tracing setup

  • Confirm you set CELESTO_API_KEY in the same environment where you run the agent.
  • Confirm you opted in with enable_tracing=True, an explicit tracer=, or tracing=True on the call - tracing is off by default.
  • A failed upload is logged as a warning, never raised. Turn on warning-level logging to see it.
See Tracing for the full span model and custom endpoints.

Next steps

Structured output

Return a validated Pydantic object instead of free text.

Durable runs

Save a run so another process can finish it after a crash.

Model providers

Point the agent at OpenRouter, Groq, Ollama, or any compatible endpoint.

Tool use

Build custom tools and connect MCP servers.
Last modified on July 30, 2026