Quickstart

This guide walks through the most common use cases in 5 minutes.

1. Basic Agent

# myapp/agents.py
from djangosdk.agents.base import Agent

class HelloAgent(Agent):
    provider = "openai"
    model = "gpt-4.1"
    system_prompt = "You are a helpful assistant."

# Use in a Django view
agent = HelloAgent()
response = agent.handle("What is Django?")
print(response.text)
print(response.usage.total_tokens)

2. Agent with Tools

from djangosdk.agents.base import Agent
from djangosdk.tools.decorator import tool

@tool
def get_order_status(order_id: str) -> str:
    """Look up the current status of an order.

    Args:
        order_id: The unique order identifier.
    """
    # Your database lookup here
    return f"Order {order_id} is shipped."

@tool
def cancel_order(order_id: str, reason: str = "customer request") -> str:
    """Cancel an order.

    Args:
        order_id: The order to cancel.
        reason: Reason for cancellation.
    """
    return f"Order {order_id} cancelled. Reason: {reason}"

class SupportAgent(Agent):
    provider = "openai"
    model = "gpt-4.1"
    system_prompt = "You are a customer support agent."
    tools = [get_order_status, cancel_order]

agent = SupportAgent()
response = agent.handle("Cancel order #ABC123 because the customer changed their mind.")
print(response.text)

3. Structured Output

4. Conversation Persistence

5. Streaming (DRF View)

6. Reasoning Models

7. Async View

Next Steps

Last updated

Was this helpful?