Pass down ToolCall.id to the tool function
Is your feature request related to a problem? Please describe.
I'm displaying a tree of tool calls (i.e. a tool can call its sub-tools or sub-agents), so I need a way for sub-tool calls to refer to their parent tool call.
While there are various ways to generate a UUID and pass it down to tool functions, it is not feasible to persist those IDs into the ChatMessages => It's not feasible to reconstruct the conversation UI from the result ChatMessages.
Imagine a UI that displays:
- User message
- Assistant message 1
- Tool 1 i. Tool 1a ii. Tool 1b
- Assistant message 2
- Tool 2
=> Need a way to persist Tool 1a and Tool 1b that can
- Link them to their parent: Tool 1
- Reconstruct the whole conversation (including User message, Assistant message 1, Assistant message 2) in the correct order
Describe the solution you'd like Either
- Pass down the LLM's tool call id to the tool function
- As direct argument. Here is my monkey-patch:
- Or as context variable
- As direct argument. Here is my monkey-patch:
- Or provide a way for the tool function to save additional details to the ChatMessage's meta
I can take this. I would go for approach 1 (pass the LLM tool call id directly) as an optional tool_call_id kwarg, injected only if the tool’s signature accepts it. This keeps the API explicit, avoids hidden global state, and is fully backward-compatible. But before starting to implement it, I'll wait for feedback on this.
Hey @datbth what are you trying to achieve (i.e. what is your higher level scope/objective)? IMHO it's a bit odd to trace this hierarchy via tool call ids - it doesn't intuitively seem to be the best place to track something like this? Please give us some more context. Can't you use open telemetry spans for something like this?
@sjrl if we don't hear from @datbth please consider closing this issue