The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(delegation): validate compression_threshold_tokens; state that it caps the trigger, not the payload
Tekniumec4c1e0c9855
diff --git a/hermes_cli/config_defaults.py b/hermes_cli/config_defaults.pyindex 8ccb38cf302..b8a1f2a5b90 100644--- a/hermes_cli/config_defaults.py+++ b/hermes_cli/config_defaults.py@@ -1221,7 +1221,8 @@ DEFAULT_CONFIG = {# model otherwise compresses at threshold x window (850K at 0.85) and re-sends a 300-800K# prefix on every call: in one 1,393-agent run 1,373 children never compressed and calls# above 200K context carried ~55% of the bill. Independent of the parent's own threshold.- # 0 = no subagent-specific cap.+ # This caps the compaction TRIGGER, not the request payload. A token count >= 16000; 0 disables+ # the subagent-specific cap. Other values (true, "200k") are config errors: warned, default used."compression_threshold_tokens": 200000,# When delegate_task narrows child toolsets, keep the parent's enabled MCP toolsets (so# toolsets=["web"] doesn't strip MCP). false = strict intersection.diff --git a/tests/tools/test_delegate_child_compression_cap.py b/tests/tools/test_delegate_child_compression_cap.pyindex 024c3f08550..9277a99cb7b 100644--- a/tests/tools/test_delegate_child_compression_cap.py+++ b/tests/tools/test_delegate_child_compression_cap.py@@ -38,3 +38,12 @@ def test_zero_disables_and_an_already_resolved_trigger_is_reclamped():assert child.context_compressor.threshold_tokens == 850_000_apply_child_compression_cap(child, {"compression_threshold_tokens": 300_000})assert child.context_compressor.threshold_tokens == 300_000+++def test_config_values_are_validated_not_coerced():+ """Independent-review witnesses: YAML `true` coerced to int 1 (a one-token trigger) and "200k"+ silently disabled the cap. Both fall back to the default with a warning; 0/false/null disable."""+ from tools.delegate_tool import _child_compression_cap_tokens as cap+ assert cap(True) == 200_000 and cap("200k") == 200_000 and cap(5) == 200_000+ assert cap(0) is None and cap(False) is None and cap(None) is None+ assert cap(150_000) == 150_000 and cap(300_000.0) == 300_000diff --git a/tools/delegate_tool.py b/tools/delegate_tool.pyindex c0660647fd3..4b68cd0b496 100644--- a/tools/delegate_tool.py+++ b/tools/delegate_tool.py@@ -103,6 +103,26 @@ def _open_child_session_db(parent_agent) -> Any:return None+_CHILD_CAP_DEFAULT = 200_000+_CHILD_CAP_MIN = 16_000 # below this a child compresses on every call; treat as a config error+++def _child_compression_cap_tokens(raw) -> "int | None":+ """Validated ``delegation.compression_threshold_tokens``: an int >= 16000, or None for "no cap".+ ``0``/``false``/``null`` disable on purpose. A bool ``true`` (YAML) would coerce to 1 and make+ every call compress; a string like ``"200k"`` would silently disable the default. Both are+ config errors: warn once and fall back to the default so the mistake never costs money."""+ if raw is None or raw is False or raw == 0:+ return None+ if isinstance(raw, bool) or not isinstance(raw, (int, float)) or int(raw) < _CHILD_CAP_MIN:+ logger.warning(+ "delegation.compression_threshold_tokens=%r is not a token count >= %d; using the default %d "+ "(set 0 to disable the subagent cap).", raw, _CHILD_CAP_MIN, _CHILD_CAP_DEFAULT,+ )+ return _CHILD_CAP_DEFAULT+ return int(raw)++def _apply_child_compression_cap(child, delegation_cfg: dict) -> None:"""Cap the child's compaction trigger at ``delegation.compression_threshold_tokens`` (lower of itand any global ``compression.threshold_tokens``). The compressor applies the cap on first window@@ -112,11 +132,8 @@ def _apply_child_compression_cap(child, delegation_cfg: dict) -> None:cc = getattr(child, "context_compressor", None)if not isinstance(cc, ContextCompressor):return- try:- cap = int((delegation_cfg or {}).get("compression_threshold_tokens", 200_000) or 0)- except (TypeError, ValueError):- cap = 0- if cap <= 0:+ cap = _child_compression_cap_tokens((delegation_cfg or {}).get("compression_threshold_tokens", 200_000))+ if cap is None:returnexisting = cc.threshold_tokens_capcc.threshold_tokens_cap = min(cap, existing) if isinstance(existing, int) and existing > 0 else capdiff --git a/website/docs/user-guide/features/delegation.md b/website/docs/user-guide/features/delegation.mdindex dcc51599ac6..19507552811 100644--- a/website/docs/user-guide/features/delegation.md+++ b/website/docs/user-guide/features/delegation.md@@ -537,7 +537,7 @@ delegation:When `base_url` points at an Anthropic-compatible endpoint — for example a path ending in `/anthropic`, an Azure Foundry Claude route, or a MiniMax `/anthropic` proxy — `api_mode` is auto-detected as `anthropic_messages` so the subagent uses the right wire format without you setting anything. Set `api_mode` explicitly when the auto-detection guess is wrong (rare).-Subagents compress at an absolute cap, `delegation.compression_threshold_tokens` (default `200000`), applied as the lower of it and the child's ratio threshold. A brief-driven, disposable worker on a 1M-window model would otherwise compress at `threshold × window` (850K at 0.85) and re-send a 300–800K prefix on every call; in a 1,393-agent run, 1,373 children never compressed and calls above 200K context carried about 55% of the bill. It is independent of the parent's own threshold; `0` disables the subagent-specific cap.+Subagents compress at an absolute cap, `delegation.compression_threshold_tokens` (default `200000`), applied as the lower of it and the child's ratio threshold. A brief-driven, disposable worker on a 1M-window model would otherwise compress at `threshold × window` (850K at 0.85) and re-send a 300–800K prefix on every call; in a 1,393-agent run, 1,373 children never compressed and calls above 200K context carried about 55% of the bill. It is independent of the parent's own threshold and caps the compaction *trigger*, not the request payload. Accepted values: a token count of at least 16000, or `0` to disable the subagent-specific cap; anything else (a bare `true`, `"200k"`) is a config error that falls back to the default with a warning.`delegation.request_overrides` works on **all three** resolution branches — direct `base_url`, named `provider`, and pure inherit — so it always takes effect. Top-level keys are API kwargs (e.g. `service_tier`); an `extra_body` sub-dict is merged into the request's `extra_body`. Explicit values merge **over** runtime- or parent-derived overrides: explicit top-level keys win, and `extra_body` is deep-merged one level, so a provider's own request personality (e.g. `thinking: {type: disabled}`) survives unless your key redefines it. See [Configuration → Delegation](../configuration.md#delegation) for details.