Overview
Rousseau's cost knobs sit at three levels: what the model spends per turn, how many turns happen per session, and how often a daemon fires. Setting all three lets you catch a runaway prompt loop before it becomes an invoice.
The four levers
agent.max_iterations caps the tool-use loop. Default 32.
agent:
max_iterations: 24
Set lower for narrow-purpose bots (community FAQ), higher for pair programming. Runaway loops (model calls the same tool 60 times) are always a bug or a prompt issue — the cap ensures they never burn through your budget.
The Anthropic provider (internal/llm/anthropic/) writes prompt-cache markers on the last two messages. Anthropic's prompt-cache pricing is roughly 10% of full inference for cache reads. In long sessions with a stable prefix (system prompt + skills + early context), this is the biggest single lever.
No config knob — it's automatic when provider: anthropic.
Compression rewrites older history into a summary once you cross trigger_messages.
agent:
compression:
enabled: true
trigger_messages: 60
keep_recent: 8
Turn on for pay-per-token providers. The one-time compression cost pays off after ~10 more messages.
Bound the output size per turn:
anthropic: { max_tokens: 4096 }
bedrock: { max_tokens: 4096 }
vertex: { max_tokens: 4096 }
Community and triage bots do fine with 2048; code-review bots often need 8192.
Monitoring
Rousseau logs one agent.turn.finished event per turn with token usage (when the provider exposes it). Aggregate with the log platform of your choice.
Loki query:
sum by (project) (
rate({service="rousseau"} |= "agent.turn.finished" | json | unwrap output_tokens [1h])
)
Graph per project, alert on >2× the moving average.
- Anthropic console: usage per API key.
- AWS: CloudWatch Bedrock model invocations.
- GCP: Vertex AI usage in the billing dashboard.
Tag rousseau's requests with a unique metadata field (via provider-specific request options) to distinguish from other apps.
Anti-patterns
- Unbounded max_iterations — a stuck agent can call
readon a 500MB file 30 times. Cap it. - Long system prompts without cache markers — you pay full price for the same tokens every turn if the provider is not Anthropic. Consider moving big context into
agent.skills_dirinstead. - No allowlist on public transports — every message from a stranger costs LLM tokens. Always allowlist.
Related pages
- Reference: Config: Agent
- Reference: Logs
- Providers: Anthropic — prompt-cache markers detail
- Best Practices: Multi-tenant
- Recipes: Airgapped deployment — the ultimate cost control is not being on a paid provider