> ## Documentation Index
> Fetch the complete documentation index at: https://docs.levanto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Pydantic AI

> Sage as the model of a Pydantic AI agent that decides.

```bash theme={"theme":"github-light"}
pip install "pydantic-ai-slim[openai]"
```

## Decisions

An agent whose output is a decision runs on Sage. Each field of `output_type` is one question: a `bool` is a yes/no, a `Literal` is a choice, and the field's description is the question.

```python theme={"theme":"github-light"}
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
```

It calls the [OpenAI Decisions API](https://docs.levanto.ai/openai-decisions.md). The `message_history` of the run goes along as the conversation.

## Images

```python theme={"theme":"github-light"}
from pathlib import Path

from pydantic_ai import BinaryContent


class Screenshot(BaseModel):
    payment_error: bool = Field(description='Does the screenshot show a payment error?')


agent = Agent(sage, output_type=Screenshot)
result = agent.run_sync([
    'Screenshot attached to a support ticket.',
    BinaryContent(data=Path('screenshot.png').read_bytes(), media_type='image/png'),
])
result.output  # Screenshot(payment_error=True)
```

One image per request.

## SystemOne

`SystemOneModel` runs the same agents on the [SystemOne API](https://docs.levanto.ai/systemone.md), text only:

```python theme={"theme":"github-light"}
from pydantic_ai.models.system_one import SystemOneModel
from pydantic_ai.providers.system_one import SystemOneProvider

sage = SystemOneModel(
    'sage-latest',
    provider=SystemOneProvider(base_url='https://api.levanto.ai/v1', api_key=os.environ['LEVANTO_API_KEY']),
)
```

## Check it worked

`result.response.model_name` is `levanto-sage-2`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.