cost_bounded_agent_looping
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-10-09
- Stars
- ★ 2
- Forks
- 1
03 SKILL.md 正文
Cost-Bounded Agent Looping
Control costs in autonomous agent loops by enforcing ceilings on iterations, spending, and time.
Quick Start
const ct = require('~/.seosona/1_CORE/scripts/cost_tracker');
// Create tracker with preset
const tracker = ct.createTracker({ taskType: 'standard' });
// In your agent loop:
while (ct.shouldContinue(tracker)) {
const result = doWork();
const iterResult = ct.recordIteration(tracker, {
input: result.inputTokens,
output: result.outputTokens
}, result.qualityScore);
if (iterResult.stopped) {
console.log(`Loop stopped: ${iterResult.reason}`);
break;
}
if (iterResult.warnings.length) {
console.warn(iterResult.warnings.join('; '));
}
}
// Save session and get report
const report = ct.saveSession(tracker);
console.log(`Total: $${report.totalCost} over ${report.iterations} iterations`);
CLI Commands
seosona cost estimate "Refactor the authentication module"
seosona cost report
seosona cost models
seosona cost ceilings
Loop Design Rules
Rule 1: Always Set max_iterations
Never allow unbounded loops. Even "unlimited" preset caps at 100 iterations.
Rule 2: Track Cumulative Cost
Not just per-iteration — total cumulative cost matters. The tracker enforces a costCeiling in USD.
Rule 3: Implement Exponential Backoff
On retries, increase wait time. Don't hammer the API with rapid retry loops.
Rule 4: Log Every Iteration
The tracker records every iteration's tokens, cost, and timestamp for post-mortem analysis. Sessions are saved to ~/.seosona/3_MEMORY/logs/cost_tracker_sessions.jsonl.
Rule 5: Exit Early on Diminishing Returns
If qualityScore plateaus across 3 consecutive iterations (delta < threshold), the loop stops automatically.
Ceiling Presets
| Type | Max Iters | Ceiling | Timeout | Use Case |
|---|---|---|---|---|
quick |
3 | $0.10 | 60s | Simple fixes, formatting |
standard |
10 | $1.00 | 5min | Normal development |
deep |
25 | $5.00 | 10min | Complex refactoring |
research |
50 | $10.00 | 30min | UAP triage, analysis |
unlimited |
100 | $50.00 | 60min | Full audit, overnight |
Decision Tree: Choosing a Ceiling
Is this a one-shot task?
├── Yes → 'quick' (3 iters, $0.10)
└── No → Does it involve multiple files?
├── No → 'standard' (10 iters, $1.00)
└── Yes → Is it exploratory/research?
├── No → 'deep' (25 iters, $5.00)
└── Yes → 'research' (50 iters, $10.00)
Model Pricing
The tracker embeds current pricing for 15+ models:
- Anthropic: Claude Sonnet 4, Opus 4, Haiku
- Google: Gemini 2.5 Pro/Flash, 2.0 Flash
- OpenAI: GPT-4o, 4.1, o3, o4-mini
Integration Points
- Module:
~/.seosona/1_CORE/scripts/cost_tracker.js - CLI:
seosona cost estimate|report|models|ceilings - Session logs:
~/.seosona/3_MEMORY/logs/cost_tracker_sessions.jsonl - SOP:
~/.seosona/2_KNOWLEDGE/sops/agent_loop_design_sop.md
04 同仓库更多 Skills
web_crawler_katana
High-speed web crawling using Katana patterns for deep site mapping, URL discovery, and content extraction.
server_log_analyzer
Analyzes Nginx/Apache server logs to identify Googlebot crawl patterns, errors, and performance bottlenecks.
schema_markup_generator
Auto-generates JSON-LD structured data for any page type (Article, Product, FAQ, LocalBusiness, etc.).
internal_linking_optimizer
Analyzes and optimizes the internal link graph of a website for SEO authority distribution.
google_trends_analyzer
Detects trending topics and seasonal patterns using Google Trends data for content planning and keyword strategy.
brand_context_analyzer
Tracks brand mentions, sentiment, and online reputation across web sources.