Skip to content

Python: [Bug]: AG-UI skips assistant text when response_format is a JSON Schema mapping #8361

Description

@likebean

Description

Agent documents two response_format values: a Pydantic model, or a JSON Schema mapping (dict). AG-UI only completes the first path.

When agent.default_options["response_format"] is set, _run_agent sets skip_text = True and does not stream TEXT_MESSAGE_* events. After the run it only re-emits text if response_format is a Pydantic BaseModel (and then only the model's message field). A mapping schema hits:

Skipping structured output parsing: response_format is not a Pydantic model type.

The model still produces tokens, but the AG-UI stream / thread snapshot has no assistant message.

Expected: a JSON Schema / {"type": "json_object"} response_format should still surface as assistant text (stream the JSON, or emit response.text / parsed JSON after the run). Pydantic + StateSnapshot behavior can stay as-is.

Steps:

  1. Create an agent with default_options={"response_format": {"type": "object", "properties": {"name": {"type": "string"}}, "required": ["name"]}}.
  2. Wrap it in AgentFrameworkAgent and run a user message through AG-UI.
  3. Observe usage tokens but no TEXT_MESSAGE_CONTENT / assistant snapshot message.

Code Sample

from agent_framework import Agent
from agent_framework.ag_ui import AgentFrameworkAgent

schema = {
    "type": "object",
    "properties": {"name": {"type": "string"}, "age": {"type": "integer"}},
    "required": ["name", "age"],
}

agent = Agent(
    name="extractor",
    instructions="Extract person info as JSON.",
    client=client,  # any Completions-compatible client
    default_options={"response_format": schema},
)

wrapper = AgentFrameworkAgent(agent=agent)
# Run via AG-UI: TEXT_MESSAGE_* never emitted for the JSON body.

Relevant code in python/packages/ag-ui/agent_framework_ag_ui/_agent_run.py:

  • skip_text = response_format is not None (any format, including mappings)
  • later: if not (isinstance(response_format, type) and issubclass(response_format, BaseModel)): logger.warning("Skipping structured output parsing...")

Error Messages / Stack Traces

No exception. Warning only:

Skipping structured output parsing: response_format is not a Pydantic model type.

Run completes with outputTokens > 0 and a user message in the thread snapshot, but no assistant message.

Package Versions

agent-framework-ag-ui: 1.3.0
agent-framework-core: 1.18.0

Python Version

Python 3.13.11

Additional Context

Docs: https://learn.microsoft.com/en-us/agent-framework/agents/structured-outputs?pivots=programming-language-python

Suggested fix: when response_format is a mapping, do not set skip_text, or after the run emit AgentResponse.from_updates(...).text (or the parsed JSON) as TEXT_MESSAGE_*. Keep the Pydantic shared-state path unchanged.

Happy to send a PR if that direction looks right.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

ag-uiUsage: [Issues, PRs], Target: AG-UI protocol integrationpythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions