Skip to content

[Bug] output_schema forces non-streaming API call, breaking Anthropic Claude models with long requests #7044

Description

@yathaarthmagi

Description

When output_schema is set on an AgnoAgent using agno.models.aws.Claude (Bedrock), the agent forces the underlying API call to be non-streaming even when stream=True is passed to agent.arun(). This causes the Anthropic SDK to reject the request with: "Streaming is required for operations that may take longer than 10 minutes."

The root cause is in agno/agent/_response.py inside ahandle_model_response_stream() (~line 1207):

should_parse_structured_output = output_schema is not None and agent.parse_response and agent.parser_model is None
stream_model_response = True
if should_parse_structured_output:
    stream_model_response = False  # Forces non-streaming

This propagates to Model.aresponse_stream() in agno/models/base.py, which then calls ainvoke() (non-streaming .create()) instead of ainvoke_stream() (streaming .stream()).

Steps to Reproduce

  1. Create an AgnoAgent with model=Claude(id="...", thinking={"type": "enabled", ...}, max_tokens=64000) and output_schema=SomePydanticModel
  2. Call agent.arun(messages, stream=True, stream_events=True)
  3. The request fails with "Streaming is required for operations that may take longer than 10 minutes"

Agent Configuration (if applicable)

agent = AgnoAgent(
    name="",
    model=Claude(
        id="global.anthropic.claude-sonnet-4-6",
        temperature=1,
        thinking={"type": "enabled", "budget_tokens": 1024},
        max_tokens=4000,
    ),
    system_message=system_prompt,
    tools=[toolkit],
    stream_events=True,
    use_json_mode=True,
    output_schema=MyPydanticSchema,  # <-- this triggers the bug
)
response = agent.arun(messages, stream=True, stream_events=True)

Expected Behavior

When stream=True is passed to arun(), the underlying API call should use streaming (.stream()) regardless of whether output_schema is set. The structured output parsing can still be performed on the fully accumulated streamed response.

Actual Behavior

Setting output_schema forces stream_model_response = False in ahandle_model_response_stream(), which causes the model to use non-streaming ainvoke() -> .create(). The Anthropic SDK rejects this for long-running requests.

Screenshots or Logs (if applicable)

ERROR Unexpected error calling Claude API: Streaming is required for operations that may take longer than 10 minutes. See https://github.com/anthropics/anthropic-sdk-python#long-requests for more details
ERROR Error in Agent run: Streaming is required for operations that may take longer than 10 minutes.

Environment

- OS: macOS Tahoe 26.3.1
- Agno Version: 2.5.9
- Additional Environment Details: Python 3.11.12

Possible Solutions (optional)

In ahandle_model_response_stream(), instead of disabling streaming entirely when output_schema is set, accumulate the streamed chunks and parse the full response into the schema after streaming completes. This preserves the streaming API call while still supporting structured output parsing.

Additional Context

This affects all Anthropic/Claude model variants (direct API and Bedrock) when used with output_schema and max_tokens high enough that the SDK enforces streaming. The workaround is to remove output_schema and manually parse the JSON from the streamed text response.

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