Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore: files changed scripts/check-prompt-budget.sh

Steven Enamakele1d939d1a9a6
diff --git a/scripts/check-prompt-budget.sh b/scripts/check-prompt-budget.sh
index ab31ebae56..1e2d762704 100755
--- a/scripts/check-prompt-budget.sh
+++ b/scripts/check-prompt-budget.sh
@@ -16,6 +16,16 @@
#
# --write Rewrite the limits file's numbers to the measured values. For
# landing a deliberate reduction; never run it to make CI green.
+#
+# Two entry shapes, both ratchets:
+# <agent>:<max prompt bytes>:<max tool-schema bytes>
+# tool:<name>:<max bytes> - one tool's own schema
+#
+# The per-tool ratchet exists because the per-agent number hides its own
+# causes: `workflow_builder` sat at 33,948 B with a single tool accounting for
+# 7,415 of it. A tool over TOOL_ATTENTION_BYTES must be recorded in the limits
+# file, so growth in one schema cannot hide inside an agent total that is still
+# under its own limit.
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
@@ -39,6 +49,20 @@ done
# ratchet update for any real reduction, which starts in the thousands.
SLACK=512
+# The size at which one tool's schema is worth an explicit decision.
+#
+# 1,600 bytes is ~400 tokens, the point at which a schema costs more than most
+# prose sections of the system prompt. Crossing it is not a bug; crossing it
+# without anyone noticing is. A tool above this line must appear in the limits
+# file, which is where the reason goes.
+#
+# Deliberately a ratchet rather than a hard cap. A cap failing above ~800
+# tokens would reject `memory` (3,788 B) and `cron` (3,228 B), which are that
+# size precisely because they replaced families of eleven and six - the
+# consolidation this budget exists to encourage. What matters is that a number
+# moves and someone looks, not that every tool fits one shape.
+TOOL_ATTENTION_BYTES=1600
+
# The measurement must not depend on who is logged in.
#
# `prompt-size` renders through the real session path, which injects the
@@ -49,7 +73,7 @@ SLACK=512
# means `integrations_agent` has no connected toolkit and is skipped, which is
# correct — its size is a property of the user's account, not of this repo.
WORKSPACE="$(mktemp -d "${TMPDIR:-/tmp}/openhuman-prompt-budget.XXXXXX")"
-cleanup() { rm -rf "$WORKSPACE"; }
+cleanup() { rm -rf "$WORKSPACE" "${TOOL_LOOKUP:-}" "${TOOL_OVERSIZE:-}"; }
trap cleanup EXIT
BIN="target/debug/openhuman-core"
@@ -65,6 +89,38 @@ if ! measured="$(RUST_LOG=error "$BIN" agent prompt-size --workspace "$WORKSPACE
exit 1
fi
+# Helper python written to temp files rather than inline heredocs: a heredoc
+# inside the `while read` loop would consume the loop's own stdin.
+TOOL_LOOKUP="$(mktemp)"
+TOOL_OVERSIZE="$(mktemp)"
+cat > "$TOOL_LOOKUP" <<'PYLOOKUP'
+import json, os, sys
+d = json.loads(sys.argv[1])
+tool = os.environ["TOOL"]
+for agent in d["agents"]:
+ for t in agent["tools"]:
+ if t["name"] == tool:
+ print(t["bytes"])
+ sys.exit(0)
+sys.exit(f"tool '{tool}' is in prompt-budget.limits but no agent advertises it - "
+ f"was it renamed, removed or deferred? Drop the line if so.")
+PYLOOKUP
+cat > "$TOOL_OVERSIZE" <<'PYOVER'
+import json, os, sys
+d = json.loads(sys.argv[1])
+listed = set(filter(None, os.environ["LISTED"].split()))
+threshold = int(os.environ["THRESHOLD"])
+seen = {}
+for agent in d["agents"]:
+ for t in agent["tools"]:
+ seen[t["name"]] = t["bytes"]
+for name, size in sorted(
+ ((n, b) for n, b in seen.items() if b > threshold and n not in listed),
+ key=lambda kv: -kv[1],
+):
+ print(f"{name} {size}")
+PYOVER
+
status=0
declare -a NEW_LINES=()
@@ -76,12 +132,38 @@ while IFS= read -r raw; do
continue
fi
- IFS=: read -r agent max_prompt max_tools extra <<< "$line"
- if [[ -n "${extra:-}" || -z "$agent" || -z "$max_prompt" || -z "$max_tools" ]]; then
+ IFS=: read -r first second third extra <<< "$line"
+ if [[ -n "${extra:-}" || -z "$first" || -z "$second" || -z "$third" ]]; then
echo "::error::invalid prompt-budget limit entry: '$line'" >&2
exit 1
fi
+ if [[ "$first" == "tool" ]]; then
+ tool_name="$second"
+ max_tool="$third"
+ if ! measured_bytes="$(TOOL="$tool_name" python3 "$TOOL_LOOKUP" "$measured")"; then
+ status=1
+ NEW_LINES+=("$raw")
+ continue
+ fi
+ if (( VERBOSE )); then echo "tool $tool_name $measured_bytes/$max_tool"; fi
+ if (( measured_bytes > max_tool )); then
+ echo "::error::tool schema REGRESSED: '$tool_name' is $measured_bytes B, limit is" \
+ "$max_tool. Every agent holding it pays this on every turn." >&2
+ status=1
+ elif (( max_tool - measured_bytes > SLACK )); then
+ echo "::error::tool schema IMPROVED but was not ratcheted: '$tool_name' is" \
+ "$measured_bytes B against a limit of $max_tool. Lower it in this PR." >&2
+ status=1
+ fi
+ NEW_LINES+=("tool:$tool_name:$measured_bytes")
+ continue
+ fi
+
+ agent="$first"
+ max_prompt="$second"
+ max_tools="$third"
+
if ! read -r prompt_bytes tool_bytes tool_count max_tool_bytes max_tool_name <<< "$(
AGENT="$agent" python3 - "$measured" <<'PY'
import json, os, sys
@@ -130,6 +212,25 @@ PY
NEW_LINES+=("$agent:$prompt_bytes:$tool_bytes")
done < "$LIMITS"
+# Any tool over the attention threshold must be recorded above. Checked after
+# the loop so the message names every offender at once rather than failing on
+# the first.
+listed_tools="$(grep -oE '^tool:[^:]+' "$LIMITS" | cut -d: -f2 | sort -u || true)"
+unlisted="$(LISTED="$listed_tools" THRESHOLD="$TOOL_ATTENTION_BYTES" \
+ python3 "$TOOL_OVERSIZE" "$measured")"
+while read -r name size; do
+ [[ -z "$name" ]] && continue
+ if (( WRITE )); then
+ NEW_LINES+=("tool:$name:$size")
+ echo "[prompt-budget] recording tool:$name:$size" >&2
+ else
+ echo "::error::'$name' is $size B, over the $TOOL_ATTENTION_BYTES B attention" \
+ "threshold, and is not in $LIMITS. Add 'tool:$name:$size' with a comment" \
+ "saying why it needs that much, or trim it." >&2
+ status=1
+ fi
+done <<< "$unlisted"
+
if (( WRITE )); then
printf '%s\n' "${NEW_LINES[@]}" > "$LIMITS.tmp"
mv "$LIMITS.tmp" "$LIMITS"