Skip to content

Python: [Bug]: ClaudeAgent.run_stream() silently ignores API errors and AssistantMessage responses #3652

@droideronline

Description

@droideronline

Description

The run_stream() method in ClaudeAgent only processes StreamEvent and ResultMessage types from self._client.receive_response(), but:

  1. AssistantMessage is completely ignored - When the Claude SDK returns an AssistantMessage (which contains the actual response text or error messages), it's silently dropped because there's no handler for it.

  2. ResultMessage.is_error is never checked - The code only extracts session_id from ResultMessage and ignores the is_error flag and error content.

Impact

When an API error occurs (e.g., invalid model name returning 404), the agent returns empty results (result.text = "", result.messages = []) with no exception raised. The error message is buried in an AssistantMessage that gets silently dropped.

Expected Behavior

  • Check ResultMessage.is_error and raise ServiceException when true
  • Process AssistantMessage to extract response text or propagate errors
  • Surface API errors as exceptions instead of returning empty results

Code Sample

# Using invalid model claude-sonnet-4.5
async with ClaudeAgent(default_options={"model": "claude-sonnet-4.5"}) as agent:
    response = await agent.run("Hello")
    # Returns empty response instead of raising error
    print(response.text)  # ""

Error Messages / Stack Traces

No error is raised - that's the bug. The API returns a 404 error but it's silently ignored.

Package Versions

agent-framework-claude: latest (main branch)

Python Version

Python 3.13

Operating System

macOS

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions