Skip to content

Python: [Bug]: Structured Output multiple .run invocations with different schemas fails AzureAIClient #3363

@savvaki

Description

@savvaki

Description

If you use the same client and call .run twice, each with a different schema in the runtime options, the second call returns None.

Code Sample

from pydantic import BaseModel
from azure.identity.aio import DefaultAzureCredential
from agent_framework.azure import AzureAIClient
from pydantic import ConfigDict

class City(BaseModel):
    name: str
    weather: int
    model_config = ConfigDict(extra="forbid")

class WeatherCity(BaseModel):
    san_fran: City
    new_york: City 
    model_config = ConfigDict(extra="forbid")
    
class Country(BaseModel):
    name: str
    weather: int
    model_config = ConfigDict(extra="forbid")
    
class WeatherCountry(BaseModel):
    america: Country
    united_kingdom: Country
    model_config = ConfigDict(extra="forbid")

    
PROJECT_URL = "" 
DEPLOYMENT = "gpt-4.1"

async with (
        DefaultAzureCredential() as credential,
        AzureAIClient(credential=credential, project_endpoint=PROJECT_URL, model_deployment_name=DEPLOYMENT) as client,
        client.as_agent(name="test") as agent
    ):
    result1 = await agent.run("Make up the weather", options={"response_format": WeatherCity})
    print("First Result")
    print(result1.value)
    result2 = await agent.run("Make up the weather", options={"response_format": WeatherCountry})
    print("Second Result")
    print(result2.value)

Error Messages / Stack Traces

First Result
san_fran=City(name='San Francisco', weather=65) new_york=City(name='New York', weather=78)
Second Result
None

Package Versions

agent-framework-azure-ai: 1.0.0b260116, agent-framework-core: 1.0.0b260116

Python Version

3.13.7

Additional Context

No response

Metadata

Metadata

Labels

bugSomething isn't workingmodel clientsIssues related to the model client implementationspythonv1.0Features being tracked for the version 1.0 GA

Type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions