Skip to content

feat: daily-subagent-optimizer — Claude workflow that proposes inline sub-agent refactorings#29787

Merged
pelikhan merged 1 commit intomainfrom
copilot/optimize-agent-workflows
May 2, 2026
Merged

feat: daily-subagent-optimizer — Claude workflow that proposes inline sub-agent refactorings#29787
pelikhan merged 1 commit intomainfrom
copilot/optimize-agent-workflows

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 2, 2026

Adds a daily Claude workflow that identifies high-token agentic workflows lacking sub-agent decomposition and produces copy-paste-ready refactoring proposals as GitHub issues.

What it does

  • Selects a target — ranks workflows by 7-day token usage via the agentic-workflows MCP logs tool; skips smoke tests, already-decomposed workflows, and anything proposed in the last 14 days (persisted in cache-memory)
  • Screens candidates cheaplyworkflow-screener (haiku) reads each candidate's frontmatter and counts prompt phases without burning main-model tokens
  • Scores decomposition opportunitiesopportunity-classifier (haiku) evaluates each prompt section on a 10-point matrix: independence, haiku-adequacy, parallelism, size; threshold ≥ 6 = strong candidate
  • Applies LLM-expert heuristics — main Claude agent distinguishes haiku-appropriate tasks (extraction, classification, summarization, format conversion) from tasks that must stay on the full model (synthesis, cross-referencing, final authoring)
  • Produces a concrete issue — includes exact ## agent: \name`` block definitions, before/after prompt diffs, estimated token savings, and implementation steps

Key design choices

  • engine: claude + features: inline-agents: true — the optimizer dog-foods the exact pattern it recommends
  • Two haiku sub-agents (workflow-screener, opportunity-classifier) handle mechanical screening/scoring; main model owns selection logic and issue authoring
  • cache-memory optimization log prevents re-targeting the same workflow within 14 days
  • close-older-issues: true on create-issue — one active proposal at a time

Daily Claude workflow that identifies the highest-token agentic
workflow lacking inline sub-agents, applies LLM-expert scoring
heuristics to locate decomposable tasks, and creates a concrete
copy-paste-ready inline-agent refactoring proposal as a GitHub issue.

Uses two haiku sub-agents (workflow-screener, opportunity-classifier)
to dog-food the inline-agents feature it recommends to others.
Persists optimization history in cache-memory to avoid re-targeting
recently proposed workflows.

Agent-Logs-Url: https://github.com/github/gh-aw/sessions/acc1317a-ea78-440b-93f8-b3e17fa7f37c

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented May 2, 2026

@copilot adds experiment to test with/without subagents solutiom

@pelikhan pelikhan marked this pull request as ready for review May 2, 2026 16:25
Copilot AI review requested due to automatic review settings May 2, 2026 16:25
@pelikhan pelikhan merged commit 80cc63e into main May 2, 2026
19 of 20 checks passed
@pelikhan pelikhan deleted the copilot/optimize-agent-workflows branch May 2, 2026 16:25
Copilot stopped work on behalf of pelikhan due to an error May 2, 2026 16:25
Copilot AI requested a review from pelikhan May 2, 2026 16:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new daily agentic workflow that analyzes recent workflow token usage, identifies a high-cost candidate for inline sub-agent extraction, and opens a GitHub issue with a concrete refactoring proposal.

Changes:

  • Adds daily-subagent-optimizer.md, a Claude-powered workflow that ranks recent runs, screens candidates, scores decomposable prompt sections, and drafts a proposal issue.
  • Defines two inline helper agents (workflow-screener and opportunity-classifier) to cheaply assess workflow suitability before the main agent authors the final recommendation.
  • Adds the compiled daily-subagent-optimizer.lock.yml workflow for execution in GitHub Actions.
Show a summary per file
File Description
.github/workflows/daily-subagent-optimizer.md New source workflow defining selection logic, analysis steps, issue template, cache-memory usage, and inline helper agents.
.github/workflows/daily-subagent-optimizer.lock.yml Generated compiled GitHub Actions workflow corresponding to the new markdown source.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 8


Create one GitHub issue with this structure:

Title: `[subagent-optimizer] Add inline sub-agents to <workflow-name> — YYYY-MM-DD`
Comment on lines +228 to +234

| Metric | Before | After (estimated) |
|---|---|---|
| Avg tokens/run | ~N | ~M (~X% reduction) |
| Main-model context saved | — | ~Y tokens/run |
| Parallelism opportunity | None | [N] sections in parallel |

2. Add each sub-agent block at the bottom of `.github/workflows/<name>.md`, after all workflow content
3. Update the prompt sections listed above to invoke sub-agents by name
4. Compile: `gh aw compile <name>`
5. Test: `gh workflow run <name>.yml`
1. **inline_agents_enabled**: Does the frontmatter contain `inline-agents: true` under `features:`? (yes/no)
2. **has_agent_blocks**: Does the file body contain any `## agent:` section? (yes/no)
3. **engine**: The value of the `engine:` field (e.g., `claude`, `copilot`, `codex`). If `engine:` is an object, report `id:` value.
4. **is_smoke_test**: Is this a smoke-test workflow? (yes if filename starts with `smoke-` or file body is fewer than 40 lines)
Comment on lines +248 to +260
## Phase 7 — Update Optimization Log

Create the directory if needed and append one entry to `/tmp/gh-aw/cache-memory/subagent-optimizer/optimization-log.json`:

```bash
mkdir -p /tmp/gh-aw/cache-memory/subagent-optimizer
```

```json
{"date":"YYYY-MM-DD","workflow_name":"...","total_tokens_7d":N,"avg_tokens_per_run":N,"sub_agents_proposed":N,"estimated_savings_pct":N}
```

Load the existing array from that path if the file is present, append the new entry, keep only the last 30 entries, and save.
Comment on lines +77 to +85
From the ranked list, filter out:
- Workflows optimized in the last 14 days (per the log above)
- Smoke-test workflows (filename starts with `smoke-`)
- This optimizer itself (`daily-subagent-optimizer`)
- Workflows already using inline sub-agents

Use the `workflow-screener` sub-agent to check the top 6 remaining candidates. For each, pass the file path and ask the agent to read the file and report all six fields: `inline_agents_enabled`, `has_agent_blocks`, `engine`, `is_smoke_test`, `prompt_phases`, and `notes`.

Select the **highest-token workflow that passes all filters and has at least 3 distinct phases/sections** in its prompt. This is your optimization target.
Comment on lines +66 to +70
- Count: 100
- Start date: `-7d`

From the results, build a ranked list of the top 15 workflows by **total token usage** over the 7-day window. Include: workflow name, run count, total tokens, avg tokens/run, avg turns/run.

Comment on lines +83 to +87
Use the `workflow-screener` sub-agent to check the top 6 remaining candidates. For each, pass the file path and ask the agent to read the file and report all six fields: `inline_agents_enabled`, `has_agent_blocks`, `engine`, `is_smoke_test`, `prompt_phases`, and `notes`.

Select the **highest-token workflow that passes all filters and has at least 3 distinct phases/sections** in its prompt. This is your optimization target.

If no suitable candidate is found, call `noop` with a brief explanation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants