ExamplescriptadvancedRunnableticket-classifier
Level 1: Augmented LLM — Single API Call
One model call with structured output, system prompt, and context. No loops, no tools.
Key Facts
- Level
- advanced
- Runtime
- Python • Pydantic + Python Dotenv
- Pattern
- Single-step delegation with explicit structured output
- Interaction
- Live sandbox • Script
- Updated
- 14 March 2026
Navigate this example
Library
Browse examplesReopen the wider library to compare adjacent patterns and linked learning paths.Interaction
Run sandbox nowTry the interaction directly in this example’s guided sandbox surface.Source
Open full sourceRead the real implementation, highlighted checkpoints, and runtime requirements.MCP
Call via MCPUse the same resource inside agents, deterministic exports, and MCP setup flows.
Linked principles
Model context
Model-agnosticLocal-viableNo tool calling requiredLow reasoning requirement
Augmented LLM pattern adds context retrieval and memory on top of a base model call. The pattern works regardless of which model handles inference.
1-augmented-llm.py
python
"""
Level 1: Augmented LLM — Single API Call
One model call with structured output, system prompt, and context. No loops, no tools.
"""
from pydantic import BaseModel
from pydantic_ai import Agent
from dotenv import load_dotenv
import nest_asyncio
load_dotenv()
nest_asyncio.apply()
class TicketClassification(BaseModel):
category: str
priority: str
summary: str
can_auto_resolve: bool
agent = Agent(
"anthropic:claude-sonnet-4-6",
output_type=TicketClassification,
system_prompt=(
"You are a customer support classifier. "
"Classify incoming tickets by category (billing, technical, general), "
"priority (low, medium, high), and whether they can be auto-resolved."
),
)
result = agent.run_sync(
"I was charged twice for my subscription last month. "
"Order ID: #12345. Please refund the duplicate charge."
)
print(result.output)
# category='billing' priority='high' summary='Duplicate subscription charge, requesting refund for order #12345' can_auto_resolve=True
Related principles
- P1delegationDesign for delegation rather than direct manipulationDesign experiences around the assignment of work, the expression of intent, the setting of constraints, and the review of results, rather than requiring users to execute each step manually.Open principle →
- P5delegationReplace implied magic with clear mental modelsThe product should help users understand what the system can do, what it is currently doing, what it cannot do, and what conditions govern its behaviour.Open principle →
- P9orchestrationRepresent delegated work as a system, not merely as a conversationWhere work involves multiple steps, agents, dependencies, or concurrent activities, it should be represented as a structured system rather than solely as a message stream.Open principle →
- P10delegationOptimise for steering, not only initiatingThe system should support users not only in starting tasks, but also in guiding, refining, reprioritising, and correcting work while it is underway.Open principle →