Skip to content

feat(Agent): add run_streaming() for structured SSE-compatible stream…#88

Open
rainj2013 wants to merge 1 commit intoMiniMax-AI:mainfrom
rainj2013:feat/add-streaming-run-method
Open

feat(Agent): add run_streaming() for structured SSE-compatible stream…#88
rainj2013 wants to merge 1 commit intoMiniMax-AI:mainfrom
rainj2013:feat/add-streaming-run-method

Conversation

@rainj2013
Copy link
Copy Markdown

…ing events

Add Agent.run_streaming() as the streaming counterpart to Agent.run(). All core logic (LLM calls, tool execution, token tracking, summarization, cancellation) is identical; only the output format differs - instead of printing to stdout, it yields structured AgentEvent objects via AsyncGenerator.

New schema types:

  • AgentEvent: discriminated union event with type, content, thinking, tool_call, tool_result, step, final_text, total_tokens
  • ToolCallEvent: emitted before tool execution (id, name, arguments)
  • ToolResultEvent: emitted after tool execution (id, name, success, content, error)

Event types: thinking | content | tool_call | tool_result |
step_complete | final

Consumers (e.g. SSE handlers) can map these events to their preferred output format without reimplementing the agent loop.

Added tests: test_streaming.py with 7 test cases covering content events, final events, tool call flow, cancellation, and max steps.

…ing events

Add Agent.run_streaming() as the streaming counterpart to Agent.run().
All core logic (LLM calls, tool execution, token tracking, summarization,
cancellation) is identical; only the output format differs - instead of
printing to stdout, it yields structured AgentEvent objects via
AsyncGenerator.

New schema types:
- AgentEvent: discriminated union event with type, content, thinking,
  tool_call, tool_result, step, final_text, total_tokens
- ToolCallEvent: emitted before tool execution (id, name, arguments)
- ToolResultEvent: emitted after tool execution (id, name, success,
  content, error)

Event types: thinking | content | tool_call | tool_result |
             step_complete | final

Consumers (e.g. SSE handlers) can map these events to their preferred
output format without reimplementing the agent loop.

Added tests: test_streaming.py with 7 test cases covering content
events, final events, tool call flow, cancellation, and max steps.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant