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.
from agentor import Agentor

agent = Agentor(
    name="Weather Agent",
    model="gpt-5-mini",
)
result = agent.run("What is the weather in London?")
print(result)

Connect to a tool

Agents has access to tools to perform tasks and get information from the world. You can define your own tools or use the ones provided by Celesto AI ToolHub.
from agentor import Agentor

agent = Agentor(
    name="Weather Agent",
    model="gpt-5-mini",
    tools=["get_weather"],  # 100+ Celesto AI managed tools — plug-and-play
)
result = agent.run("What is the weather in London?")
print(result)

Stream the response

You can stream the response from the Agent with the stream method.
from agentor import Agentor
import asyncio

agent = Agentor(name="Weather Agent", tools=["get_weather"])

async def main():
    async for event in agent.stream_chat(
        "How is the weather in Tokyo?",
    ):
        print(event, flush=True)

if __name__ == "__main__":
    asyncio.run(main())
The response is streamed as a JSON object with the following fields:
  • type: The type of event.
  • message: The message from the Agent.
  • chunk: The chunk of the message.
  • tool_action: The tool action from the Agent.
  • reasoning: The reasoning from the Agent.
  • raw_event: The raw event from the Agent.

Serve the Agent

Agents can be deployed as REST API server so you can query them from your applications or integrate them into your existing infrastructure. Agentor makes it easy to serve the Agents by providing a simple serve method.
from agentor import Agentor

agent = Agentor(name="Weather Agent", model="gpt-5-mini", tools=["get_weather"])
agent.serve(port=8000)   
To query your Agent server:
import requests

URL = "http://localhost:8000/chat"

response = requests.post(
    URL,
    json={"input": "how are you?"},
    headers={"Content-Type": "application/json"}
)
print(response.content)