Skip to content

GenAI Utils | Update ToolCall Type#4218

Open
keith-decker wants to merge 19 commits intoopen-telemetry:mainfrom
keith-decker:pr1-enhance-toolcall-type
Open

GenAI Utils | Update ToolCall Type#4218
keith-decker wants to merge 19 commits intoopen-telemetry:mainfrom
keith-decker:pr1-enhance-toolcall-type

Conversation

@keith-decker
Copy link
Contributor

@keith-decker keith-decker commented Feb 19, 2026

Description

Update the tool type to match semantic conventions for GenAI Spans.

TelemetryHandler functions for start_tool and stop_tool coming in next PR.

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • basic setters and getter functions

Does This PR Require a Core Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@keith-decker keith-decker force-pushed the pr1-enhance-toolcall-type branch from f766cd6 to 9b3f2a6 Compare February 19, 2026 22:59
@keith-decker keith-decker marked this pull request as ready for review February 23, 2026 18:30
@keith-decker
Copy link
Contributor Author

I think the docker tests failure is unrelated to this PR.

arguments: Any
name: str
id: str | None
type: Literal["tool_call"] = "tool_call"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we are to have 2 different types here, should we also have 2 different type names ? Otherwise why not just have 1 type that encompasses both ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially started with one type, but ended up blowing up the vertex tests with extra data. It looks like vertexai uses toolcall as part of the body of an LLM request.

I separated these into two types to distinguish between toolcallrequests that are part of an LLM invocation, and a tool execution that may be stand alone.

What are your thoughts on that approach?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable but what's in the sem convs ? I think we want these types to match the sem coonvs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type here refers to the "type" in the message part for ToolCallRequest (https://github.com/open-telemetry/semantic-conventions/blob/95c6e0a3c6803c6546fc66847855761e9c90f9c6/docs/gen-ai/non-normative/models.ipynb?plain=1)

The type in the new ToolCall refers to the type defined here (https://github.com/open-telemetry/semantic-conventions/blob/95c6e0a3c6803c6546fc66847855761e9c90f9c6/docs/gen-ai/gen-ai-spans.md?plain=1#L618) which is a span level attribute instead of part of the message.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type is weirdly named tool_call instead of tool_call_request in the sem conv.. oh well.

That second type https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-spans/#execute-tool-span -- seems like it's just supposed to be a string though unless I'm missing something ??

@aabmass
Copy link
Member

aabmass commented Feb 26, 2026

I'm a little confused.ToolCall is just a wrapper as part of GenAI util for instrumentation purposes? This is separate from the ToolCallRequest and ToolCallResponse json schemas in here which defines an actual data format.

Is that right?



@dataclass()
class ToolCall(ToolCallRequest):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it inherit class ToolCall(GenAIInvocation) instead ? ToolCallRequest can be separate and ok to have its attributes duplicated in ToolCall?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored to extend GenAIInvocation instead. Separated ToolCallRequest to align with message parts

@tammy-baylis-swi tammy-baylis-swi moved this to Ready for review in Python PR digest Feb 26, 2026
@tammy-baylis-swi tammy-baylis-swi moved this from Ready for review to Reviewed PRs that need fixes in Python PR digest Feb 26, 2026
@keith-decker
Copy link
Contributor Author

keith-decker commented Mar 2, 2026

I'm a little confused.ToolCall is just a wrapper as part of GenAI util for instrumentation purposes? This is separate from the ToolCallRequest and ToolCallResponse json schemas in here which defines an actual data format.

Is that right?

@aabmass As discussed in the SIG call on thursday:
The types here called it ToolCall instead of ToolCallRequest like in the "GenAI messages Python models" link here. Changing the names aligns them with that part of the semconvs, and opens ToolCall type for use with the execute_tool span conventions here

yield user_event(role=content.role, content=request_content)


@dataclass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where this was moved but we can put BlobPart into the Gen AI util types and also add it to Message part --- that's how it exists in the sem convs (https://github.com/open-telemetry/semantic-conventions/blob/95c6e0a3c6803c6546fc66847855761e9c90f9c6/docs/gen-ai/non-normative/models.ipynb?plain=1)

That way we don't need to wrap it in a GenericPart (it should be it's own part)

@@ -30,6 +30,17 @@
ContextToken: TypeAlias = Token[Context]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if you saw but https://github.com/open-telemetry/semantic-conventions/pull/3038/changes was merged.. This adds 4 new types:

GenericServerToolCall/GenerticServerToolCallResponse (not added to MessagePart.. maybe because GenericPart is already there)

also ServerToolCallPart/ServerToolCallResponsePart (added to MessagePart)

Maybe we can use this PR to just get completely in sync with https://github.com/open-telemetry/semantic-conventions/blob/95c6e0a3c6803c6546fc66847855761e9c90f9c6/docs/gen-ai/non-normative/models.ipynb?plain=1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

9 participants