microsoft / microsoft/agent-framework

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

Open
#8,361 1 comment 0 reactions 1 assignee View on GitHub

@eavanvalkenburg is already working on this.

Since Sep 14, 2026.

ag-ui python reproduced
Dominant language
Python
Stars
13.6k
Forks
2.3k
Avg merge
2d 45m
Merged PRs (30d)
358

Description

### 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

```python
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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.