-
Notifications
You must be signed in to change notification settings - Fork 9
feat(openai-temporal): render hosted/server-side tool calls in TemporalStreamingModel #442
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
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
135 changes: 135 additions & 0 deletions
135
src/agentex/lib/core/temporal/plugins/openai_agents/tests/test_hosted_tools.py
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,135 @@ | ||
| """Unit tests for hosted/server-side tool rendering helpers. | ||
|
|
||
| These cover the pure extraction helpers used by TemporalStreamingModel to surface | ||
| Responses-API hosted tools (web_search, file_search, code_interpreter, mcp, ...) | ||
| as ToolRequest/ToolResponse pairs. They never become function_call items, so the | ||
| streaming loop must render them explicitly. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from types import SimpleNamespace | ||
|
|
||
| from openai.types.responses.response_output_item import ( | ||
| LocalShellCall, | ||
| ImageGenerationCall, | ||
| LocalShellCallAction, | ||
| ) | ||
| from openai.types.responses.response_computer_tool_call import ActionClick, ResponseComputerToolCall | ||
| from openai.types.responses.response_function_web_search import ActionSearch, ResponseFunctionWebSearch | ||
|
|
||
| from agentex.lib.core.temporal.plugins.openai_agents.models.temporal_streaming_model import ( | ||
| _HOSTED_TOOL_TYPES, | ||
| _coerce_args, | ||
| _hosted_tool_result, | ||
| _hosted_tool_request, | ||
| ) | ||
|
|
||
|
|
||
| def test_hosted_tool_types_membership(): | ||
| for t in ("web_search_call", "file_search_call", "code_interpreter_call", | ||
| "image_generation_call", "mcp_call", "computer_call", "local_shell_call"): | ||
| assert t in _HOSTED_TOOL_TYPES | ||
| assert "function_call" not in _HOSTED_TOOL_TYPES | ||
|
|
||
|
|
||
| def test_coerce_args_variants(): | ||
| assert _coerce_args(None) == {} | ||
| assert _coerce_args({"a": 1}) == {"a": 1} | ||
| assert _coerce_args('{"a": 1}') == {"a": 1} | ||
| assert _coerce_args("[1, 2]") == {"value": [1, 2]} | ||
| assert _coerce_args("not json") == {"raw": "not json"} | ||
|
|
||
|
|
||
| def test_hosted_tool_request_web_search(): | ||
| # Use the real Responses-API type to prove `action` is a genuine SDK field | ||
| # (it is on ResponseFunctionWebSearch), not a hand-crafted stand-in. | ||
| item = ResponseFunctionWebSearch( | ||
| id="ws_1", | ||
| status="completed", | ||
| type="web_search_call", | ||
| action=ActionSearch(type="search", query="agentex"), | ||
| ) | ||
| call_id, name, args = _hosted_tool_request(item) | ||
| assert call_id == "ws_1" | ||
| assert name == "web_search" # "_call" stripped | ||
| assert args["query"] == "agentex" | ||
| assert args["type"] == "search" | ||
|
|
||
|
|
||
| def test_hosted_tool_request_computer_call(): | ||
| item = ResponseComputerToolCall( | ||
| id="cc_1", | ||
| call_id="ccall_1", | ||
| type="computer_call", | ||
| status="completed", | ||
| pending_safety_checks=[], | ||
| action=ActionClick(type="click", button="left", x=10, y=20), | ||
| ) | ||
| call_id, name, args = _hosted_tool_request(item) | ||
| assert call_id == "cc_1" | ||
| assert name == "computer" | ||
| assert args["type"] == "click" | ||
| assert args["button"] == "left" | ||
| assert args["x"] == 10 and args["y"] == 20 | ||
|
|
||
|
|
||
| def test_hosted_tool_request_local_shell_call(): | ||
| item = LocalShellCall( | ||
| id="ls_1", | ||
| call_id="lscall_1", | ||
| type="local_shell_call", | ||
| status="completed", | ||
| action=LocalShellCallAction(type="exec", command=["ls", "-la"], env={}), | ||
| ) | ||
| call_id, name, args = _hosted_tool_request(item) | ||
| assert call_id == "ls_1" | ||
| assert name == "local_shell" | ||
| assert args["command"] == ["ls", "-la"] | ||
|
|
||
|
|
||
| def test_hosted_tool_request_mcp_uses_server_label(): | ||
| item = SimpleNamespace(type="mcp_call", id="m_1", name="search", | ||
| server_label="linear", arguments='{"q": "x"}') | ||
| call_id, name, args = _hosted_tool_request(item) | ||
| assert call_id == "m_1" | ||
| assert name == "linear.search" | ||
| assert args == {"q": "x"} | ||
|
|
||
|
|
||
| def test_hosted_tool_request_file_search_queries(): | ||
| item = SimpleNamespace(type="file_search_call", id="fs_1", | ||
| queries=["q1", "q2"]) | ||
| _, name, args = _hosted_tool_request(item) | ||
| assert name == "file_search" | ||
| assert args == {"queries": ["q1", "q2"]} | ||
|
|
||
|
|
||
| def test_hosted_tool_request_falls_back_to_generated_id(): | ||
| item = SimpleNamespace(type="code_interpreter_call", code="print(1)") | ||
| call_id, name, args = _hosted_tool_request(item) | ||
| assert call_id.startswith("hosted_") | ||
| assert name == "code_interpreter" | ||
| assert args == {"code": "print(1)"} | ||
|
|
||
|
|
||
| def test_hosted_tool_result_mcp_error_and_output(): | ||
| err_item = SimpleNamespace(type="mcp_call", error="boom") | ||
| assert "boom" in _hosted_tool_result(err_item) | ||
| ok_item = SimpleNamespace(type="mcp_call", error=None, output="done") | ||
| assert _hosted_tool_result(ok_item) == "done" | ||
|
|
||
|
|
||
| def test_hosted_tool_result_image_generation(): | ||
| item = ImageGenerationCall( | ||
| id="ig_1", | ||
| type="image_generation_call", | ||
| status="completed", | ||
| result="QUJD", # 4 chars of (fake) base64 | ||
| ) | ||
| assert _hosted_tool_result(item) == "<image generated: 4 bytes>" | ||
|
|
||
|
|
||
| def test_hosted_tool_result_falls_back_to_status(): | ||
| item = SimpleNamespace(type="web_search_call", status="completed") | ||
| assert _hosted_tool_result(item) == "completed" |
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.