Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Add streaming tool output support#1964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
pokliu wants to merge1 commit intoopenai:main
base:main
Choose a base branch
Loading
frompokliu:feature/tool-output-streaming

Conversation

@pokliu
Copy link

Summary

This PR adds support forstreaming tool output in the OpenAI Agents SDK. Previously, users could only receive tool results after complete execution. Now, tools can yield incremental output during execution, enabling real-time progress feedback for long-running operations.

Key improvements:

  • NewToolOutputStreamEvent for receiving incremental tool output
  • Support for async generator functions as tools (returningAsyncIterator[str])
  • Automatic chunk accumulation for final LLM output
  • Full backward compatibility with existing non-streaming tools
  • Works in bothRunner.run_streamed() andRunner.run() modes

Type system fix:
Fixed the type signature ofFunctionTool.on_invoke_tool from:

Callable[[...],Awaitable[Any]|AsyncIterator[str]]

to:

Callable[[...],Awaitable[Any|AsyncIterator[str]]]

This properly represents that the function always returns an awaitable, which then yields either a regular value or an async iterator.

Test plan

New tests (tests/test_tool_streaming.py):

  1. test_basic_streaming_tool - Verifies basic streaming functionality
  2. test_streaming_tool_with_arguments - Tests parameter handling
  3. test_mixed_streaming_and_non_streaming_tools - Validates coexistence
  4. test_streaming_tool_accumulation - Confirms proper output accumulation
  5. test_streaming_tool_in_non_streaming_mode - TestsRunner.run() mode
  6. test_streaming_tool_agent_association - Checks event metadata

Example (examples/tools/streaming_tool_example.py):

  • Runnable example demonstrating streaming tools with realistic use case

Validation:

make format# ✅ All files formattedmake lint# ✅ All checks passedmake mypy# ✅ 347 files type-checked successfullymake tests# ✅ 926 tests passed (including 6 new streaming tests)

Issue number

N/A - New feature enhancement

Checks

  • I've added new tests (6 comprehensive tests)
  • I've added/updated the relevant documentation (4 language versions)
  • I've runmake lint andmake format (all passed)
  • I've made sure tests pass (926 passed, 3 skipped)

Usage Example

fromcollections.abcimportAsyncIteratorfromagentsimportAgent,Runner,function_tool@function_toolasyncdefsearch_documents(query:str)->AsyncIterator[str]:"""Search through documents and stream results."""documents= ["Doc 1...","Doc 2...","Doc 3..."]fordocindocuments:awaitasyncio.sleep(0.5)yielddocagent=Agent(name="Research Assistant",tools=[search_documents],)result=Runner.run_streamed(agent,input="Search for AI info")asyncforeventinresult.stream_events():ifevent.type=="tool_output_stream_event":print(f"[{event.tool_name}]{event.delta}",end="",flush=True)

Documentation

Updated streaming documentation in 4 languages:

  • English:docs/streaming.md
  • Chinese:docs/zh/streaming.md
  • Japanese:docs/ja/streaming.md
  • Korean:docs/ko/streaming.md

All include complete examples and key points about streaming tools.

chatgpt-codex-connector[bot], hayescode, and dhpancor reacted with thumbs up emoji
@ProCityHub

This comment was marked as off-topic.

1 similar comment
@ProCityHub

This comment was marked as off-topic.

@seratch
Copy link
Member

Thanks for sharing this idea. I see this could be useful for some use cases and it's an interesting enhancement idea. That being said, this requires a careful design decision, so we'll look into it later on.

@seratchseratch marked this pull request as draftOctober 21, 2025 22:10
@github-actions
Copy link
Contributor

This PR is stale because it has been open for 10 days with no activity.

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

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@pokliu@ProCityHub@seratch

[8]ページ先頭

©2009-2025 Movatter.jp