Let a worker hand a too-hard task to a subagent one rung up per escalation trigger, at most two above its item's rung
This commit is contained in:
@@ -20,6 +20,8 @@ MEASURED_AT_LEAST = 5
|
||||
DIMENSIONS = ("project", "subagent type", "rung", "tool")
|
||||
# The tool label of a message that follows no tool call, such as the first message after a prompt.
|
||||
PROMPT = "prompt"
|
||||
# How a worker opens the prompt of a subagent it escalates a task to: CLAUDE.md → "Working with the codebase".
|
||||
ESCALATION = re.compile(r"Escalation trigger ([0-9]+):")
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -52,13 +54,14 @@ class Reports:
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
class ChunkFigures:
|
||||
"""tokens maps each of DIMENSIONS to its labels' tokens; start is the rung a routed chunk started on, None where no item routed it."""
|
||||
"""tokens maps each of DIMENSIONS to its labels' tokens; start is the rung a routed chunk started on, None where no item routed it; escalated counts the worker's escalations by trigger."""
|
||||
tokens: dict[str, collections.Counter[str]]
|
||||
start: Rung | None
|
||||
rounds_past_first: int
|
||||
unfinished: int
|
||||
delegated: collections.Counter[str]
|
||||
reports: dict[str, Reports]
|
||||
escalated: collections.Counter[str]
|
||||
|
||||
|
||||
@dataclasses.dataclass(frozen=True)
|
||||
@@ -68,6 +71,7 @@ class Figures:
|
||||
tokens: dict[str, collections.Counter[str]]
|
||||
routed: dict[Rung, list[ChunkFigures]]
|
||||
reports: dict[str, Reports]
|
||||
escalated: collections.Counter[str]
|
||||
skipped: tuple[str, ...] = ()
|
||||
|
||||
|
||||
@@ -89,7 +93,8 @@ def measured(chunk: Chunk, home: str) -> ChunkFigures:
|
||||
for _, tools, spent in spend(subagent.entries):
|
||||
add(tokens, chunk.project, kind, rung, tools, spent)
|
||||
start = route_from(cycles[0][1]) if cycles else None
|
||||
return ChunkFigures(tokens, start.rung if start and start.item else None, rounds_past_first(chunk.worker, home), sum(len(UNFINISHED_AT.findall(kept)) for kept in chunk.outcomes), delegated, reports)
|
||||
escalated = collections.Counter(found[1] for _, arguments in launches.values() if (found := ESCALATION.match(str(arguments.get("prompt") or ""))))
|
||||
return ChunkFigures(tokens, start.rung if start and start.item else None, rounds_past_first(chunk.worker, home), sum(len(UNFINISHED_AT.findall(kept)) for kept in chunk.outcomes), delegated, reports, escalated)
|
||||
|
||||
|
||||
def agent_calls(worker: list[dict]) -> dict[str, tuple[str, dict]]:
|
||||
@@ -182,12 +187,13 @@ def totals(chunks: list[ChunkFigures], skipped: tuple[str, ...] = ()) -> Figures
|
||||
tokens = {dimension: sum((chunk.tokens.get(dimension, collections.Counter()) for chunk in chunks), collections.Counter()) for dimension in DIMENSIONS}
|
||||
routed: dict[Rung, list[ChunkFigures]] = {}
|
||||
reports: dict[str, Reports] = {}
|
||||
escalated: collections.Counter[str] = sum((chunk.escalated for chunk in chunks), collections.Counter())
|
||||
for chunk in chunks:
|
||||
if chunk.start:
|
||||
routed.setdefault(chunk.start, []).append(chunk)
|
||||
for kind, found in chunk.reports.items():
|
||||
reports[kind] = reports.get(kind, Reports(0, 0, 0)) + found
|
||||
return Figures(len(chunks), tokens, routed, reports, skipped)
|
||||
return Figures(len(chunks), tokens, routed, reports, escalated, skipped)
|
||||
|
||||
|
||||
def calls(figures: Figures) -> list[str]:
|
||||
@@ -222,6 +228,8 @@ def render(figures: Figures, found: list[str], at: str, cycle: int, since: str)
|
||||
]),
|
||||
"## Subagent reports against the searches they ran, in characters",
|
||||
table(("Subagent type", "Subagents", "Reports", "Searches"), [(kind, str(found.subagents), str(found.report), str(found.searches)) for kind, found in sorted(figures.reports.items())]),
|
||||
"## Escalations by trigger",
|
||||
table(("Trigger", "Subagents"), [(trigger, str(times)) for trigger, times in sorted(figures.escalated.items(), key=lambda item: int(item[0]))]),
|
||||
*(["## Chunks skipped, unreadable", "".join(f"- {folder}\n" for folder in figures.skipped).rstrip("\n")] if figures.skipped else []),
|
||||
]
|
||||
return "\n\n".join(sections) + "\n"
|
||||
|
||||
Reference in New Issue
Block a user