fix(delegate): handle content-block tool results
This commit is contained in:
committed by
Teknium
parent
16beab421f
commit
f83918c31d
@@ -554,6 +554,37 @@ class TestDelegateObservability(unittest.TestCase):
|
||||
self.assertIn("result_bytes", entry["tool_trace"][0])
|
||||
self.assertEqual(entry["tool_trace"][0]["status"], "ok")
|
||||
|
||||
def test_tool_trace_handles_list_content_blocks(self):
|
||||
"""Tool-result content blocks should not crash observability metadata."""
|
||||
parent = _make_mock_parent(depth=0)
|
||||
|
||||
with patch("run_agent.AIAgent") as MockAgent:
|
||||
mock_child = MagicMock()
|
||||
mock_child.model = "claude-sonnet-4-6"
|
||||
mock_child.session_prompt_tokens = 0
|
||||
mock_child.session_completion_tokens = 0
|
||||
mock_child.run_conversation.return_value = {
|
||||
"final_response": "done",
|
||||
"completed": True,
|
||||
"interrupted": False,
|
||||
"api_calls": 1,
|
||||
"messages": [
|
||||
{"role": "assistant", "tool_calls": [
|
||||
{"id": "tc_1", "function": {"name": "image_generate", "arguments": '{"prompt": "x"}'}}
|
||||
]},
|
||||
{"role": "tool", "tool_call_id": "tc_1", "content": [
|
||||
{"type": "text", "text": '{"success": true}'},
|
||||
]},
|
||||
],
|
||||
}
|
||||
MockAgent.return_value = mock_child
|
||||
|
||||
result = json.loads(delegate_task(goal="Test list content", parent_agent=parent))
|
||||
trace = result["results"][0]["tool_trace"]
|
||||
self.assertEqual(trace[0]["tool"], "image_generate")
|
||||
self.assertEqual(trace[0]["status"], "ok")
|
||||
self.assertGreater(trace[0]["result_bytes"], 0)
|
||||
|
||||
def test_tool_trace_detects_error(self):
|
||||
"""Tool results containing 'error' should be marked as error status."""
|
||||
parent = _make_mock_parent(depth=0)
|
||||
|
||||
Reference in New Issue
Block a user