Skip to content

Agent stream doesn't set actual model name on ModelResponse #2840

@alexmojaki

Description

@alexmojaki

Initial Checks

Description

A ModelResponse produced by Agent.run has the correct actual model_name returned by the API, but not when streaming.

Example Code

import asyncio

from pydantic_ai import Agent

agent = Agent('gpt-4o')


async def main():
    run = await agent.run('hi')
    assert run.all_messages()[-1].model_name != 'gpt-4o'
    print(run.all_messages()[-1].model_name)  # gpt-4o-2024-08-06

    async with agent.run_stream('hi') as run:
        async for _ in run.stream_text():
            ...

    assert run.all_messages()[-1].model_name == 'gpt-4o'  # problem!

asyncio.run(main())

Python, Pydantic AI & LLM client version

Latest on GitHub.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions