Overview

The Agent class is the primary abstraction in djangosdk. An agent encapsulates a provider, a model, a system prompt, tools, and any configuration needed to handle a request.

Defining an Agent

Subclass Agent and declare class attributes:

from djangosdk.agents.base import Agent
from djangosdk.providers.schemas import ReasoningConfig

class MyAgent(Agent):
    provider = "openai"             # From AI_SDK.PROVIDERS
    model = "gpt-4.1"
    system_prompt = "You are a helpful assistant."
    temperature = 0.7               # Default: 0.7
    max_tokens = 2048               # Default: 2048
    enable_cache = True             # Enable prompt caching
    max_tool_iterations = 10        # Max tool-call rounds per turn
    tools = []                      # List of @tool functions or BaseTool instances
    reasoning = None                # ReasoningConfig for reasoning models
    mcp_servers = []                # MCP server configs (Phase 2)

Calling an Agent

Synchronous

Asynchronous

Streaming

Agent Response

Every handle() / ahandle() call returns an AgentResponse:

Mixin Composition

Agent inherits from five mixins. Each adds a distinct capability:

Mixin
Adds

Promptable

handle(), ahandle(), stream(), astream()

HasTools

Tool calling, dispatch loop

HasStructuredOutput

Pydantic output validation

Conversational

DB-backed conversation history

ReasoningMixin

Reasoning model parameters

All five are composed by default. You can create leaner agents by composing only the mixins you need:

Default Provider / Model

If provider or model is left empty, the SDK falls back to AI_SDK.DEFAULT_PROVIDER and AI_SDK.DEFAULT_MODEL:

Using Multiple Agents Together

Agents are plain Python objects. You can chain them, pipe output from one into another, or run them in parallel with asyncio.gather:

Last updated

Was this helpful?