Your LLM Shouldn't Be Handling If/Else Logic
· 4 min read
Here's code that's running in production right now across thousands of applications:
from pydantic_ai import Agent
from enum import Enum
class Team(Enum):
BILLING = "billing"
AUTH = "auth"
SHIPPING = "shipping"
RETURNS = "returns"
GENERAL = "general"
agent = Agent(
"openai:gpt-4o-mini",
output_type=Team,
system_prompt="Route this support ticket to the correct team.",
)
async def route(subject: str, body: str) -> Team:
result = await agent.run(f"Subject: {subject}\n\n{body}")
return result.output
It's clean. It's flexible. And every time a user types "I want to unsubscribe" or "forgot my password," it burns tokens to answer a question the model already answered yesterday.
