From 7b450c8215f329eda0b0d844af53ff77745c31b1 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sat, 10 May 2025 11:06:38 -0700 Subject: [PATCH] Response.add_tool_call() method and ToolCall class Refs https://github.com/simonw/llm/issues/936#issuecomment-2869064678 --- llm/models.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/llm/models.py b/llm/models.py index 74d60ce..025f187 100644 --- a/llm/models.py +++ b/llm/models.py @@ -177,6 +177,12 @@ class Tool: ) +@dataclass +class ToolCall: + name: str + arguments: dict + + @dataclass class Prompt: _prompt: Optional[str] @@ -387,6 +393,7 @@ class _BaseResponse: self._key = key self._chunks: List[str] = [] self._done = False + self.tool_calls: List[ToolCall] = [] self.response_json = None self.conversation = conversation self.attachments: List[Attachment] = [] @@ -404,6 +411,9 @@ class _BaseResponse: if self.prompt.tools and not self.model.supports_tools: raise ValueError(f"{self.model} does not support tools") + def add_tool_call(self, tool_call: ToolCall): + self.tool_calls.append(tool_call) + def set_usage( self, *,