Extract a partial result string from agent messages. Used when an async agent is killed to preserve what it accomplished.
(messages: list[Message])
| 313 | |
| 314 | |
| 315 | def extract_partial_result(messages: list[Message]) -> str | None: |
| 316 | """Extract a partial result string from agent messages. |
| 317 | |
| 318 | Used when an async agent is killed to preserve what it accomplished. |
| 319 | """ |
| 320 | for msg in reversed(messages): |
| 321 | if isinstance(msg, AssistantMessage): |
| 322 | raw = msg.content |
| 323 | if isinstance(raw, str) and raw.strip(): |
| 324 | return raw |
| 325 | if isinstance(raw, list): |
| 326 | texts = [] |
| 327 | for block in raw: |
| 328 | if hasattr(block, "type") and block.type == "text" and block.text: |
| 329 | texts.append(block.text) |
| 330 | if texts: |
| 331 | return "\n".join(texts) |
| 332 | return None |
| 333 | |
| 334 | |
| 335 | def _extract_tool_name(tool_spec: str) -> str: |