Build a structured dict representing one tool's output. Schema ------ { "tool": str, # tool name "target": str, # target passed to the tool "timestamp": str, # ISO-8601 UTC timestamp "results": list[str], # non-empty o
(
tool: str,
target: str,
result: str,
error: str | None = None,
)
| 12 | |
| 13 | |
| 14 | def format_tool_result( |
| 15 | tool: str, |
| 16 | target: str, |
| 17 | result: str, |
| 18 | error: str | None = None, |
| 19 | ) -> dict: |
| 20 | """ |
| 21 | Build a structured dict representing one tool's output. |
| 22 | |
| 23 | Schema |
| 24 | ------ |
| 25 | { |
| 26 | "tool": str, # tool name |
| 27 | "target": str, # target passed to the tool |
| 28 | "timestamp": str, # ISO-8601 UTC timestamp |
| 29 | "results": list[str], # non-empty output lines |
| 30 | "error": str | null # error message if the call failed |
| 31 | } |
| 32 | """ |
| 33 | lines = [ln for ln in result.splitlines() if ln.strip()] if result else [] |
| 34 | return { |
| 35 | "tool": tool, |
| 36 | "target": target, |
| 37 | "timestamp": datetime.now(timezone.utc).isoformat(), |
| 38 | "results": lines, |
| 39 | "error": error, |
| 40 | } |
| 41 | |
| 42 | |
| 43 | def to_json( |
no outgoing calls