Outcome of a tool execution. ENHANCED: Now wraps chuk_tool_processor.models.tool_result.ToolResult for full tracking (start_time, end_time, machine, pid, cached, attempts). Provides simplified interface for backward compatibility while exposing chuk's rich result data via .chu
| 243 | |
| 244 | |
| 245 | class ToolCallResult(BaseModel): |
| 246 | """ |
| 247 | Outcome of a tool execution. |
| 248 | |
| 249 | ENHANCED: Now wraps chuk_tool_processor.models.tool_result.ToolResult |
| 250 | for full tracking (start_time, end_time, machine, pid, cached, attempts). |
| 251 | |
| 252 | Provides simplified interface for backward compatibility while exposing |
| 253 | chuk's rich result data via .chuk_result property. |
| 254 | """ |
| 255 | |
| 256 | tool_name: str |
| 257 | success: bool |
| 258 | result: Any = None |
| 259 | error: str | None = None |
| 260 | execution_time: float | None = None |
| 261 | |
| 262 | # Rich chuk result data (optional, provides full tracking) |
| 263 | chuk_result: Any | None = None |
| 264 | |
| 265 | model_config = {"frozen": False, "arbitrary_types_allowed": True, "extra": "allow"} |
| 266 | |
| 267 | @classmethod |
| 268 | def from_chuk_result(cls, tool_result: Any) -> "ToolCallResult": |
| 269 | """ |
| 270 | Create ToolCallResult from chuk's ToolResult. |
| 271 | |
| 272 | Args: |
| 273 | tool_result: chuk_tool_processor.models.tool_result.ToolResult |
| 274 | |
| 275 | Returns: |
| 276 | ToolCallResult with data mapped from chuk's ToolResult |
| 277 | """ |
| 278 | # Calculate execution time from start/end |
| 279 | execution_time = None |
| 280 | if hasattr(tool_result, "start_time") and hasattr(tool_result, "end_time"): |
| 281 | if tool_result.start_time and tool_result.end_time: |
| 282 | delta = tool_result.end_time - tool_result.start_time |
| 283 | execution_time = delta.total_seconds() |
| 284 | |
| 285 | return cls( |
| 286 | tool_name=tool_result.tool, |
| 287 | success=(tool_result.error is None), |
| 288 | result=tool_result.result, |
| 289 | error=tool_result.error, |
| 290 | execution_time=execution_time, |
| 291 | chuk_result=tool_result, |
| 292 | ) |
| 293 | |
| 294 | @property |
| 295 | def is_cached(self) -> bool: |
| 296 | """Check if result was cached.""" |
| 297 | if self.chuk_result and hasattr(self.chuk_result, "cached"): |
| 298 | return bool(self.chuk_result.cached) |
| 299 | return False |
| 300 | |
| 301 | @property |
| 302 | def attempts(self) -> int: |
no outgoing calls