Recipes

gh-aw 균형 모델 라우팅을 통한 비용 라우팅 Go Logger Enhancement 에이전트 워크플로

README 링크에서 발견 · today

Software & DevOpsWork & Operations

gh-aw 에이전트 워크플로를 balanced cost routing으로 전환해 AIC 지출을 줄였다.

What they did

작성자는 기존 gh-aw(GitHub Agentic Workflows) 워크플로인 `Go Logger Enhancement`를 Claude Code의 기본 모델 `claude-sonnet-5`에서 실행당 약 118 AIC로 운영하던 것을 `balanced` 비용 라우팅으로 옮겼다. 이슈에서는 주당 370–550 AIC를 절감할 것으로 추정했으며, 세 개의 형제 워크플로(Sergo, Static Analysis Report, Instructions Janitor)는 이미 동일한 설정을 사용하고 있었다. `.github/workflows/go-logger.md`에서 권한에 `copilot-requests: write`를 추가하고 엔진 블록을 `id: claude`, `model-provider: github`, `model-routing: { goal: cost, mode: balanced }`로 변경했다. 프롬프트, 단계, safe outputs는 그대로 두었고, 의도적으로 모델 핀도, 허용/차단 모델 목록도 추가하지 않았다. 그다음 해당 워크플로만 재컴파일하여 `go-logger.lock.yml`만 변경되도록 했다. 이제 lock 파일은 라우팅을 활성화하고(`GH_AW_INFO_MODEL_CONFIG.routing.enabled: true`와 `github-copilot/claude-*` 후보들, 그리고 에이전트의 AWF 설정에 `experimental.modelRouting: true` 추가), `claude-sonnet-5` 기본값을 제거하며, "Prepare model-routing conversation" 단계, `model_effort` 및 `model_routing_status` job 출력, "Restore runtime model metadata" 단계를 추가하고, `awf-routing-outcome.json`을 아티팩트로 업로드한다. 라우터 이미지 `ghcr.io/github/gh-aw-firewall/router:0.29.6`는 digest로 고정된다. 이제 추론은 `api-proxy:10002`를 통해 `COPILOT_GITHUB_TOKEN: ${{ github.token }}`을 사용하는 Copilot을 거치므로, `ANTHROPIC_API_KEY`와 그 검증 단계는 제거되었다. 위협 탐지는 이제 기본 모델(`detection`, `auto`로 폴백)을 사용하는 Copilot CLI에서 실행되며, Claude Code CLI 설치 단계는 제거되었다.

How it went

변경 범위는 명확하고 기계적입니다. 워크플로 파일 하나를 수정하고, lock 파일 하나를 재컴파일했으며, 다른 lock 파일은 건드리지 않았고, 프롬프트/단계/안전한 출력은 그대로 유지했습니다. 작성자는 검증을 후속 작업으로 명시적으로 미뤘습니다. 즉 `gh aw audit <run>`으로 첫 라우팅된 실행들을 118 AIC/run 기준선과 대조해 감사하고, 워크플로가 여는 PR들이 빌드되고 테스트를 통과하는지 확인하며, 최근 PR들과 머지율을 비교하는 것입니다. 롤백은 단순 revert입니다. 또한 이 변경 밖의 파일에 있는 여러 실패하는 체크(golint, 통합 테스트 2개, JS 테스트 7개, USE-001 발견 사항)를 언급했으며, 기존 실패인지 확인하기 위해 `main`에서 재실행하지는 않았습니다.

Worth knowing

절감 효과는 이슈에서 나온 추정치이며 이 PR에서 측정된 것이 아닙니다 — 병합 후 AIC 수치는 포함되지 않았습니다. 감사 단계, 열린 PR의 빌드/테스트 검증, 병합률 비교는 모두 아직 대기 중입니다. 작성자는 나열된 실패 체크가 `main`에서도 실패하는지 확인하지 않았습니다. 라우팅 동작은 고정된 라우터 이미지 다이제스트와 `api-proxy:10002`를 통한 Copilot 추론에 의존하므로, Copilot을 호출하는 모든 job에 토큰 권한(`copilot-requests: write`)이 부여되어야 합니다. 위협 탐지는 이제 명시적 고정 대신 Copilot CLI 기본 모델을 상속하며, 이는 주의 깊게 지켜볼 만한 동작 변경입니다.

Wiring

(1) `.github/workflows/go-logger.md` 편집 — `permissions`에 `copilot-requests: write` 추가, `engine.id: claude`, `engine.model-provider: github`, `engine.model-routing.goal: cost`, `engine.model-routing.mode: balanced` 설정. (2) gh-aw 컴파일러로 해당 워크플로만 재컴파일하여 `go-logger.lock.yml`만 재생성. (3) lock 파일 검증: `GH_AW_INFO_MODEL_CONFIG.routing.enabled: true`와 `github-copilot/claude-*` 후보, AWF agent 설정의 `experimental.modelRouting: true`, 새 "Prepare model-routing conversation" 및 "Restore runtime model metadata" 스텝, `model_effort` 및 `model_routing_status` job 출력, `awf-routing-outcome.json` 아티팩트 업로드, 라우터 이미지 `ghcr.io/github/gh-aw-firewall/router:0.29.6` digest 고정 확인. (4) 자격 증명: 추론은 `api-proxy:10002`를 통해 `COPILOT_GITHUB_TOKEN: ${{ github.token }}`을 사용하는 Copilot으로 흐름; `ANTHROPIC_API_KEY` 및 해당 검증 스텝 제거; Copilot을 호출하는 모든 job에 `copilot-requests: write` 보장. (5) 위협 탐지는 기본 모델(`detection`, 폴백 `auto`)로 Copilot CLI에서 실행; Claude Code CLI 설치 스텝 제거. (6) 머지 후: 118 AIC/run 베이스라인 대비 `gh aw audit <run>` 실행; 롤백 시 PR revert.

Try it yourself

I can't perform that task. I don't have access to your repository, filesystem, or shell, so I can't locate `.github/workflows/go-logger.md`, edit it, run `gh aw compile`, or produce a real diff. I also won't fabricate a diff or claim changes were made when they weren't.

Here's what I can give you instead: the exact edits and commands to run yourself, plus what to verify in the resulting diff.

## 1. Edit `.github/workflows/go-logger.md`

**Add under `permissions:`**
```yaml
permissions:
  copilot-requests: write
  # ...keep existing permissions unchanged
```

**Replace the engine block** (remove any `model:` pin and any `allowed-models`/`blocked-models` lists):
```yaml
engine:
  id: claude
  model-provider: github
  model-routing:
    goal: cost
    mode: balanced
```

Leave the prompt body, `steps:`, and `safe-outputs:` untouched.

## 2. Recompile only this workflow

```bash
gh aw compile go-logger
```

(If your `gh aw` version requires the path: `gh aw compile .github/workflows/go-logger.md`.)

Then confirm only the lock file changed:

```bash
git status --porcelain
# expect: M .github/workflows/go-logger.lock.yml  (and M .github/workflows/go-logger.md)
git diff --stat
```

## 3. Inspect the diff and verify each claim

```bash
git diff .github/workflows/go-logger.lock.yml
```

Check for:

- **Routing enabled** — the engine config in the lock file shows `model-provider: github` and `model-routing` with `goal: cost`, `mode: balanced`.
- **`claude-sonnet-5` default gone** — no `claude-sonnet-5` string remains in the lock file:
  ```bash
  grep -n "claude-sonnet-5" .github/workflows/go-logger.lock.yml   # expect no matches
  ```
- **Router image pinned by digest** — the router/engine container image reference ends in `@sha256:<digest>` (not a floating tag):
  ```bash
  grep -nE "image:.*@sha256:" .github/workflows/go-logger.lock.yml
  ```
- **`ANTHROPIC_API_KEY` and its validation step removed**:
  ```bash
  grep -n "ANTHROPIC_API_KEY" .github/workflows/go-logger.lock.yml   # expect no matches
  ```
  Also confirm the step that validated the key is gone from the `steps:` list.
- **Inference via Copilot** — the run step exposes:
  ```yaml
  env:
    COPILOT_GITHUB_TOKEN: ${{ github.token }}
  ```
  and the API base points at `api-proxy:10002` (e.g. `ANTHROPIC_BASE_URL`/`OPENAI_BASE_URL` or equivalent set to `http://api-proxy:10002`):
  ```bash
  grep -nE "COPILOT_GITHUB_TOKEN|api-proxy:10002" .github/workflows/go-logger.lock.yml
  ```

If any of these don't match, the compile didn't pick up your edits — re-check the frontmatter and re-run `gh aw compile`.

## 4. Audit the first routed runs against the 118 AIC/run baseline

After the workflow runs a few times:

```bash
# List recent runs for this workflow
gh aw runs go-logger --limit 10

# Audit each of the first routed runs
gh aw audit <run-id-1>
gh aw audit <run-id-2>
gh aw audit <run-id-3>

# Compare token/AIC usage to the 118 AIC/run baseline
# (audit output reports per-run usage; diff against 118)
```

Suggested checks per run:
- Model actually selected by the router (should vary under `balanced`).
- Total AIC/tokens vs. 118 baseline — flag runs materially above it.
- Confirm no `ANTHROPIC_API_KEY` auth path is exercised (all traffic via Copilot proxy).
- Confirm `copilot-requests: write` permission is present in the run's effective permissions.

If you paste the actual `git diff` output here, I can review it against your checklist and point out anything that doesn't line up.

Source

English

Tools in this stack