Skip to content
Merged
Show file tree
Hide file tree
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 Feb 19, 2026
3de0e8d
update changelog
keith-decker Feb 19, 2026
b277b72
lint updates
keith-decker Feb 19, 2026
9b3f2a6
feat: refactor ToolCall to ToolCallRequest and enhance type definitions
keith-decker Feb 19, 2026
0f28588
test: point vertexai at current version of genai utils
keith-decker Feb 23, 2026
db3802a
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker Feb 23, 2026
2f009f9
test: fix fileupload test to use ToolCallRequest
keith-decker Feb 23, 2026
5e8d489
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker Feb 25, 2026
3064499
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker Feb 26, 2026
1287d96
refactor(types): update inheritance structure
keith-decker Mar 2, 2026
865bdab
Merge remote-tracking branch 'origin/main' into pr1-enhance-toolcall-…
keith-decker Mar 2, 2026
1bdd5c4
fix: update opentelemetry-util-genai version constraints and introduc…
keith-decker Mar 2, 2026
57898bf
fix version mismatch
keith-decker Mar 2, 2026
432fc6c
Merge remote-tracking branch 'origin/main' into pr1-enhance-toolcall-…
keith-decker Mar 4, 2026
b11de5c
Convert GenericPart to a dataclass
keith-decker Mar 4, 2026
9bd35dc
patch openai to use toolcallrequest
keith-decker Mar 4, 2026
dc2b1b9
Refactor message part handling to use Blob and Uri types
keith-decker Mar 4, 2026
6512305
Merge remote-tracking branch 'origin/main' into pr1-enhance-toolcall-…
keith-decker Mar 4, 2026
124abd0
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker Mar 5, 2026
73b8369
Add ServerToolCall and ServerToolCallResponse models with tests
keith-decker Mar 9, 2026
24b1721
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker Mar 9, 2026
dc4f7c2
refactor: streamline Blob and Uri handling in message processing
keith-decker Mar 10, 2026
828e954
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker Mar 10, 2026
e1fdd08
convert anthropic to toolcallrequest and remove toolcall from message…
keith-decker Mar 11, 2026
978d837
Merge branch 'pr1-enhance-toolcall-type' of github.com:keith-decker/o…
keith-decker Mar 11, 2026
1f336d3
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker Mar 12, 2026
cdec2bc
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker Mar 17, 2026
e7f07f6
move error.type to base genai class
keith-decker Mar 17, 2026
3730a3e
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker Mar 19, 2026
dbac1b6
Merge branch 'main' into pr1-enhance-toolcall-type
xrmx Mar 20, 2026
ecfb339
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker Mar 24, 2026
d5997ec
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker Mar 25, 2026
70c7804
Merge branch 'main' into pr1-enhance-toolcall-type
keith-decker Mar 26, 2026
01ab8ae
update version requirements
keith-decker Mar 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
FinishReason,
MessagePart,
Text,
ToolCall,
ToolCallRequest,
ToolCallResponse,
)
from opentelemetry.util.genai.utils import get_content_capturing_mode
Expand Down Expand Up @@ -341,7 +341,7 @@ def convert_content_to_message_parts(
elif "function_call" in part:
part = part.function_call
parts.append(
ToolCall(
ToolCallRequest(
id=f"{part.name}_{idx}",
name=part.name,
arguments=json_format.MessageToDict(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ opentelemetry-api==1.37
opentelemetry-sdk==1.37
opentelemetry-semantic-conventions==0.58b0
opentelemetry-instrumentation==0.58b0
opentelemetry-util-genai[upload]==0.2b0
# opentelemetry-util-genai[upload]==0.2b0
-e util/opentelemetry-util-genai[upload]
fsspec==2025.9.0

-e instrumentation-genai/opentelemetry-instrumentation-vertexai[instruments]
2 changes: 2 additions & 0 deletions util/opentelemetry-util-genai/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- Enrich ToolCall type ([#4218](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4218))
Comment thread
keith-decker marked this conversation as resolved.
Outdated

## Version 0.3b0 (2026-02-20)

- Add `gen_ai.tool_definitions` to completion hook ([#4181](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/4181))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ContentCapturingMode(Enum):


@dataclass()
class ToolCall:
class ToolCallRequest:
Comment thread
lmolkova marked this conversation as resolved.
"""Represents a tool call requested by the model

This model is specified as part of semconv in `GenAI messages Python models - ToolCallRequestPart
Expand All @@ -55,6 +55,40 @@ class ToolCall:
type: Literal["tool_call"] = "tool_call"
Comment thread
DylanRussell marked this conversation as resolved.


@dataclass()
class ToolCall(ToolCallRequest):
Comment thread
keith-decker marked this conversation as resolved.
Outdated
"""Represents a tool call for execution tracking with spans and metrics.

This type extends ToolCallRequest with additional fields for tracking tool execution
per the execute_tool span semantic conventions.

Reference: https://github.com/open-telemetry/semantic-conventions/blob/main/docs/gen-ai/gen-ai-spans.md#execute-tool-span

For simple message parts (tool calls requested by the model), consider using
ToolCallRequest instead to avoid unnecessary execution-tracking fields.

Semantic convention attributes for execute_tool spans:
- gen_ai.operation.name: "execute_tool" (Required)
- gen_ai.tool.name: Name of the tool (Recommended)
- gen_ai.tool.call.id: Tool call identifier (Recommended if available)
- gen_ai.tool.type: Type classification - "function", "extension", or "datastore" (Recommended if available)
- gen_ai.tool.description: Tool description (Recommended if available)
- gen_ai.tool.call.arguments: Parameters passed to tool (Opt-In, may contain sensitive data)
- gen_ai.tool.call.result: Result returned by tool (Opt-In, may contain sensitive data)
- error.type: Error type if operation failed (Conditionally Required)
"""

# Execution-only fields (used for execute_tool spans):
# gen_ai.tool.type - Tool type: "function", "extension", or "datastore"
tool_type: str | None = None
# gen_ai.tool.description - Description of what the tool does
tool_description: str | None = None
# gen_ai.tool.call.result - Result returned by the tool (Opt-In, may contain sensitive data)
tool_result: Any = None
# error.type - Error type if the tool call failed
error_type: str | None = None


@dataclass()
class ToolCallResponse:
"""Represents a tool call result sent to the model or a built-in tool call outcome and details
Expand Down Expand Up @@ -158,7 +192,15 @@ class GenericToolDefinition:
ToolDefinition = Union[FunctionToolDefinition, GenericToolDefinition]

MessagePart = Union[
Text, ToolCall, ToolCallResponse, Blob, File, Uri, Reasoning, Any
Text,
ToolCallRequest,
ToolCall,
ToolCallResponse,
Blob,
File,
Uri,
Reasoning,
Any,
Comment thread
DylanRussell marked this conversation as resolved.
Outdated
]


Expand Down
165 changes: 165 additions & 0 deletions util/opentelemetry-util-genai/tests/test_toolcall.py
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"])
2 changes: 1 addition & 1 deletion util/opentelemetry-util-genai/tests/test_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
types.InputMessage(
role="assistant",
parts=[
types.ToolCall(
types.ToolCallRequest(
id="get_capital_0",
name="get_capital",
arguments={"city": "Paris"},
Expand Down
Loading