-
Notifications
You must be signed in to change notification settings - Fork 3.2k
feat: #2228 Add tool origin tracking to ToolCallItem and ToolCallOutputItem #2242
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
base: main
Are you sure you want to change the base?
Changes from all commits
edbec4e
e1b6357
5b2835b
68c9dde
c2ea42d
6825a74
f850af4
6eb8473
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,11 @@ | |
| from collections.abc import Awaitable, Callable | ||
| from typing import Any, TypeVar, cast | ||
|
|
||
| from openai.types.responses import ResponseCompletedEvent, ResponseOutputItemDoneEvent | ||
| from openai.types.responses import ( | ||
| ResponseCompletedEvent, | ||
| ResponseFunctionToolCall, | ||
| ResponseOutputItemDoneEvent, | ||
| ) | ||
| from openai.types.responses.response_prompt_param import ResponsePromptParam | ||
| from openai.types.responses.response_reasoning_item import ResponseReasoningItem | ||
|
|
||
|
|
@@ -49,7 +53,7 @@ | |
| RawResponsesStreamEvent, | ||
| RunItemStreamEvent, | ||
| ) | ||
| from ..tool import Tool, dispose_resolved_computers | ||
| from ..tool import FunctionTool, Tool, _get_tool_origin_info, dispose_resolved_computers | ||
| from ..tracing import Span, SpanError, agent_span, get_current_trace | ||
| from ..tracing.model_tracing import get_model_tracing_impl | ||
| from ..tracing.span_data import AgentSpanData | ||
|
|
@@ -113,6 +117,7 @@ | |
| from .streaming import stream_step_items_to_queue, stream_step_result_to_queue | ||
| from .tool_actions import ApplyPatchAction, ComputerAction, LocalShellAction, ShellAction | ||
| from .tool_execution import ( | ||
| build_litellm_json_tool_call, | ||
| coerce_shell_call, | ||
| execute_apply_patch_calls, | ||
| execute_computer_actions, | ||
|
|
@@ -1222,13 +1227,28 @@ async def run_single_turn_streamed( | |
| # execution behavior in process_model_response). | ||
| tool_name = getattr(output_item, "name", None) | ||
| tool_description: str | None = None | ||
| tool_origin = None | ||
| if isinstance(tool_name, str) and tool_name in tool_map: | ||
| tool_description = getattr(tool_map[tool_name], "description", None) | ||
| tool = tool_map[tool_name] | ||
| tool_description = getattr(tool, "description", None) | ||
| if isinstance(tool, FunctionTool): | ||
| tool_origin = _get_tool_origin_info(tool) | ||
habema marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
1231
to
+1235
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This lookup uses Useful? React with 👍 / 👎. |
||
| elif ( | ||
| isinstance(tool_name, str) | ||
| and tool_name == "json_tool_call" | ||
| and output_schema is not None | ||
| and isinstance(output_item, ResponseFunctionToolCall) | ||
| ): | ||
| # json_tool_call is synthesized dynamically and not in tool_map. | ||
| # Synthesize it here to get tool_origin, matching process_model_response. | ||
| json_tool = build_litellm_json_tool_call(output_item) | ||
| tool_origin = _get_tool_origin_info(json_tool) | ||
|
|
||
| tool_item = ToolCallItem( | ||
| raw_item=cast(ToolCallItemTypes, output_item), | ||
| agent=agent, | ||
| description=tool_description, | ||
| tool_origin=tool_origin, | ||
| ) | ||
| streamed_result._event_queue.put_nowait( | ||
| RunItemStreamEvent(item=tool_item, name="tool_called") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.