Skip to main content

Agent

Write agent logic once. Run it anywhere. Switch providers anytime.

Agent is a clean Python runtime for multi-provider LLM apps and agent workflows. One elegant, provider-agnostic interface for building LLM applications and tool-using agents.

Features

  • One API, Many Providers: OpenAI, Anthropic, Gemini, DeepSeek, and more
  • Provider Portability: Switch providers with minimal code changes
  • Structured Outputs: Pydantic-based typed responses
  • Tool Calling: Register Python functions as tools with automatic schema generation
  • Sessions: Multi-turn conversations with pluggable persistence
  • Streaming: Normalized streaming events across providers
  • Routing & Fallback: Automatic failover and smart routing strategies
  • Middleware: Extensible hooks for logging, tracing, and policy control

Installation

pip install agent-core-py

# With provider extras
pip install agent-core-py[openai]
pip install agent-core-py[anthropic]
pip install agent-core-py[all]

Quick Start

from agent import Agent

# Create an agent
agent = Agent(
    provider="anthropic",
    model="claude-sonnet-4-20250514",
)

# Simple text generation
response = agent.run("Explain quantum computing in one paragraph")
print(response.text)

Structured Outputs

from pydantic import BaseModel
from agent import Agent

class Summary(BaseModel):
    title: str
    bullets: list[str]
    sentiment: str

agent = Agent(provider="openai", model="gpt-4o")
response = agent.json("Summarize this article about AI progress", schema=Summary)
print(response.output)  # Typed Summary object

Tool Calling

from agent import Agent, tool

@tool
def search_code(query: str) -> str:
    """Search the codebase for matching patterns."""
    # Your implementation
    return f"Found 5 matches for: {query}"

@tool
def read_file(path: str) -> str:
    """Read contents of a file."""
    with open(path) as f:
        return f.read()

agent = Agent(
    provider="anthropic",
    model="claude-sonnet-4-20250514",
    tools=[search_code, read_file],
)

response = agent.run("Find all TODO comments in the codebase")

Sessions

from agent import Agent

agent = Agent(provider="openai", model="gpt-4o")

# Create a session for multi-turn conversation
session = agent.session()
session.run("My name is Alice")
response = session.run("What's my name?")
print(response.text)  # "Your name is Alice"

Streaming

from agent import Agent

agent = Agent(provider="anthropic", model="claude-sonnet-4-20250514")

for event in agent.stream("Write a short poem about coding"):
    if event.type == "text_delta":
        print(event.text, end="", flush=True)

Router & Fallback

from agent import AgentRouter

router = AgentRouter(
    agents=[
        Agent(provider="anthropic", model="claude-sonnet-4-20250514"),
        Agent(provider="openai", model="gpt-4o"),
    ],
    strategy="fallback",
)

# Automatically falls back if first provider fails
response = router.run("Hello, world!")

Middleware

from agent import Agent, Middleware

class LoggingMiddleware(Middleware):
    def before(self, request):
        print(f"Request: {request.input[:50]}...")
        return request
    
    def after(self, request, response):
        print(f"Response: {response.text[:50]}...")
        return response

agent = Agent(
    provider="openai",
    model="gpt-4o",
    middleware=[LoggingMiddleware()],
)

Configuration

from agent import Agent

# Explicit configuration
agent = Agent(
    provider="openai",
    model="gpt-4o",
    api_key="sk-...",
    timeout=120.0,
    max_retries=3,
    temperature=0.7,
)

# Or use environment variables
# OPENAI_API_KEY, ANTHROPIC_API_KEY, etc.
agent = Agent(provider="openai", model="gpt-4o")

CLI

# Quick chat
agent chat --provider openai --model gpt-4o

# Single prompt
agent run "What is the capital of France?" --provider anthropic

# List providers
agent providers

# Test configuration
agent doctor

Supported Providers

Provider Text Streaming Tools Structured Output Vision
OpenAI Yes Yes Yes Yes Yes
Anthropic Yes Yes Yes Yes Yes
Gemini Yes Yes Yes Yes Yes
DeepSeek Yes Yes Yes Yes No

Documentation

Documentation

Full docs at agent-core.readthedocs.io.

Contributing

See CONTRIBUTING.md for development setup and guidelines.

License

MIT License - see LICENSE for details.

Metadata

Release files for agent-core-py 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agent-core-py 0.1.0
File Size Uploaded
agent_core_py-0.1.0.tar.gz 134.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agent-core-py 0.1.0
File Interpreter ABI Platform
agent_core_py-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 194.0 kB

Release files / agent_core_py-0.1.0.tar.gz

Download URL agent_core_py-0.1.0.tar.gz
Size 134.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2ee8bb44395cad4c165bf900d20a32ac5f874d6ef843018c5cc9576cb7c1d35d
BLAKE2b-256 checksum
How to use checksums
fe18438f1e284efc375e697cf11b2c2c003004472089d4c694aefcc744024f48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 21, 2026.

Transparency log

Release files / agent_core_py-0.1.0-py3-none-any.whl

Download URL agent_core_py-0.1.0-py3-none-any.whl
Size 59.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3abbf45eac84c4407bd19f34935dd97fad8accd209d1dec6ca0844bb340a6bcf
BLAKE2b-256 checksum
How to use checksums
fc2109d31a49e7f11707ec53b92a39eff8706ae30ad0c3890d7eff3be4e0367d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 21, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page