Python SDK
The Python SDK is a fully async client for building agents on the Athyr platform. It provides the same orchestration patterns, middleware, and resilience features as the Go SDK, designed for Python’s async/await paradigm.
Installation
pip install git+https://github.com/athyr-tech/athyr-sdk-python.git
Requires Python 3.10+ and a running Athyr server.
Quick Start
import asyncio
from athyr import AthyrAgent, AgentCard, CompletionRequest, Message
async def main():
async with AthyrAgent(
"localhost:9090",
agent_card=AgentCard(name="my-agent", description="My first Athyr agent"),
) as agent:
resp = await agent.complete(CompletionRequest(
model="llama3",
messages=[Message(role="user", content="Hello!")]
))
print(resp.content)
asyncio.run(main())
Features
Core Agent
- Connect/Disconnect — Lifecycle management with automatic reconnection
- Pub/Sub Messaging — Subscribe to subjects, publish messages, request/reply
- LLM Completions — Blocking and streaming completions via Athyr backends
- Memory Sessions — Conversation context with automatic summarization
- KV Storage — Key-value buckets for agent state
- Tool Calling — Decorator-based function calling support
Orchestration Patterns
Located in athyr.orchestration:
| Pattern | Description |
|---|---|
| Pipeline | Sequential agent chain (A → B → C) |
| FanOut | Parallel execution with aggregation |
| Handoff | Dynamic routing via triage agent |
| GroupChat | Multi-agent collaborative discussion |
Middleware
recover— Exception recoverytimeout— Request timeoutsretry— Automatic retries with backofflog_requests— Request/response logging- Custom middleware via
@middlewaredecorator
Tool Calling
Define tools with the @tool decorator:
from athyr import tool, ToolRegistry, run_tool_loop
@tool(description="Get weather for a city")
def get_weather(city: str, unit: str = "celsius") -> str:
return f"Weather in {city}: sunny"
registry = ToolRegistry()
registry.register(get_weather)
response = await run_tool_loop(agent, request, registry)
Documentation
Full documentation and examples are maintained in the SDK repository:
- SDK README — Complete feature guide
- Examples — Working code samples
Available Examples
| Example | Demonstrates |
|---|---|
| quickstart | Basic agent setup |
| streaming | Streaming LLM responses |
| messaging | Pub/sub and request/reply |
| tool_calling | LLM function calling |
| chat_agent | Memory sessions |
| pipeline | Sequential orchestration |
| fanout | Parallel execution |
| groupchat | Multi-agent collaboration |
| handoff | Dynamic routing via triage |
| resilient_agent | Error handling and retries |
Next Steps
- Agents — Agent concepts and lifecycle
- LLM Gateway — LLM provider configuration
- State Management — Memory and KV details