Queue Docs
Get Started
Integrations
SDK
Python SDK
Full reference for the Python SDK.
Python SDK
The Python SDK supports both synchronous and async usage and is compatible with asyncio, FastAPI, and Django out of the box.
Creating a Client
Import AgentClient from ai_agent_sdk and initialize with your API key. For async usage, use AsyncAgentClient instead.
Defining Tools
Decorate any Python function with @tool to expose it to the agent. The SDK auto-generates the schema from your function signature and docstring.
Pydantic Support
Pass Pydantic models as tool input/output types for automatic validation and JSON schema generation.
Installation
pip install queue-sdk
For async support: pip install queue-sdk[async]
Synchronous usage
from queue_sdk import QueueClient client = QueueClient() # reads QUEUE_API_KEY from env result = client.agents.run( agent=’refactor-agent’, goal=’Add type hints to all functions in auth.py’, ) print(result.output)
Async usage
from queue_sdk.async_client import AsyncQueueClient client = AsyncQueueClient() async def run(): result = await client.agents.run( agent=’refactor-agent’, goal=’Write pytest tests for the payments module’, ) print(result.output)
Defining tools with decorators
from queue_sdk import tool @tool(description=’Search our internal knowledge base for relevant documentation.’) def search_kb(query: str) -> str: “””Returns the top 3 matching documents as a formatted string.””” return kb_client.search(query)
Queue infers the tool’s schema from the function signature and docstring. Parameter descriptions from the docstring improve the model’s ability to use the tool correctly.
Pydantic input models
For tools with complex inputs, use a Pydantic model as the first argument. Queue generates a full JSON Schema from the model, including field descriptions from Field(description=…).
Streaming
async for event in client.agents.stream(agent=’my-agent’, goal=’…’): if event.type == ‘token’: print(event.data, end=’’, flush=True) elif event.type == ‘done’: print(f’\nFinished in {event.result.steps} steps’)
On this page