66"""
77
88from abc import ABC , abstractmethod
9- from typing import TYPE_CHECKING , Any , Dict , List , Literal , Optional , Union
9+ from typing import TYPE_CHECKING , Any , Generator , Literal , Optional , Union
1010
1111from typing_extensions import TypedDict
1212
@@ -90,7 +90,7 @@ class ToolResult(TypedDict):
9090 toolUseId: The unique identifier of the tool use request that produced this result.
9191 """
9292
93- content : List [ToolResultContent ]
93+ content : list [ToolResultContent ]
9494 status : ToolResultStatus
9595 toolUseId : str
9696
@@ -122,9 +122,9 @@ class ToolChoiceTool(TypedDict):
122122
123123
124124ToolChoice = Union [
125- Dict [Literal ["auto" ], ToolChoiceAuto ],
126- Dict [Literal ["any" ], ToolChoiceAny ],
127- Dict [Literal ["tool" ], ToolChoiceTool ],
125+ dict [Literal ["auto" ], ToolChoiceAuto ],
126+ dict [Literal ["any" ], ToolChoiceAny ],
127+ dict [Literal ["tool" ], ToolChoiceTool ],
128128]
129129"""
130130Configuration for how the model should choose tools.
@@ -135,6 +135,10 @@ class ToolChoiceTool(TypedDict):
135135"""
136136
137137
138+ ToolGenerator = Generator [dict [str , Any ], None , ToolResult ]
139+ """Generator of tool events and a returned tool result."""
140+
141+
138142class ToolConfig (TypedDict ):
139143 """Configuration for tools in a model request.
140144
@@ -143,7 +147,7 @@ class ToolConfig(TypedDict):
143147 toolChoice: Configuration for how the model should choose tools.
144148 """
145149
146- tools : List [Tool ]
150+ tools : list [Tool ]
147151 toolChoice : ToolChoice
148152
149153
@@ -250,7 +254,7 @@ def process(
250254 messages : "Messages" ,
251255 tool_config : ToolConfig ,
252256 kwargs : dict [str , Any ],
253- ) -> ToolResult :
257+ ) -> ToolGenerator :
254258 """Process a tool use request and execute the tool.
255259
256260 Args:
@@ -261,7 +265,10 @@ def process(
261265 tool_config: The tool configuration for the current session.
262266 kwargs: Additional context-specific arguments.
263267
268+ Yields:
269+ Events of the tool invocation.
270+
264271 Returns:
265- The result of the tool execution .
272+ The final tool result .
266273 """
267274 ...
0 commit comments