Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
0541476
feat: enable real-time streaming of function call arguments
devtalker Jul 3, 2025
ed1bee7
docs: add documentation for real-time streaming of function call argu…
devtalker Jul 3, 2025
2a704d6
refactor: improve function call detection in streaming examples
devtalker Jul 7, 2025
08d626a
fix: resolve mypy type errors in function call streaming examples
devtalker Jul 7, 2025
d3eb92a
fix: prevent function call_id from being reset during streaming
devtalker Jul 9, 2025
39b0370
docs: optimize stream function call arguments example
devtalker Jul 10, 2025
1deec68
Revert "docs: add function call argument streaming documentation"
devtalker Jul 10, 2025
cd617b8
style: refine comment in stream handler
devtalker Jul 10, 2025
34b1754
refactor: remove stream function call args example
devtalker Jul 10, 2025
6885e4f
Merge branch 'main' into feature/function-call-args-streaming
devtalker Jul 14, 2025
0fbf80d
fix: simplify function call streaming logic based on LLM provider beh…
devtalker Jul 14, 2025
930783c
Merge branch 'main' into feature/function-call-args-streaming
devtalker Jul 14, 2025
ddd8b0d
Merge branch 'main' into feature/function-call-args-streaming
devtalker Jul 15, 2025
c5d982e
Merge branch 'main' into feature/function-call-args-streaming
devtalker Jul 15, 2025
87a7a87
Merge branch 'main' into feature/function-call-args-streaming
devtalker Jul 15, 2025
b2f1242
Merge branch 'main' into feature/function-call-args-streaming
devtalker Jul 16, 2025
e79e0ca
Merge branch 'main' into feature/function-call-args-streaming
devtalker Jul 16, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: add documentation for real-time streaming of function call argu…
…ments
  • Loading branch information
devtalker committed Jul 11, 2025
commit ed1bee7d1c406ea0ce3a72734a9ac12ab0eb3fb2
67 changes: 67 additions & 0 deletions docs/streaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,73 @@ if __name__ == "__main__":
asyncio.run(main())
```

### Function call argument streaming

Function call arguments are now streamed in real-time as they are generated, providing immediate feedback during large parameter generation. This is especially useful for scenarios like code generation, API request building, or complex configuration creation.

```python
import asyncio
from openai.types.responses import ResponseFunctionCallArgumentsDeltaEvent
from agents import Agent, Runner, function_tool

@function_tool
def write_file(filename: str, content: str) -> str:
"""Write content to a file."""
return f"File {filename} written successfully"

async def main():
agent = Agent(
name="CodeGenerator",
instructions="You are a helpful coding assistant. When asked to create files, use the write_file tool.",
tools=[write_file],
)

result = Runner.run_streamed(
agent,
input="Create a Python script that prints 'Hello, World!' and saves it as hello.py"
)

function_name = None
current_arguments = ""

async for event in result.stream_events():
if event.type == "raw_response_event":
# Function call started
if event.data.type == "response.output_item.added":
if hasattr(event.data.item, 'name'):
function_name = event.data.item.name
print(f"📞 Function call streaming started: {function_name}()")
print("📝 Arguments building...")

# Real-time argument streaming
elif isinstance(event.data, ResponseFunctionCallArgumentsDeltaEvent):
current_arguments += event.data.delta
print(f" + {event.data.delta}", end="", flush=True)

# Function call completed
elif event.data.type == "response.output_item.done":
if hasattr(event.data.item, 'name'):
print(f"\n✅ Function call streaming completed: {function_name}")
print(f"🔧 Final arguments: {current_arguments}")

print(f"\n🎉 Result: {result.final_output}")


if __name__ == "__main__":
asyncio.run(main())
```

This will show the function arguments being built incrementally:
```
📞 Function call streaming started: write_file()
📝 Arguments building...
+ {"filename": "
+ hello.py", "content": "
+ print('Hello, World!')"}
✅ Function call streaming completed: write_file
🔧 Final arguments: {"filename": "hello.py", "content": "print('Hello, World!')"}
```

## Run item events and agent events

[`RunItemStreamEvent`][agents.stream_events.RunItemStreamEvent]s are higher level events. They inform you when an item has been fully generated. This allows you to push progress updates at the level of "message generated", "tool ran", etc, instead of each token. Similarly, [`AgentUpdatedStreamEvent`][agents.stream_events.AgentUpdatedStreamEvent] gives you updates when the current agent changes (e.g. as the result of a handoff).
Expand Down