Providers¶
Agent provides a unified interface across multiple LLM providers. This guide covers provider configuration, capabilities, and best practices.
Supported Providers¶
Provider |
Text |
Streaming |
Tools |
Structured Output |
Vision |
|---|---|---|---|---|---|
OpenAI |
Yes |
Yes |
Yes |
Yes (native) |
Yes |
Anthropic |
Yes |
Yes |
Yes |
Yes |
Yes |
Gemini |
Yes |
Yes |
Yes |
Yes (native) |
Yes |
DeepSeek |
Yes |
Yes |
Yes |
Yes |
No |
OpenAI¶
Setup¶
pip install agent-core-py[openai]
export OPENAI_API_KEY="sk-..."
Usage¶
from agent import Agent
agent = Agent(
provider="openai",
model="gpt-4o", # or "gpt-4o-mini", "gpt-4-turbo", "gpt-3.5-turbo"
)
Available Models¶
Model |
Alias |
Context |
Best For |
|---|---|---|---|
gpt-4o |
|
128K |
Complex tasks, vision |
gpt-4o-mini |
|
128K |
Fast, cost-effective |
gpt-4-turbo |
|
128K |
Complex reasoning |
gpt-3.5-turbo |
|
16K |
Simple tasks |
OpenAI-Specific Features¶
Native JSON Schema:
# OpenAI supports native schema-enforced output
response = agent.json("Extract data", schema=MyModel)
# Uses response_format with json_schema
Vision:
from agent import Message, ContentPart
message = Message.user([
ContentPart.text_part("What's in this image?"),
ContentPart.image_url_part("https://example.com/image.jpg"),
])
response = agent.run(messages=[message])
Anthropic¶
Setup¶
pip install agent-core-py[anthropic]
export ANTHROPIC_API_KEY="sk-ant-..."
Usage¶
from agent import Agent
agent = Agent(
provider="anthropic",
model="claude-sonnet-4-20250514", # or use alias "claude-sonnet"
)
Available Models¶
Model |
Alias |
Context |
Best For |
|---|---|---|---|
claude-opus-4-20250514 |
|
200K |
Complex analysis |
claude-sonnet-4-20250514 |
|
200K |
Balanced performance |
claude-3-5-haiku-20241022 |
|
200K |
Fast responses |
Anthropic-Specific Features¶
Long Context:
# Claude supports very long contexts (200K tokens)
agent = Agent(provider="anthropic", model="claude-sonnet")
response = agent.run(very_long_document)
System Prompts:
# Anthropic handles system prompts separately
response = agent.run(
"Analyze this code",
system="You are an expert code reviewer. Be thorough and constructive."
)
Google Gemini¶
Setup¶
pip install agent-core-py[gemini]
export GOOGLE_API_KEY="..."
Usage¶
from agent import Agent
agent = Agent(
provider="gemini",
model="gemini-1.5-pro", # or "gemini-1.5-flash"
)
Available Models¶
Model |
Alias |
Context |
Best For |
|---|---|---|---|
gemini-1.5-pro |
|
1M |
Complex tasks |
gemini-1.5-flash |
|
1M |
Fast, efficient |
Gemini-Specific Features¶
Million Token Context:
# Gemini supports up to 1M tokens
agent = Agent(provider="gemini", model="gemini-pro")
response = agent.run(enormous_document)
DeepSeek¶
Setup¶
pip install agent-core-py[deepseek]
export DEEPSEEK_API_KEY="..."
Usage¶
from agent import Agent
agent = Agent(
provider="deepseek",
model="deepseek-chat", # or "deepseek-coder"
)
Available Models¶
Model |
Alias |
Best For |
|---|---|---|
deepseek-chat |
|
General conversation |
deepseek-coder |
|
Code generation |
Custom Endpoints¶
Use OpenAI-compatible APIs:
from agent import Agent
# Azure OpenAI
agent = Agent(
provider="openai",
model="gpt-4",
base_url="https://your-resource.openai.azure.com/openai/deployments/your-deployment",
api_key="your-azure-key",
)
# Local LLM (Ollama, vLLM, etc.)
agent = Agent(
provider="openai",
model="llama2",
base_url="http://localhost:11434/v1",
api_key="not-needed",
)
Provider Capabilities¶
Check what a provider supports at runtime:
from agent import Agent
agent = Agent(provider="openai", model="gpt-4o")
# Check capabilities via the provider
print(agent._provider.supports_tools()) # True
print(agent._provider.supports_streaming()) # True
print(agent._provider.supports_vision()) # True
print(agent._provider.supports_structured_output()) # True
print(agent._provider.supports_native_schema()) # True
Provider-Agnostic Code¶
Write code that works across providers:
from agent import Agent
def analyze_text(text: str, provider: str = "openai") -> str:
"""Analyze text using any provider."""
models = {
"openai": "gpt-4o",
"anthropic": "claude-sonnet",
"gemini": "gemini-pro",
"deepseek": "deepseek-chat",
}
agent = Agent(
provider=provider,
model=models[provider],
temperature=0.3, # Works across all providers
)
return agent.run(f"Analyze: {text}").text
Cost Optimization¶
Agent tracks usage and estimates costs:
response = agent.run("Hello!")
print(f"Prompt tokens: {response.usage.prompt_tokens}")
print(f"Completion tokens: {response.usage.completion_tokens}")
print(f"Estimated cost: ${response.cost_estimate:.6f}")
Use the router for cost-optimized routing:
from agent import Agent, AgentRouter
router = AgentRouter(
agents=[
Agent(provider="openai", model="gpt-4o-mini"), # Cheapest
Agent(provider="anthropic", model="claude-haiku"),
Agent(provider="openai", model="gpt-4o"), # Most expensive
],
strategy="cheapest", # Use cheapest available
)
Next Steps¶
Tools - Register functions as LLM tools
Structured Outputs - Type-safe responses
Routing - Multi-provider fallback