Repository navigation
feat(subagent): give spawned sub-agents a condenser by default - #3696
Conversation
Spawned sub-agents (task/delegate/workflow) were a special case that never got the summarizing condenser every top-level agent has, so a deep sub-agent run dead-ended on context-window overflow instead of auto-compacting. agent_definition_to_factory now attaches a default summarizing condenser to sub-agents (shared sizing with the preset via a new sdk default_condenser helper), using a distinct usage_id so its tokens are tracked rather than deduped out of conversation stats. Add an optional AgentDefinition.condenser field (markdown: omit for default, 'none'/false to disable, mapping for a custom spec) so it stays overridable and serializes for the remote path.
Python API breakage checks — ✅ PASSEDResult: ✅ PASSED |
REST API breakage checks (OpenAPI) — ✅ PASSEDResult: ✅ PASSED |
all-hands-bot
left a comment
There was a problem hiding this comment.
⚠️ QA Report: PASS WITH ISSUES
The sub-agent condenser behavior works as described in real SDK usage; the only issue I found is the existing PR Description Check failure, which needs a human PR-description update.
Does this PR achieve its stated goal?
Yes. On main, a Markdown-loaded sub-agent factory produced an agent with agent_condenser: null, so spawned sub-agents had no default compaction path. On this PR, the same SDK flow produces LLMSummarizingCondenser with max_size: 80, keep_first: 4, and a separate condenser usage ID; condenser: none and condenser: false both produce NoOpCondenser. I also exercised the PR branch with a live LLM-backed condenser call over 90 events, and it returned a real Condensation with a summary and 51 forgotten events.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed successfully and installed the uv environment. |
| CI Status | Validate PR description is failing with template/HUMAN-field errors. |
| Functional Verification | ✅ Default condenser, opt-out frontmatter, sizing parity, distinct usage ID, and live condensation were verified through SDK calls. |
Functional Verification
Test 1: File-based sub-agent factory default and opt-out behavior
Step 1 — Reproduce / establish baseline without the fix:
Ran git checkout --detach origin/main && uv run python /tmp/qa_subagent_condenser.py.
Relevant output:
{"agent_condenser": null, "agent_llm_usage_id": "agent", "definition_condenser": null, "label": "absent", "metadata_keys": []}
{"agent_condenser": null, "definition_condenser": null, "label": "disabled_string", "metadata_keys": ["condenser"]}
{"agent_condenser": null, "definition_condenser": null, "label": "disabled_boolean", "metadata_keys": ["condenser"]}
{"label": "top_level_default_preset", "preset_condenser": "LLMSummarizingCondenser", "preset_keep_first": 4, "preset_llm_usage_id": "agent", "preset_max_size": 80}This confirms the old behavior: the top-level preset had a summarizing condenser, but file-based spawned sub-agents got no condenser by default, and condenser frontmatter was just metadata.
Step 2 — Apply the PR's changes:
Checked out origin/alona/sdk-subagent-condenser at f13075b1adf87a4b4c0519e22092ce21cfdab54d.
Step 3 — Re-run with the fix in place:
Ran uv run python /tmp/qa_subagent_condenser.py.
Relevant output:
{"agent_condenser": "LLMSummarizingCondenser", "agent_llm_usage_id": "agent", "condenser_keep_first": 4, "condenser_llm_usage_id": "condenser", "condenser_max_size": 80, "definition_condenser": null, "label": "absent", "metadata_keys": []}
{"agent_condenser": "NoOpCondenser", "definition_condenser": "NoOpCondenser", "label": "disabled_string", "metadata_keys": []}
{"agent_condenser": "NoOpCondenser", "definition_condenser": "NoOpCondenser", "label": "disabled_boolean", "metadata_keys": []}
{"label": "top_level_default_preset", "preset_condenser": "LLMSummarizingCondenser", "preset_keep_first": 4, "preset_llm_usage_id": "agent", "preset_max_size": 80}This shows the PR delivers the promised default condenser, keeps sizing aligned with the top-level preset, tracks condenser calls under a distinct usage ID, and makes the documented opt-out frontmatter work without leaking into metadata.
Test 2: Live condenser execution on the spawned sub-agent default
Step 1 — Reproduce / establish baseline without the fix:
The baseline run above showed agent_condenser: null for an omitted condenser field, so there was no spawned-sub-agent condenser to invoke by default.
Step 2 — Apply the PR's changes:
Used the PR branch and the environment-provided LLM configuration (LLM_MODEL, LLM_BASE_URL, LLM_API_KEY) to exercise the actual condenser object created by agent_definition_to_factory.
Step 3 — Re-run with the fix in place:
Ran OPENHANDS_SUPPRESS_BANNER=1 uv run python /tmp/qa_condense_real.py.
Output:
{"condenser_type": "LLMSummarizingCondenser", "condenser_usage_id": "condenser", "forgotten_event_count": 51, "input_events": 90, "llm_response_id_present": true, "result_type": "Condensation", "summary_offset": 4, "summary_present": true}This confirms the spawned sub-agent's default condenser does not just exist structurally; it successfully performed a real LLM-backed condensation, produced a summary, and forgot old events.
CI note
I did not run the test suite, linters, formatters, or type checkers. I only checked CI status via GitHub.
The failed Validate PR description job reported:
The first visible line of the PR description must be `HUMAN:`.
Add a short human-written note between `HUMAN:` and the human-tested checkbox.
Keep the `- [ ] A human has tested these changes.` checkbox in the PR description.
Keep the `AGENT:` marker from the PR template.
Keep the `## Why` section from the PR template.
Keep the `## Summary` section from the PR template.
Keep the `## How to Test` section from the PR template.
PR description validation failed with 7 error(s).
Per repository guidance, those human-only PR description fields should be updated by a human, not by an AI agent.
Issues Found
- 🟡 Non-functional CI issue:
Validate PR descriptionis failing because the PR description does not match the required template/HUMAN-field format. No functional defect was found in the PR behavior I exercised.
Final verdict: PASS WITH ISSUES.
This QA review was created by an AI agent (OpenHands) on behalf of the user.
Coverage Report •
|
|||||||||||||||||||||||||||||||||||||||||||||
|
✅ Review complete. This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here. |
all-hands-bot
left a comment
There was a problem hiding this comment.
Code Review
🟢 Good taste — elegant, well-scoped solution
Summary
This PR solves a real problem: sub-agents spawned by the top-level agent had no condenser by default, causing context overflow errors during deep multi-turn runs. The fix extracts a shared default_condenser() function that both the top-level preset and sub-agent factory use, ensuring consistent behavior and sizing across all agent levels.
Design Quality
The solution is clean and pragmatic:
-
Shared constant (
_DEFAULT_MAX_SIZE,_DEFAULT_KEEP_FIRST) inllm_summarizing_condenser.pykeeps sizing in sync — any future change to these values automatically propagates to both the top-level agent and spawned sub-agents. -
Distinct
usage_id="condenser"is the right call. The LLM tracks token usage byusage_id, and without a distinct ID, condenser calls would overwrite agent calls in the stats. The code handles this correctly withllm.model_copy(update={"usage_id": "condenser"}). -
Flexible opt-out: The frontmatter parser handles
none,false,off, etc., with a sensible default (None→ use summarizing condenser). This gives users escape hatches without complicating the happy path. -
_extract_condenserfunction is well-designed — it returnsNonefor absent/default,NoOpCondenser()for explicit disable, and a validatedCondenserBasefor explicit configs. The type coercion (bool→NoOpCondenser,dict→ validated model) is clean. -
Tests are substantive: They verify actual behavior (type checks, value assertions) rather than just mocking calls.
No Issues Found
- No breaking changes to existing APIs
- No unnecessary complexity introduced
- No security concerns
- No tests missing for new behavior
Minor Note
The PR description validation is failing due to template/HUMAN-field format requirements. Per the existing QA review, that's a non-functional issue that needs a human to update the PR description.
[RISK ASSESSMENT]
- [Overall PR]
⚠️ Risk Assessment: 🟢 LOW
This is a low-risk change that adds a beneficial default (context condensation) to sub-agents. Existing behavior is preserved for users who explicitly opt out. The shared constants actually reduce future maintenance risk by preventing drift between top-level and sub-agent settings.
VERDICT:
✅ Worth merging — solid implementation solving a real problem with good design choices.
KEY INSIGHT:
Extracting default_condenser() as a shared factory function is the right abstraction — it centralizes the sizing constants and ensures the top-level agent and spawned sub-agents always stay in sync.
Improve this review? If any feedback above seems incorrect or irrelevant to this repository, you can teach the reviewer to do better:
- Add a
.agents/skills/custom-codereview-guide.mdfile to your branch (or edit it if one already exists) with the/codereviewtrigger and the context the reviewer is missing (e.g., "Security concerns about X do not apply here because Y"). See the customization docs for the required frontmatter format.- Re-request a review - the reviewer reads guidelines from the PR branch, so your changes take effect immediately.
- When your PR is merged, the guideline file goes through normal code review by repository maintainers.
Resolve with AI? Install the iterate skill in your agent and run
/iterateto automatically drive this PR through CI, review, and QA until it's merge-ready.Was this review helpful? React with 👍 or 👎 to give feedback.
This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation
all-hands-bot
left a comment
There was a problem hiding this comment.
✅ QA Report: PASS
Verified via real SDK execution that spawned file-based sub-agents now get a default summarizing condenser, can disable it via frontmatter, and can run a live condensation.
Does this PR achieve its stated goal?
Yes. On origin/main, the same sub-agent factory path produced agent_condenser=None, confirming spawned sub-agents had no condenser. On PR head f13075b1, default and file-loaded sub-agents produced LLMSummarizingCondenser with usage_id=condenser; condenser: none / false produced NoOpCondenser; and a live LLM-backed condenser call over 85 events returned a Condensation with a summary.
| Phase | Result |
|---|---|
| Environment Setup | ✅ make build completed and installed the editable SDK/tools/workspace/server packages. |
| CI Status | gh pr checks showed 35 successful, 0 failing, 2 skipped, and 1 pending qa-changes check (this run). |
| Functional Verification | ✅ Before/after SDK probes and a live condenser call matched the PR goal. |
Functional Verification
Test 1: Default spawned sub-agent condenser and frontmatter controls
Step 1 — Reproduce / establish baseline without the fix:
Ran git checkout --detach origin/main then uv run python /tmp/qa_subagent_condenser.py:
default_frontmatter.agent_condenser=None
default_frontmatter.condenser_usage_id=None
default_frontmatter.agent_usage_id=default
default_frontmatter.metadata_has_condenser=False
disabled_frontmatter.agent_condenser=None
disabled_frontmatter.condenser_usage_id=None
disabled_frontmatter.agent_usage_id=default
disabled_frontmatter.metadata_has_condenser=True
false_frontmatter.agent_condenser=None
false_frontmatter.condenser_usage_id=None
false_frontmatter.agent_usage_id=default
false_frontmatter.metadata_has_condenser=True
This confirms the old behavior: sub-agent factories created agents with no condenser, and condenser: frontmatter was treated as metadata instead of a behavior control.
Step 2 — Apply the PR's changes:
Checked out alona/sdk-subagent-condenser at f13075b1.
Step 3 — Re-run with the fix in place:
Ran uv run python /tmp/qa_subagent_condenser.py:
default_frontmatter.agent_condenser=LLMSummarizingCondenser
default_frontmatter.condenser_usage_id=condenser
default_frontmatter.agent_usage_id=default
default_frontmatter.metadata_has_condenser=False
disabled_frontmatter.agent_condenser=NoOpCondenser
disabled_frontmatter.condenser_usage_id=None
disabled_frontmatter.agent_usage_id=default
disabled_frontmatter.metadata_has_condenser=False
false_frontmatter.agent_condenser=NoOpCondenser
false_frontmatter.condenser_usage_id=None
false_frontmatter.agent_usage_id=default
false_frontmatter.metadata_has_condenser=False
This shows the default sub-agent now gets a summarizing condenser with a distinct condenser usage id, while explicit disable values produce a no-op condenser.
Test 2: File-based sub-agent loading path and live condensation
Step 1 — Reproduce / establish baseline without the fix:
Ran the same construction path on origin/main using the configured LLM settings, without invoking the LLM because no condenser existed:
agent_condenser=None
condense_probe_skipped=no_subagent_condenser_available
This confirms the runtime sub-agent could not compact because there was no condenser to call.
Step 2 — Apply the PR's changes:
Checked out alona/sdk-subagent-condenser at f13075b1.
Step 3 — Re-run with the fix in place:
First exercised the file-based agent path using load_agents_from_dir(...) → agent_definition_to_factory(...):
loaded_agent_count=1
loaded_agent_name=researcher
spawned_agent_condenser=LLMSummarizingCondenser
spawned_condenser_usage_id=condenser
Then ran a live LLM-backed condenser call through the spawned sub-agent's default condenser:
agent_condenser=LLMSummarizingCondenser
condenser_usage_id=condenser
condense_result_type=Condensation
condense_result_event_count=0
condense_summary_present=True
This demonstrates the PR path does more than instantiate the object: the spawned sub-agent's default condenser can actually call the configured LLM and produce a condensation summary.
Test 3: Default preset parity and serialization
Ran the public default-preset and AgentDefinition serialization APIs on PR head:
top_level_default_condenser=LLMSummarizingCondenser
top_level_default_max_size=80
top_level_default_keep_first=4
frontmatter_none_condenser=NoOpCondenser
serialized_condenser={'kind': 'NoOpCondenser'}
This confirms the existing top-level default condenser sizing remains 80 / 4, while a disabled sub-agent condenser serializes as a concrete no-op condenser spec for downstream paths.
Issues Found
None.
This QA review was created by an AI agent (OpenHands) on behalf of the user.
|
@ak684 this pr add an api for file-based agent which i'm not sire it is what we wanted. There it was already another PR for that: https://github.com/OpenHands/software-agent-sdk/pull/2349/files |
|
The default sub-agent condenser (the PR's main goal) is token-correct and unaffected. Both trace to the passthrough at condenser = (
agent_def.condenser # <- passed by reference, usage_id untouched
if agent_def.condenser is not None
else default_condenser(llm.model_copy(update={"usage_id": "condenser"}))
)Both were reproduced through the real LocalConversation → llm_registry.add() → ConversationStats path (no LLM calls; tokens recorded the way Telemetry would).
Impact: inflated/cross-contaminated condenser cost, propagated to the parent via the task:{id} rollup; under concurrent same-type sub-agents it's also a mutable-state race on the shared Metrics/Telemetry.
|
|
Moreover, the docs should be update for file-based agents |
HUMAN:
Closes the gap where spawned sub-agents had no condenser and dead-ended on context overflow. Reviewed the change and the real-LLM before/after. Subagents now auto-compact and keep going instead of eventually error'ing out on large workflows.
AGENT:
Why
Spawned sub-agents (the
task/delegate/workflowtools) never received the summarizing condenser that every top-level agent gets, so a deep sub-agent run dead-ended on context-window overflow instead of auto-compacting. This made sub-agents a special case that silently lacked the context management the mainagent has.
Summary
agent_definition_to_factorynow attaches a default summarizing condenser to sub-agents, sharing sizing with the standard preset via a newdefault_condenserSDK helper (get_default_condenserdelegates to it).usage_id="condenser"so its tokens are tracked, not deduped out of conversation stats (first-write-wins onusage_id).AgentDefinition.condenserfield keeps it overridable and serializes for the remote agent-server path: omit/None→ default;none/false→NoOpCondenser(disable); a mapping → a custom condenser spec.How to Test
Unit + full suite (in this branch's worktree):
Real-LLM end-to-end before/after (identical 7-message input, run against a live model via the standalone SDK):
['agent']['agent', 'condenser']Live AFTER log excerpt:
BEFORE never compacts — the view grows unbounded (the path that eventually overflows
the real context window). AFTER fires the condenser (summarized + forgot 9 events),
the sub-agent continues, and its tokens are tracked under a distinct
condenserusage_id.
Type
Notes
Additive and back-compat: the new field defaults to today's behavior, programmatic agents built without the factory are unaffected, and
AgentDefinition.condenseris serialization-safe for the remote path (CondenserBaseis a discriminated union; round-trip covered by a test).