haystack icon indicating copy to clipboard operation
haystack copied to clipboard

Pass down ToolCall.id to the tool function

Open datbth opened this issue 1 month ago • 1 comments

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:

  1. User message
  2. Assistant message 1
  3. Tool 1 i. Tool 1a ii. Tool 1b
  4. Assistant message 2
  5. 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: Image
    • Or as context variable
  • Or provide a way for the tool function to save additional details to the ChatMessage's meta

datbth avatar Dec 08 '25 10:12 datbth

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.

tommasocerruti avatar Dec 09 '25 08:12 tommasocerruti

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?

vblagoje avatar Dec 15 '25 10:12 vblagoje

@sjrl if we don't hear from @datbth please consider closing this issue

vblagoje avatar Dec 17 '25 13:12 vblagoje