API Quick Start#
Get started with the Pantheon Python API.
Installation#
pip install pantheon-agents
Set your API key:
export OPENAI_API_KEY="your-key"
Basic Agent#
import asyncio
from pantheon.agent import Agent
async def main():
agent = Agent(
name="assistant",
instructions="You are a helpful assistant."
)
response = await agent.run("Hello!")
print(response.content)
asyncio.run(main())
With Tools#
from pantheon.agent import Agent
from pantheon.toolsets import FileManagerToolSet, ShellToolSet
async def main():
agent = Agent(
name="developer",
instructions="You are a developer assistant."
)
await agent.toolset(FileManagerToolSet("files"))
await agent.toolset(ShellToolSet("shell"))
response = await agent.run("List files in the current directory")
print(response.content)
Custom Tools#
from pantheon.agent import Agent
agent = Agent(name="calculator", instructions="Do math.")
@agent.tool
def calculate(expression: str) -> float:
"""Evaluate a math expression."""
return eval(expression)
response = await agent.run("What is 15 * 7?")
Interactive Chat#
# Start interactive REPL
await agent.chat()
Teams#
from pantheon.agent import Agent
from pantheon.team import PantheonTeam
researcher = Agent(name="researcher", instructions="Research topics.")
writer = Agent(name="writer", instructions="Write content.")
team = PantheonTeam([researcher, writer])
response = await team.run("Write about AI safety")
print(response.content)
Streaming#
async for chunk in agent.stream("Tell me a story"):
print(chunk.content, end="", flush=True)
Memory#
# Enable memory persistence
agent = Agent(
name="assistant",
instructions="...",
use_memory=True
)
# Conversations are saved and can be resumed
Common Patterns#
Error Handling
try:
response = await agent.run("...")
except Exception as e:
print(f"Error: {e}")
Timeout
response = await asyncio.wait_for(
agent.run("..."),
timeout=60.0
)
Multiple Queries
queries = ["Q1", "Q2", "Q3"]
responses = await asyncio.gather(
*[agent.run(q) for q in queries]
)
Next Steps#
Agent API - Full Agent API
Team API - Team patterns
Toolsets API - Available toolsets