| 150 | |
| 151 | |
| 152 | class DummyToolManager: |
| 153 | def __init__(self, return_result=None, raise_exception=False): |
| 154 | self.return_result = return_result or { |
| 155 | "isError": False, |
| 156 | "content": "Tool executed successfully", |
| 157 | } |
| 158 | self.raise_exception = raise_exception |
| 159 | self.executed_tool = None |
| 160 | self.executed_args = None |
| 161 | |
| 162 | async def stream_execute_tools( |
| 163 | self, calls, timeout=None, on_tool_start=None, max_concurrency=4 |
| 164 | ): |
| 165 | for call in calls: |
| 166 | self.executed_tool = call.tool |
| 167 | self.executed_args = call.arguments |
| 168 | |
| 169 | if on_tool_start: |
| 170 | await on_tool_start(call) |
| 171 | |
| 172 | now = datetime.now(UTC) |
| 173 | if self.raise_exception: |
| 174 | yield CTPToolResult( |
| 175 | id=call.id, |
| 176 | tool=call.tool, |
| 177 | result=None, |
| 178 | error="Simulated exception", |
| 179 | start_time=now, |
| 180 | end_time=now, |
| 181 | machine=platform.node(), |
| 182 | pid=os.getpid(), |
| 183 | ) |
| 184 | elif self.return_result.get("isError"): |
| 185 | yield CTPToolResult( |
| 186 | id=call.id, |
| 187 | tool=call.tool, |
| 188 | result=None, |
| 189 | error=self.return_result.get("error", "Error"), |
| 190 | start_time=now, |
| 191 | end_time=now, |
| 192 | machine=platform.node(), |
| 193 | pid=os.getpid(), |
| 194 | ) |
| 195 | else: |
| 196 | yield CTPToolResult( |
| 197 | id=call.id, |
| 198 | tool=call.tool, |
| 199 | result=self.return_result.get("content"), |
| 200 | error=None, |
| 201 | start_time=now, |
| 202 | end_time=now, |
| 203 | machine=platform.node(), |
| 204 | pid=os.getpid(), |
| 205 | ) |
| 206 | |
| 207 | |
| 208 | class CancellingToolManager: |
no outgoing calls