import os
from typing import Literal
from pydantic import BaseModel, Field
from pydantic_ai import Agent
from pydantic_ai.models.openai_decisions import OpenAIDecisionsModel
from pydantic_ai.providers.openai import OpenAIProvider
sage = OpenAIDecisionsModel(
'sage-latest',
provider=OpenAIProvider(base_url='https://api.levanto.ai/v1', api_key=os.environ['LEVANTO_API_KEY']),
)
class Ticket(BaseModel):
"""Triage a support ticket."""
team: Literal['billing', 'technical', 'shipping'] = Field(description='Which team should handle this?')
refund: bool = Field(description='Is the customer asking for money back?')
agent = Agent(sage, output_type=Ticket)
result = agent.run_sync('I was charged twice for my order. Please refund the duplicate today.')
result.output # Ticket(team='billing', refund=True)
result.response.provider_details # each field's confidence and the choice probabilities