| 98 | |
| 99 | @dataclass |
| 100 | class ToolResult: |
| 101 | text: str |
| 102 | resources: List[str] = field(default_factory=list) |
| 103 | extra: dict = field(default_factory=dict) |
| 104 | |
| 105 | @staticmethod |
| 106 | def from_raw(raw): |
| 107 | if isinstance(raw, str): |
| 108 | return ToolResult(text=raw) |
| 109 | if isinstance(raw, dict): |
| 110 | return ToolResult( |
| 111 | text=str(raw.get('text', '')), |
| 112 | resources=raw.get('resources', []), |
| 113 | extra={ |
| 114 | k: v |
| 115 | for k, v in raw.items() if k not in ['text', 'resources'] |
| 116 | }) |
| 117 | raise TypeError('tool_call_result must be str or dict') |