Skip to content

Greater introspection into the successful model when using FallbackModel #2141

Open
@dhimmel

Description

@dhimmel

My initial use case here is to know which provider and model combination produced the output when using FallbackModel. Right now we can know the model name (possibly different than the input model name str) but not the provider. Example:

from pydantic_ai import Agent
from pydantic_ai.models import infer_model
from pydantic_ai.models.fallback import FallbackModel

agent = Agent(
    model=FallbackModel([
        infer_model("provider_1:model_1"),
        infer_model("provider_2:model_1"),
    ]),
)
result = await agent.run(
    user_prompt="This is a test. Respond with only the word 'okay'."
)
result.new_messages()[-1].model_name

But I think there are a broader set of related use cases:

Is there a way for AgentRunResult to learn more about the models and calls behind it including each model in a Fallback scenario?

Related

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions