MCPcopy Create free account
hub / github.com/agentforce314/clawcodex / extract_partial_result

Function extract_partial_result

src/agent/agent_tool_utils.py:315–332  ·  view source on GitHub ↗

Extract a partial result string from agent messages. Used when an async agent is killed to preserve what it accomplished.

(messages: list[Message])

Source from the content-addressed store, hash-verified

313
314
315def 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
335def _extract_tool_name(tool_spec: str) -> str:

Callers 6

_background_lifecycleFunction · 0.90
test_empty_messagesMethod · 0.90
test_text_contentMethod · 0.90
test_block_contentMethod · 0.90

Calls 2

joinMethod · 0.80
appendMethod · 0.45

Tested by 5

test_empty_messagesMethod · 0.72
test_text_contentMethod · 0.72
test_block_contentMethod · 0.72