Set your LLM provider API key as an environment variable:
Copy
Ask AI
# For OpenAIexport OPENAI_API_KEY="your-api-key-here"# For Anthropicexport ANTHROPIC_API_KEY="your-api-key-here"# For Googleexport GEMINI_API_KEY="your-api-key-here"
Create a simple weather agent that can answer questions about the weather:
Copy
Ask AI
from agentor import Agentoragent = Agentor( name="Weather Agent", model="gpt-4o-mini", tools=["get_weather"])# Run the agentresult = agent.run("What is the weather in London?")print(result)
The get_weather tool is a built-in tool that uses the WeatherAPI.com service. You’ll need to set the WEATHER_API_KEY environment variable to use it.
import asynciofrom agentor import Agentoragent = Agentor( name="Weather Agent", model="gpt-4o-mini", tools=["get_weather"])async def main(): async for event in agent.stream_chat("What is the weather in Tokyo?"): print(event, flush=True)asyncio.run(main())
Guide your agent’s behavior with custom instructions:
Copy
Ask AI
from agentor import Agentoragent = Agentor( name="Weather Bot", model="gpt-4o-mini", instructions="You are a friendly weather assistant. Always include temperature in both Celsius and Fahrenheit.", tools=["get_weather"])result = agent.run("How's the weather in Paris?")print(result)
Combine multiple tools to create more capable agents:
Copy
Ask AI
from agentor import Agentor, function_tool@function_tooldef calculate_temperature_diff(temp1: float, temp2: float) -> str: """Calculate the temperature difference between two values.""" diff = abs(temp1 - temp2) return f"The temperature difference is {diff}°F"agent = Agentor( name="Weather Analyzer", model="gpt-4o-mini", tools=["get_weather", calculate_temperature_diff])result = agent.run("What's the temperature difference between London and Paris?")print(result)
Turn your agent into a REST API with a single line:
Copy
Ask AI
from agentor import Agentoragent = Agentor( name="Weather Agent", model="gpt-4o-mini", tools=["get_weather"])# Serve the agent on port 8000agent.serve(port=8000)
This creates a FastAPI server with these endpoints:
POST /chat - Send messages to the agent
GET /.well-known/agent-card.json - A2A protocol agent card
from agentor import Agentor, ModelSettingsagent = Agentor( name="Creative Writer", model="gpt-4o", model_settings=ModelSettings( temperature=0.9, # More creative max_tokens=2000, top_p=0.95 ), tools=[])result = agent.run("Write a short story about a robot learning to paint")print(result)