Skip to content

Conversation

@KeremTurgutlu
Copy link
Contributor

@KeremTurgutlu KeremTurgutlu commented Jan 27, 2026

This PR enables AI to reference previous tool results in subsequent tool calls using $tool_call_id`` syntax when tc_refs=True.

Changes:

  • Added tc_refs=False parameter to Chat.__init__ — when enabled, initializes self.tc_res={} and appends syntax instructions to system prompt
  • Added tc_res_sysp constant — system prompt text explaining the $tool_call_id`` syntax with example
  • Added _prep_tool_res() — prepends [tool_call_id: ...] text block to tool results so AI can see the ID
  • Added _resolve_tool_refs() — parses tool arguments and replaces $id`` with actual stored results before calling function
  • Updated _lite_call_func and _alite_call_func — stores raw results in tc_res dict and calls _resolve_tool_refs for reference resolution

Nit

  • Fixed patch_litellm ID generation — changed +/ translation to __ so IDs match Anthropic's srvtoolu_[a-zA-Z0-9_]+ pattern

Example:

def get_data(): return "Hello"
def process(content: str): return content.upper()

chat = Chat('claude-sonnet-4-5', tools=[get_data, process], tc_refs=True)
chat("Call get_data, then pass the result to process", max_steps=10)
chat.tc_res  # {'toolu_abc': 'Hello', 'toolu_xyz': 'HELLO'}

Fixes #95 and #96

Example test dialog: https://share.solve.it.com/d/72c67213c1cf5345698a8fb010505995

@KeremTurgutlu KeremTurgutlu changed the title Tool call ids and referencing Tool call ids and results referencing Jan 27, 2026
@KeremTurgutlu KeremTurgutlu requested review from jph00 and removed request for jph00 January 27, 2026 13:53
@jph00
Copy link
Contributor

jph00 commented Jan 27, 2026

Great stuff! :)

BTW @KeremTurgutlu this was super hard to review, because there's so much output I had to scroll through to try to find your actual changes. Are we using cachy on all these pages? Can you try to try to make it so re-running these pages doesn't change the output?

@jph00
Copy link
Contributor

jph00 commented Jan 27, 2026

BTW one thing I'm torn about is whether we should be changing the system prompt automatically. Something to keep an eye on...

@jph00 jph00 merged commit 55d1b8e into main Jan 27, 2026
1 check passed
@jph00 jph00 added the enhancement New feature or request label Jan 27, 2026
@jph00
Copy link
Contributor

jph00 commented Jan 27, 2026

Oh don't forget to label your PRs :)

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tell the AI what the tool call ID was, if possible

3 participants