Skip to content

The agent that grows with you

fix: async delegation completions name the inherited child model

Teknium71fa6e176aea
diff --git a/tests/tools/test_delegate_completion_model.py b/tests/tools/test_delegate_completion_model.py
new file mode 100644
index 00000000000..f9caa9d81e5
--- /dev/null
+++ b/tests/tools/test_delegate_completion_model.py
@@ -0,0 +1,24 @@
+"""The async completion header names the model the children actually run on."""
+
+from dataclasses import fields
+from types import SimpleNamespace
+
+from tools import async_delegation
+from tools.delegate_tool_dispatch import _Batch, _dispatch_unit
+
+
+def _unit(configured_model):
+ batch = _Batch(**{field.name: None for field in fields(_Batch)})
+ task = {"goal": "probe"}
+ batch.task_list, batch.live_writers, batch.top_role = [task], [], "leaf"
+ batch.children = [(0, task, SimpleNamespace(model="inherited/model"))]
+ batch.creds = {"model": configured_model}
+ return batch
+
+
+def test_completion_model_falls_back_to_inherited_child_model(monkeypatch):
+ seen = []
+ monkeypatch.setattr(async_delegation, "dispatch_async_delegation_batch", lambda **kw: seen.append(kw["model"]))
+ _dispatch_unit(_unit(None), None, None, {}) # delegation.model blank: children inherit the parent's model
+ _dispatch_unit(_unit("configured/model"), None, None, {})
+ assert seen == ["inherited/model", "configured/model"]
diff --git a/tools/delegate_tool_dispatch.py b/tools/delegate_tool_dispatch.py
index 5fe497d134b..74e81ace981 100644
--- a/tools/delegate_tool_dispatch.py
+++ b/tools/delegate_tool_dispatch.py
@@ -398,7 +398,9 @@ def _dispatch_unit(unit: _Batch, unit_id: Optional[str], slot_key: Optional[str]
# Call-wide goals: completion formatting indexes them by task_index.
goals=[t["goal"] for t in unit.task_list], context=unit.context,
toolsets=None, # metadata for the completion block only; subagents inherit the parent's toolsets
- role=unit.top_role, model=unit.creds["model"],
+ # creds["model"] is None when delegation.model is blank (children inherit): report what the child runs on.
+ role=unit.top_role, model=unit.creds["model"] or next(
+ (getattr(c, "model", None) for c in child_agents if getattr(c, "model", None)), None),
runner=lambda: _execute_and_aggregate(unit, honor_parent_interrupt=False),
interrupt_fn=_interrupt, delegation_id=unit_id, slot_key=slot_key,
task_indexes=[i for (i, _, _) in unit.children] if len(unit.children) < len(unit.task_list) else None,