CorfedoCorfedoDocs

Pydantic AI

Give a Pydantic AI agent Corfedo's code tools with CorfedoToolset, or use Corfedo AI as the agent's model with CorfedoModel.

corfedo.pydantic_ai brings Corfedo to Pydantic AI. It gives your agent Corfedo's read tools as a toolset, or makes Corfedo AI the agent's model.

Before you begin

  • An API key file with Search and read code. Add Ask Corfedo AI to use CorfedoModel. See API keys.
  • Python 3.11 or later and the package with its extra:
pip install 'corfedo[pydantic-ai]'

Give your agent Corfedo's tools

import os
from pydantic_ai import Agent
from corfedo import CorfedoClient
from corfedo.pydantic_ai import CorfedoToolset

async with CorfedoClient.from_api_key_file(os.environ['CORFEDO_API_KEY_FILE']) as client:
    agent = Agent('openai:gpt-5', toolsets=[CorfedoToolset(client)])
    result = await agent.run('Where is the retry policy configured?')
    print(result.output)

The agent's own model runs the loop. Each tool returns Corfedo's result as JSON text. An invalid argument or an unknown or ambiguous repository becomes a retry, so the model can correct the call. CorfedoToolset(client, groups=[], tools=['search_code', 'read_file']) selects single tools.

Check: result.all_messages() contains calls to search_code or read_file, and the output cites files from your repositories.

Use Corfedo AI as the model

from pydantic_ai import Agent
from corfedo.pydantic_ai import CorfedoModel, CorfedoModelSettings

agent = Agent(
    CorfedoModel(client),
    model_settings=CorfedoModelSettings(corfedo_tools=['search_code']),
)
first = await agent.run('How are search requests routed?')
next_answer = await agent.run(
    'Which modules call that code?', message_history=first.all_messages()
)
print(next_answer.output)

The conversation lives in Corfedo. It continues from the provider_details kept in the message history, also after a JSON round trip, so earlier messages are not sent again.

SettingEffect
corfedo_conversation_idContinues a conversation
corfedo_sources, corfedo_references, corfedo_limits, corfedo_toolsRepositories to read, context to start from, run limits and Corfedo's own tools

The profile chosen for the API answers.

Settings merge across model, agent and run as Pydantic AI usually merges them. Function tools you add become client tools your agent runs. agent.run_stream shows progress. A structured output_type uses native JSON Schema output.

A response gives the conversation, the run, the outcome and the citations in provider_details, the run ID as provider_response_id and token usage in RequestUsage. Cancelling a run of the agent ends its subscription, not the Corfedo run. client.ai.cancel with the run ID stops it.

Check: the second answer refers to the first, which shows the conversation continued.

Troubleshooting

What you seeWhyWhat to do
CorfedoUnsupportedInputErrorThe call has a system prompt, a sampling setting, non-text content, a native tool, or tool or prompted output modeRemove it. The profile owns instructions and settings.
CorfedoRunErrorThe run ended without an answerRead its outcome
CorfedoOutputDiscardedErrorText already streamed was replaced after the run recoveredRead the answer with await client.ai.get_run(run_id)

On this page