Skip to content
Source
Sign inSign up

agent-context-budget.yml

52 lines2.2 KB

1name: Agent Context Budget
2​
3# Fails when a PR raises a value in agentContextBudget.json above main's. AgentContextBudget.test.ts
4# keeps that file equal to the measured context, so the context cannot grow by editing the file.
5# To accept growth on purpose, a maintainer adds the agent-context-increase label.
6on:
7 pull_request:
8 types: [opened, synchronize, reopened, labeled, unlabeled]
9​
10permissions:
11 contents: read
12​
13# No concurrency group: label events arrive in bursts, and a cancelled run reports as a failed check.
14jobs:
15 budget:
16 name: Agent context budget
17 runs-on: ubuntu-24.04
18 timeout-minutes: 5
19 env:
20 BUDGET: apps/server/src/provider/agentContextBudget.json
21 ALLOW_INCREASE: ${{ contains(github.event.pull_request.labels.*.name, 'agent-context-increase') }}
22 steps:
23 - name: Checkout
24 uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0
25 with:
26 sparse-checkout: apps/server/src/provider/agentContextBudget.json
27 sparse-checkout-cone-mode: false
28​
29 - name: Compare with main
30 run: |
31 git fetch --quiet --depth=1 origin main
32 if ! git cat-file -e "FETCH_HEAD:$BUDGET" 2>/dev/null; then
33 echo "main has no agent context budget yet."
34 exit 0
35 fi
36 git show "FETCH_HEAD:$BUDGET" > "$RUNNER_TEMP/main.json"
37 grown=$(jq -r --slurpfile main "$RUNNER_TEMP/main.json" '
38 to_entries[]
39 | select($main[0][.key] != null and .value > $main[0][.key])
40 | "\(.key): \($main[0][.key]) -> \(.value) (+\(.value - $main[0][.key]))"
41 ' "$BUDGET")
42 if [ -z "$grown" ]; then
43 echo "Agent context is not larger than main."
44 exit 0
45 fi
46 printf 'Agent context grew compared to main:\n%s\n' "$grown"
47 if [ "$ALLOW_INCREASE" = "true" ]; then
48 echo "Accepted by the agent-context-increase label."
49 exit 0
50 fi
51 echo "::error file=$BUDGET::Agent context grew compared to main. Cut the added text and rerun the evals that cover it (evals/README.md), or ask a maintainer to add the agent-context-increase label."
52 exit 1