Skip to content

[agentic-token-optimizer] Optimization: Typist - Go Type Analysis (35–50 AIC/run savings) #43823

Description

@github-actions

Target Workflow: Typist — Go Type Analysis (typist.md)

Why selected: Highest AIC among un-optimized workflows this week (261.8 AIC/run). Runs daily on weekdays; 22 runs audited over 30-day window (20 success, 2 infrastructure failures on Jun 25). Never previously optimized.


Analysis Period & Runs Audited

  • Period: 2026-06-06 → 2026-07-06 (30 days)
  • Runs audited: 22 total (20 success, 2 failure — both Jun 25 infrastructure failures: CLI proxy DNS resolution failure EAI_AGAIN awmg-cli-proxy)
  • Primary run analyzed in depth: §28791658618 (Jul 6, success, 13 min, 261.8 AIC)

Cost Profile

Metric Value
Total AIC (7-day) 261.8
Avg AIC / run 261.8
Action minutes / run 13 min
Cache write (first turn) 39,335 tokens
Total cache reads (session) 1,271,776 tokens
Raw I/O tokens 6,062
Agent turns (Jul 6 run) 27
Bash tool calls 23
Engine Claude Opus 4
Inline sub-agents defined 1 (duplicate-type-finder)
GitHub API calls / run 11

Cache efficiency is high (1,271,776 cache reads vs 6,062 fresh I/O) — prompt caching is working well. The main optimization surface is the prompt verbosity, unused bash allowlist entries, Serena over-exploration, and a firewall-rejected multi-op bash command that causes a retry loop.


Ranked Recommendations

1. Fix multi-op bash rejection that adds 3–5 extra turns (~15–20 AIC/run)

Evidence: In the Jul 6 run, turn 5 shows the agent constructed a chained bash command (cd && mkdir && grep ... | grep | wc | echo && grep ...) that was rejected by the sandbox firewall as a "multi-op" command. This triggered a retry loop with 3 additional recovery turns (turns 6–8) to re-execute the same grep via a sequence of simpler individual calls.

Action: Add an explicit instruction to Phase 0 of the prompt that reinforces bash allowlist constraints. The duplicate-type-finder sub-agent prompt already uses single-op patterns correctly — surface the same constraint in the main prompt:

> **Bash constraint:** Run one logical operation per Bash call. Chain with `&&` only when both parts are on the configured allowlist.

Estimated savings: 3–5 turns eliminated → ~15–20 AIC/run


2. Remove unused bash allowlist entries — 6 of 8 entries never triggered (~5 AIC/run)

Evidence (Jul 6 run, 23 bash calls):

Configured allowlist entry Used?
find pkg -name "*.go" ! -name "*_test.go" -type f ✅ 1 use
find pkg -type f -name "*.go" ! -name "*_test.go" ❌ 0 uses (duplicate of above)
find pkg/ -maxdepth 1 -ls ❌ 0 uses
wc -l pkg/**/*.go ✅ ~5 uses (wc used, though not always with glob)
grep -r "type " pkg --include="*.go" ❌ 0 uses (agent uses -rn "^type [A-Za-z]" instead)
grep -r "interface{}" pkg --include="*.go" ❌ 0 uses (agent uses `-rnP "\b(interface{}
grep -r "\\bany\\b" pkg --include="*.go" ❌ 0 uses (merged into above)
cat pkg/**/*.go ❌ 0 uses (never cat entire pkg tree)

Recommended allowlist (replace current):

tools:
  bash:
  - find pkg -name "*.go" ! -name "*_test.go" -type f
  - grep -rn
  - grep -rhnP
  - grep -rhoP
  - grep -rcP
  - wc -l
  - awk
  - python3
  - serena
  - sed -n
  - head
  - mkdir -p

Tighter allowlist reduces sandbox evaluation overhead and helps the firewall reject over-broad commands faster.

Estimated savings: 2–5 AIC/run (reduced overhead and fewer sandbox decision round-trips)


3. Remove unnecessary serena --help probe at session start (~3–4 AIC/run)

Evidence: Turn 2 (Jul 6 run) runs serena --help 2>&1 | head -40 — purely exploratory, adds one full turn with ~2,639 fresh input tokens before the agent proceeds to activate_project. This call recurs across multiple runs; the same model is used every run with the same Serena version.

Action: Remove the "check serena CLI help" turn by making the Phase 0 instruction explicit enough that the agent activates without probing:

Replace:

1. **Activate Serena Project**:
   Use Serena's `activate_project` tool with the workspace path to enable semantic analysis.

With:

1. **Activate Serena** (skip any help-check):
   ```bash
   serena activate_project --project ${{ github.workspace }} 2>&1 | tail -20

**Estimated savings:** 1 turn × ~2,639 tokens → ~3–4 AIC/run

---

#### 4. Trim Phase 4 discussion template — remove inline code examples (~10–15% prompt token reduction)

**Evidence:** Phase 4 is 257 lines / ~1,567 estimated tokens. It contains 6 complete `before/after` Go code examples that the model reads on every run — even though the *actual* findings each run are specific to the current codebase state. These examples occupy ~40% of Phase 4.

**Action:** Replace the inline code examples with terse references. Keep the structural headers but cut the Go code blocks:

Before (285 chars of one example):
```go
// BEFORE (untyped)
func processData(input interface{}) error {
    data := input.(map[string]interface{})
    return nil
}
// AFTER (strongly typed)
type InputData struct { Fields map[string]string }
func processData(input InputData) error { return nil }

After:

- Replace `interface{}` params with domain-specific struct types (eliminates type assertions)
- Replace `any` map values with typed value structs

Apply the same treatment to all 5 remaining example blocks. Estimated reduction: ~500 tokens from Phase 4.

Estimated savings: ~8–12 AIC/run (from reduced initial cache creation size)


5. Collapse duplicate Phase 0 conditional into a single block (~minor)

Evidence: The prompt has two {{#if experiments.tone_style}} blocks that both emit ### Phase 0: Setup and Activation as a header, but the body steps (Activate Serena, Discover Go Files) are outside both conditionals. This renders the header twice and adds unnecessary template expansion overhead.

Action: Collapse to one block:

### Phase 0: Setup and Activation
{{#if experiments.tone_style == 'conversational'}}
First things first—let's activate Serena and discover all the Go files we need to analyze.
{{/if}}

Estimated savings: <1 AIC/run (minimal, but reduces template token count slightly)


Supporting Run Evidence

Jul 6 run turn sequence (bash calls):

# Time Command (truncated) Notes
1 12:33:13 find pkg -name "*.go" ... | wc -l && find ... File discovery
2 12:33:14 serena --help 2>&1 | head -40 Wasted exploratory turn
3 12:33:20 serena activate_project ... Activation
4 12:33:22 grep -rn "^type .* struct" pkg ... Type scan
5 12:33:34 cd ... && mkdir && grep ... | grep | wc ... REJECTED (multi-op)
6 12:33:38 mkdir -p ... && grep -rn ... Recovery retry 1
7 12:33:48 grep -v "_test.go" ... Recovery retry 2
8 12:33:52 grep -v "_test.go" ... Recovery retry 3
9–11 12:33:59–12:34:16 awk, python3 -c, python3 analyze_types.py Type analysis
12–14 12:34:31–12:34:49 grep -oP, grep -v, grep -v Duplicate filtering
15–17 12:35:05–12:35:17 sed -n, sed -n, head -8 ... Type inspection
18–23 12:35:26–12:36:09 grep -rn, grep -rhn, grep -rho, grep -rc × 2, grep -rnP Untyped usage scans

Cache token breakdown (Jul 6 run):

  • Initial context cache write: 39,335 tokens (prompt + tool config loaded)
  • Cumulative cache writes by end: ~107,180 tokens
  • Total cache reads: 1,271,776 tokens
  • Raw I/O: 6,062 tokens (very efficient once cache populated)

Failures (Jun 25, both runs): Both failures are infrastructure-only (awf-cli-proxy DNS resolution failure — EAI_AGAIN awmg-cli-proxy). Agent never started. No agent-side action needed.

References:


Caveats

  • Only 1 run is available in the 7-day window (Jul 6); the 22-run analysis uses GitHub API history. Token breakdowns are from the single available JSONL log.
  • The duplicate-type-finder sub-agent is already defined — no new sub-agents recommended.
  • Bash allowlist changes must be validated against the firewall before merging (some new patterns like grep -rcP must match the actual commands run).
  • Infrastructure failures (2 of 22) are not agent-caused and have no optimization path.
  • The experiment tone_style A/B test is ongoing — prompt changes to Phase 4 should be applied to both formal and conversational branches.

Total estimated AIC savings (all recommendations combined): 35–50 AIC/run (~13–19% of current 261.8 avg)

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • awmgmcpg

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "awmgmcpg"

See Network Configuration for more information.

Generated by Agentic Workflow AIC Usage Optimizer · 249.7 AIC · ⊞ 7K ·

  • expires on Jul 13, 2026, 8:20 AM UTC-08:00

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions