Repository navigation
feat(openai): emit AG-UI text and tool events #161
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
fb51650
feat(agui): add a shared reader for handler streams
cursoragent b7a9f3a
feat(agui): close an unfinished tool call as a failure
cursoragent 6e013a9
feat(openai): emit AG-UI text and tool events
cursoragent c35077d
fix(openai): keep streamed tool arguments and hosted results
cursoragent 4d7504c
fix(openai): serialize hosted results and close every open call
cursoragent e8c324e
fix(openai): close tool arguments and text in read order
cursoragent 57abadc
fix(openai): close the open text message when a turn fails
cursoragent c8d198c
fix(agui): keep each run valid for an AG-UI client
cursoragent 57be15d
merge(agui): take the shared reader fixes
cursoragent f43b888
fix(openai): share the function-tool stream mapper
cursoragent 3248d3c
fix(openai): close text before a tool result and on failure
cursoragent 3807bbe
fix(openai): apply unread text before a tool result
cursoragent fa05f74
feat(agui): add a shared reader for handler streams
cursoragent b104481
feat(agui): close an unfinished tool call as a failure
cursoragent 8294f59
fix(agui): keep each run valid for an AG-UI client
cursoragent 37c7387
fix(client): close only streams that implement aclose
cursoragent fc3e02b
merge(agui): take the rebased reader
cursoragent d8ea26b
merge(agui): take main after the reader landed
cursoragent 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
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| """Map OpenAI Responses stream events onto the AG-UI text and tool subset. | ||
|
|
||
| Both OpenAI handler packages call :func:`map_responses_event`. They only | ||
| offer function tools, so hosted and MCP item types are ignored until those | ||
| tools are wired. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
|
|
||
| from .agui import TurnEmitter | ||
|
|
||
|
|
||
| def _call_id(event: Any, item_to_call: dict[str, str]) -> str: | ||
| direct = getattr(event, "call_id", None) | ||
| if isinstance(direct, str) and direct: | ||
| return direct | ||
| item_id = getattr(event, "item_id", None) | ||
| if isinstance(item_id, str) and item_id in item_to_call: | ||
| return item_to_call[item_id] | ||
| return item_id if isinstance(item_id, str) else "" | ||
|
|
||
|
|
||
| def map_responses_event( | ||
| event: Any, emitter: TurnEmitter, item_to_call: dict[str, str] | ||
| ) -> list[dict[str, Any]]: | ||
| """Map one Responses event. Unknown events, including hosted tools, are ignored.""" | ||
| kind = getattr(event, "type", None) | ||
| if kind == "response.created": | ||
| return emitter.end_text() | ||
| if kind == "response.output_text.delta": | ||
| delta = getattr(event, "delta", "") | ||
| if not isinstance(delta, str) or not delta: | ||
| return [] | ||
| return emitter.text(delta) | ||
| if kind == "response.output_item.added": | ||
| item = getattr(event, "item", None) | ||
| if getattr(item, "type", None) != "function_call": | ||
| return [] | ||
| call_id = getattr(item, "call_id", None) or getattr(item, "id", None) or "" | ||
| name = getattr(item, "name", None) or "" | ||
| item_id = getattr(item, "id", None) | ||
| if isinstance(item_id, str) and isinstance(call_id, str) and call_id: | ||
| item_to_call[item_id] = call_id | ||
| return emitter.tool_start(str(call_id), str(name)) | ||
| if kind == "response.function_call_arguments.delta": | ||
| delta = getattr(event, "delta", "") | ||
| if not isinstance(delta, str): | ||
| return [] | ||
| return emitter.tool_args(_call_id(event, item_to_call), delta) | ||
| if kind == "response.function_call_arguments.done": | ||
| return emitter.tool_end( | ||
| _call_id(event, item_to_call), | ||
| arguments=getattr(event, "arguments", None), | ||
| ) | ||
| return [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.