-
Notifications
You must be signed in to change notification settings - Fork 931
GenAI Utils | Update ToolCall Type #4218
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
lzchen
merged 34 commits into
open-telemetry:main
from
keith-decker:pr1-enhance-toolcall-type
Mar 27, 2026
Merged
Changes from 7 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
321ea30
feat: update toolcall types to match semconv
keith-decker 3de0e8d
update changelog
keith-decker b277b72
lint updates
keith-decker 9b3f2a6
feat: refactor ToolCall to ToolCallRequest and enhance type definitions
keith-decker 0f28588
test: point vertexai at current version of genai utils
keith-decker db3802a
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker 2f009f9
test: fix fileupload test to use ToolCallRequest
keith-decker 5e8d489
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker 3064499
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker 1287d96
refactor(types): update inheritance structure
keith-decker 865bdab
Merge remote-tracking branch 'origin/main' into pr1-enhance-toolcall-…
keith-decker 1bdd5c4
fix: update opentelemetry-util-genai version constraints and introduc…
keith-decker 57898bf
fix version mismatch
keith-decker 432fc6c
Merge remote-tracking branch 'origin/main' into pr1-enhance-toolcall-…
keith-decker b11de5c
Convert GenericPart to a dataclass
keith-decker 9bd35dc
patch openai to use toolcallrequest
keith-decker dc2b1b9
Refactor message part handling to use Blob and Uri types
keith-decker 6512305
Merge remote-tracking branch 'origin/main' into pr1-enhance-toolcall-…
keith-decker 124abd0
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker 73b8369
Add ServerToolCall and ServerToolCallResponse models with tests
keith-decker 24b1721
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker dc4f7c2
refactor: streamline Blob and Uri handling in message processing
keith-decker 828e954
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker e1fdd08
convert anthropic to toolcallrequest and remove toolcall from message…
keith-decker 978d837
Merge branch 'pr1-enhance-toolcall-type' of github.com:keith-decker/o…
keith-decker 1f336d3
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker cdec2bc
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker e7f07f6
move error.type to base genai class
keith-decker 3730a3e
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker dbac1b6
Merge branch 'main' into pr1-enhance-toolcall-type
xrmx ecfb339
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker d5997ec
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker 70c7804
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker 01ab8ae
update version requirements
keith-decker 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| # Copyright The OpenTelemetry Authors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Tests for ToolCallRequest and ToolCall types""" | ||
|
|
||
| import pytest | ||
|
|
||
| from opentelemetry.util.genai.types import ( | ||
| InputMessage, | ||
| OutputMessage, | ||
| ToolCall, | ||
| ToolCallRequest, | ||
| ) | ||
|
|
||
|
|
||
| def test_toolcallrequest_basic(): | ||
| """Test basic ToolCallRequest instantiation""" | ||
| tcr = ToolCallRequest(arguments=None, name="get_weather", id=None) | ||
| assert tcr.name == "get_weather" | ||
| assert tcr.type == "tool_call" | ||
| assert tcr.arguments is None | ||
| assert tcr.id is None | ||
|
|
||
|
|
||
| def test_toolcallrequest_with_all_fields(): | ||
| """Test ToolCallRequest with all fields""" | ||
| tcr = ToolCallRequest( | ||
| name="get_weather", | ||
| arguments={"location": "Paris"}, | ||
| id="call_123", | ||
| ) | ||
| assert tcr.name == "get_weather" | ||
| assert tcr.arguments == {"location": "Paris"} | ||
| assert tcr.id == "call_123" | ||
| assert tcr.type == "tool_call" | ||
|
|
||
|
|
||
| def test_toolcallrequest_in_message(): | ||
| """Test ToolCallRequest works as message part""" | ||
| tcr = ToolCallRequest( | ||
| arguments={"location": "Paris"}, name="get_weather", id=None | ||
| ) | ||
| msg = InputMessage(role="user", parts=[tcr]) | ||
| assert len(msg.parts) == 1 | ||
| assert msg.parts[0] == tcr | ||
|
|
||
|
|
||
| def test_toolcall_inherits_from_toolcallrequest(): | ||
| """Test that ToolCall inherits from ToolCallRequest""" | ||
| tc = ToolCall(arguments=None, name="get_weather", id=None) | ||
| assert isinstance(tc, ToolCallRequest) | ||
| assert isinstance(tc, ToolCall) | ||
|
|
||
|
|
||
| def test_toolcall_has_execution_fields(): | ||
| """Test ToolCall has execution-only fields""" | ||
| tc = ToolCall(arguments=None, name="get_weather", id=None) | ||
| assert hasattr(tc, "tool_type") | ||
| assert hasattr(tc, "tool_description") | ||
| assert hasattr(tc, "tool_result") | ||
| assert hasattr(tc, "error_type") | ||
|
|
||
|
|
||
| def test_toolcall_execution_fields_default_none(): | ||
| """Test ToolCall execution fields default to None""" | ||
| tc = ToolCall(arguments=None, name="get_weather", id=None) | ||
| assert tc.tool_type is None | ||
| assert tc.tool_description is None | ||
| assert tc.tool_result is None | ||
| assert tc.error_type is None | ||
|
|
||
|
|
||
| def test_toolcall_with_execution_fields(): | ||
| """Test ToolCall with execution fields set""" | ||
| tc = ToolCall( | ||
| name="get_weather", | ||
| arguments={"location": "Paris"}, | ||
| id="call_123", | ||
| tool_type="function", | ||
| tool_description="Get current weather", | ||
| tool_result={"temp": 20, "condition": "sunny"}, | ||
| ) | ||
| assert tc.name == "get_weather" | ||
| assert tc.tool_type == "function" | ||
| assert tc.tool_description == "Get current weather" | ||
| assert tc.tool_result == {"temp": 20, "condition": "sunny"} | ||
|
|
||
|
|
||
| def test_toolcall_with_error(): | ||
| """Test ToolCall with error_type set""" | ||
| tc = ToolCall( | ||
| arguments={"location": "Invalid"}, | ||
| name="get_weather", | ||
| id=None, | ||
| error_type="InvalidLocationError", | ||
| ) | ||
| assert tc.error_type == "InvalidLocationError" | ||
| assert tc.tool_result is None | ||
|
|
||
|
|
||
| def test_toolcall_backward_compatibility(): | ||
| """Test ToolCall still works as message part (backward compatibility)""" | ||
| tc = ToolCall( | ||
| name="get_weather", | ||
| arguments={"location": "Paris"}, | ||
| id="call_123", | ||
| ) | ||
| # Should work in messages | ||
| msg = InputMessage(role="user", parts=[tc]) | ||
| assert len(msg.parts) == 1 | ||
|
|
||
| # Should work in output messages | ||
| out_msg = OutputMessage( | ||
| role="assistant", parts=[tc], finish_reason="tool_calls" | ||
| ) | ||
| assert len(out_msg.parts) == 1 | ||
|
|
||
|
|
||
| def test_toolcallrequest_no_execution_fields(): | ||
| """Test that ToolCallRequest doesn't have execution fields""" | ||
| tcr = ToolCallRequest(arguments=None, name="get_weather", id=None) | ||
| # ToolCallRequest should only have message part fields | ||
| assert not hasattr(tcr, "tool_type") | ||
| assert not hasattr(tcr, "tool_description") | ||
| assert not hasattr(tcr, "tool_result") | ||
| assert not hasattr(tcr, "error_type") | ||
|
|
||
|
|
||
| def test_mixed_types_in_message(): | ||
| """Test using both ToolCallRequest and ToolCall in messages""" | ||
| tcr = ToolCallRequest(arguments=None, name="simple_tool", id=None) | ||
| tc = ToolCall( | ||
| arguments=None, name="complex_tool", id=None, tool_type="function" | ||
| ) | ||
|
|
||
| msg = InputMessage(role="user", parts=[tcr, tc]) | ||
| assert len(msg.parts) == 2 | ||
| assert isinstance(msg.parts[0], ToolCallRequest) | ||
| assert isinstance(msg.parts[1], ToolCall) | ||
| # ToolCall is also a ToolCallRequest | ||
| assert isinstance(msg.parts[1], ToolCallRequest) | ||
|
|
||
|
|
||
| def test_toolcall_tool_type_values(): | ||
| """Test valid tool_type values""" | ||
| for tool_type in ["function", "extension", "datastore"]: | ||
| tc = ToolCall( | ||
| arguments=None, name="test", id=None, tool_type=tool_type | ||
| ) | ||
| assert tc.tool_type == tool_type | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| pytest.main([__file__, "-v"]) |
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.
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.