Skip to content

The agent that grows with you

fix(compression): skill-tool summaries carry skill names and failure outcome

Konstantin Khlopkov031654650f22
diff --git a/agent/context_compressor.py b/agent/context_compressor.py
index 41d92dee2b9..b231558a30c 100644
--- a/agent/context_compressor.py
+++ b/agent/context_compressor.py
@@ -1490,8 +1490,46 @@ def _sum_clarify(name, args, content, content_len, line_count):
return "[clarify] asked user a question"
-def _sum_named(name, args, content, content_len, line_count):
- return f"[{name}] name={args.get('name', '?')} ({content_len:,} chars)"
+def _sum_skill_manage(name, args, content, content_len, line_count):
+ # The advertised call shape is an operations array; the legacy flat shape
+ # (top-level action/name) is still accepted, so both must summarize to a
+ # skill name instead of `name=?` — there is no top-level `name` arg here.
+ ops = args.get("operations")
+ if isinstance(ops, list) and ops:
+ rendered = []
+ for op in ops:
+ if not isinstance(op, dict):
+ continue
+ action = _str_arg(op, "action", "?")
+ op_name = _str_arg(op, "name", "?")
+ rendered.append(f"{action} {op_name}")
+ summary = f"[skill_manage] {'; '.join(rendered[:3])}"
+ if len(ops) > 3:
+ summary += f" (+{len(ops) - 3} more)"
+ else:
+ action = _str_arg(args, "action", "?")
+ op_name = _str_arg(args, "name", "?")
+ summary = f"[skill_manage] {action} {op_name}"
+ payload = _json_dict(content)
+ error = payload.get("error")
+ if error:
+ summary += f" FAILED: {str(error)[:80]}"
+ return f"{summary} ({content_len:,} chars)"
+
+
+def _sum_skills_list(name, args, content, content_len, line_count):
+ # `skills_list` takes category/query, not a top-level `name` — the count
+ # from the payload is what identifies the call after compression.
+ category = _str_arg(args, "category")
+ scope = f" category={category}" if category else ""
+ payload = _json_dict(content)
+ count = payload.get("count")
+ listed = f" {count} skills" if isinstance(count, int) else ""
+ summary = f"[skills_list]{scope}{listed}"
+ error = payload.get("error")
+ if error:
+ summary += f" FAILED: {str(error)[:80]}"
+ return f"{summary} ({content_len:,} chars)"
def _sum_template(template: str, **defaults):
@@ -1517,8 +1555,8 @@ _TOOL_RESULT_SUMMARIZERS = {
"delegate_task": _sum_delegate_task,
"execute_code": _sum_execute_code,
"skill_view": _sum_skill_view,
- "skills_list": _sum_named,
- "skill_manage": _sum_named,
+ "skills_list": _sum_skills_list,
+ "skill_manage": _sum_skill_manage,
"vision_analyze": lambda name, args, content, content_len, line_count: (
f"[vision_analyze] '{_str_arg(args, 'question')[:50]}' ({content_len:,} chars)"
),
diff --git a/tests/agent/test_compressor_skill_tool_summaries.py b/tests/agent/test_compressor_skill_tool_summaries.py
new file mode 100644
index 00000000000..9c84d95f484
--- /dev/null
+++ b/tests/agent/test_compressor_skill_tool_summaries.py
@@ -0,0 +1,118 @@
+"""Summaries of skill-tool results must carry the skill names and the failure
+outcome across compression — `skill_manage` names live inside ``operations``
+(or the legacy flat shape), and ``skills_list`` has no top-level ``name`` at
+all. A failed call must never compress into a success-shaped line."""
+
+import json
+
+from agent.context_compressor import _summarize_tool_result
+
+
+class TestSummarizeSkillManage:
+ def test_operations_array_names_the_skills(self):
+ args = json.dumps({
+ "operations": [
+ {
+ "action": "create",
+ "name": "orca-ade",
+ "content": "---\nname: orca-ade\n---\nbody",
+ },
+ {
+ "action": "patch",
+ "name": "llama-server",
+ "old_string": "a",
+ "new_string": "b",
+ },
+ ]
+ })
+ content = json.dumps({
+ "success": True,
+ "operations_applied": 2,
+ "results": [
+ {"name": "orca-ade", "action": "create", "success": True},
+ {"name": "llama-server", "action": "patch", "success": True},
+ ],
+ })
+ summary = _summarize_tool_result("skill_manage", args, content)
+ assert "create orca-ade" in summary
+ assert "patch llama-server" in summary
+ assert "name=?" not in summary
+ assert "FAILED" not in summary
+
+ def test_failed_batch_keeps_error_visible(self):
+ args = json.dumps({"operations": [{"action": "create", "name": "orca-ade"}]})
+ content = json.dumps({
+ "success": False,
+ "error": (
+ "operations[0] (create on 'orca-ade') failed: content is "
+ "required for 'create' — batch aborted, all touched skills "
+ "rolled back."
+ ),
+ })
+ summary = _summarize_tool_result("skill_manage", args, content)
+ assert "FAILED" in summary
+ assert "create orca-ade" in summary
+ assert "content is required" in summary
+
+ def test_legacy_flat_shape_names_the_skill(self):
+ args = json.dumps({"action": "delete", "name": "stale-skill"})
+ content = json.dumps({
+ "success": True,
+ "message": "Skill 'stale-skill' deleted.",
+ })
+ summary = _summarize_tool_result("skill_manage", args, content)
+ assert "delete stale-skill" in summary
+ assert "name=?" not in summary
+ assert "FAILED" not in summary
+
+ def test_malformed_ops_render_guarded_not_crash(self):
+ args = json.dumps({"operations": ["not-a-dict", 42]})
+ content = json.dumps({
+ "success": False,
+ "error": "operations[0] needs an 'action'.",
+ })
+ summary = _summarize_tool_result("skill_manage", args, content)
+ assert summary.startswith("[skill_manage]")
+ assert "FAILED" in summary
+
+ def test_error_text_is_bounded_to_one_line(self):
+ args = json.dumps({"operations": [{"action": "patch", "name": "s"}]})
+ content = json.dumps({"success": False, "error": "x" * 500})
+ summary = _summarize_tool_result("skill_manage", args, content)
+ assert "\n" not in summary
+ assert len(summary) < 250
+
+
+class TestSummarizeSkillsList:
+ def test_success_lists_count_and_category(self):
+ args = json.dumps({"category": "devops"})
+ content = json.dumps({
+ "success": True,
+ "skills": [{"name": "a"}, {"name": "b"}],
+ "categories": ["devops"],
+ "count": 2,
+ })
+ summary = _summarize_tool_result("skills_list", args, content)
+ assert "category=devops" in summary
+ assert "2 skills" in summary
+ assert "name=?" not in summary
+ assert "FAILED" not in summary
+
+ def test_failure_keeps_error_visible(self):
+ args = json.dumps({})
+ content = json.dumps({"success": False, "error": "skills directory unreadable"})
+ summary = _summarize_tool_result("skills_list", args, content)
+ assert "FAILED" in summary
+ assert "skills directory unreadable" in summary
+
+
+class TestSummarizerRegistryEntries:
+ def test_skill_tool_stubs_never_render_question_name(self):
+ cases = [
+ ("skills_list", "{}", '{"success": true, "skills": [], "count": 0}'),
+ ("skill_manage", "{}", '{"success": true}'),
+ ("skill_view", '{"name": "real-skill"}', "x" * 300),
+ ]
+ for tool, args, content in cases:
+ summary = _summarize_tool_result(tool, args, content)
+ assert "name=?" not in summary, (tool, summary)