Quick Start
This guide will get you up and running with a simple AI agent in minutes.
1. Setup API Keys
Create a .env file in your project root and add your API keys:
OPENAI_API_KEY=sk-...
GEMINI_API_KEY=AIza...
ANTHROPIC_API_KEY=sk-ant...
2. Create Your First Agent
Here is a simple example using OpenRouter (which supports many models). You can replace OpenRouterClient with OpenAIClient, GeminiClient, etc.
import os
from dotenv import load_dotenv
from agent_sdk import Runner, Agent, OpenRouterClient
# 1. Load Environment Variables
load_dotenv()
# 2. Initialize Client and Runner
client = OpenRouterClient(api_key=os.getenv("OPENRouter_API_KEY"))
runner = Runner(client)
# 3. Define the Agent
assistant = Agent(
name="Assistant",
model="mistralai/mistral-7b-instruct",
instructions="You are a helpful assistant who answers concisely."
)
# 4. Run the Agent (Streaming)
print(f"Chatting with {assistant.name}...
")
stream = runner.run_stream(assistant, "Hello! Who are you?")
for event in stream:
if event.type == "token":
print(event.data, end="", flush=True)
elif event.type == "final":
print("\n\n[Done]")
3. What Just Happened?
- Client: We initialized a client to communicate with the LLM provider.
- Runner: The
Runnerclass manages the conversation loop, tool execution, and memory. - Agent: We defined an
Agentwith a name, a specific model, and system instructions. - Streaming:
runner.run_streamreturns a generator that yields events (tokens, tool calls, errors) in real-time.
Next Steps
- Learn about Universal Clients to use different providers.
- Explore Agents & Runners for more configuration options.
- Add Tools to give your agent capabilities like web search or file access.