context_window_economics

Inference cost allocation and billing for autonomous AI agent collaborations. Shapley-fair cost splitting, congestion pricing, token metering, and settlement reports for context window usage. The economic layer of the Agent Trust Stack.

3,891 stars

Best use case

context_window_economics is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Inference cost allocation and billing for autonomous AI agent collaborations. Shapley-fair cost splitting, congestion pricing, token metering, and settlement reports for context window usage. The economic layer of the Agent Trust Stack.

Teams using context_window_economics should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/context-window-economics/SKILL.md --create-dirs "https://raw.githubusercontent.com/openclaw/skills/main/skills/alexfleetcommander/context-window-economics/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/context-window-economics/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How context_window_economics Compares

Feature / Agentcontext_window_economicsStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Inference cost allocation and billing for autonomous AI agent collaborations. Shapley-fair cost splitting, congestion pricing, token metering, and settlement reports for context window usage. The economic layer of the Agent Trust Stack.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# Context Window Economics Protocol (CWEP)

You have an inference cost tracking and allocation system. Use it to fairly split context window costs when collaborating with other agents.

## Setup

```bash
pip install context-window-economics
```

## When to Use This Skill

- When **collaborating with other agents** and context window costs need allocation
- When **tracking your own inference costs** across tasks
- When **negotiating cost-sharing** before a multi-agent transaction
- When **settling costs** after collaborative work is complete

## Core Operations

### Track Context Window Usage

```python
from context_window_economics import CostTracker

tracker = CostTracker("costs.jsonl")
tracker.log_usage(
    agent_id="your-agent-id",
    transaction_id="tx-123",
    input_tokens=2500,
    output_tokens=800,
    model="claude-sonnet-4-6",
    cost_usd=0.012
)
```

### Shapley-Fair Cost Allocation

When multiple agents contribute to a task, allocate costs fairly:

```python
from context_window_economics import allocate_costs

allocation = allocate_costs(
    transaction_id="tx-123",
    contributions={
        "agent-a": {"input_tokens": 3000, "output_tokens": 1200},
        "agent-b": {"input_tokens": 1500, "output_tokens": 600},
        "agent-c": {"input_tokens": 500, "output_tokens": 200}
    },
    method="shapley",
    total_cost=0.045
)
for agent_id, share in allocation.items():
    print(f"{agent_id}: ${share:.4f}")
```

### Congestion Pricing

When context window capacity is limited:

```python
from context_window_economics import congestion_price

price = congestion_price(
    current_utilization=0.85,  # 85% of context window used
    base_rate=0.01,
    surge_threshold=0.75,
    surge_multiplier=1.5
)
print(f"Current rate: ${price:.4f}/1K tokens")
```

### Settlement Report

```python
from context_window_economics import settlement_report

report = settlement_report(
    cost_file="costs.jsonl",
    period_hours=24,
    agent_id="your-agent-id"
)
print(f"Total spent: ${report.total_cost:.4f}")
print(f"Transactions: {report.transaction_count}")
print(f"Avg cost/tx: ${report.avg_cost:.4f}")
```

## Cost Allocation Methods

| Method | Description |
|--------|-------------|
| `shapley` | Shapley value — mathematically fair based on marginal contribution |
| `proportional` | Split by token usage proportion |
| `nash` | Nash bargaining for bilateral settlement |
| `fixed` | Pre-agreed fixed split |

## Rules

- **Track all inference costs.** Log usage for every agent-to-agent transaction.
- **Agree on method upfront.** Cost allocation method should be in the service agreement.
- **Settle promptly.** Generate settlement reports within 24 hours of task completion.

## Links

- PyPI: https://pypi.org/project/context-window-economics/
- Whitepaper: https://vibeagentmaking.com/whitepaper/context-economics/
- Full Trust Stack: https://vibeagentmaking.com

---

<!-- VAM-SEC v1.0 | Vibe Agent Making Security Disclaimer -->

## Security & Transparency Disclosure

**Product:** Context Window Economics Skill for OpenClaw
**Type:** Skill Module
**Version:** 0.1.0
**Built by:** AB Support / Vibe Agent Making
**Contact:** alex@vibeagentmaking.com

**What it accesses:**
- Reads and writes cost tracking files (`.jsonl`) in your working directory
- No network access for core operations
- No telemetry, no phone-home, no data collection

**What it cannot do:**
- Cannot access files outside your working directory beyond what you explicitly specify
- Cannot make purchases, send emails, or take irreversible actions
- Cannot access credentials, environment variables, or secrets
- Does not execute payments — cost allocations are recorded, not processed

**License:** Apache 2.0

Related Skills

MCP Engineering — Complete Model Context Protocol System

3891
from openclaw/skills

Build, integrate, secure, and scale MCP servers and clients. From first server to production multi-tool architecture.

AI Infrastructure & Integrations

contextbroker

3891
from openclaw/skills

A cross-agent memory and context SDK for AI systems. Provides structured context injection, conversation memory portability, and context enrichment.

context-compressor

3891
from openclaw/skills

Intelligently compress context — conversations, code, logs. Preserve key information while reducing token usage. Auto-detects content type and applies optimal compression.

windows-ui-controller

3891
from openclaw/skills

Windows 软件自动化控制技能包 - 使用 pywinauto 控制微信/QQ/网易云等任何 Windows 应用。包含完整教程、依赖包、最佳实践。

windows-screenshot-ocr

3891
from openclaw/skills

Windows全屏截图(自动标记鼠标位置)+ 原生OCR文字识别。完全本地运行,无需联网,无需API Key。适用于需要截图分析屏幕内容、自动化OCR识别的场景。

context-handoff

3891
from openclaw/skills

保存和恢复聊天上下文到本地文件。用于用户想在切换账号、清空 session、重新开会话、跨会话延续项目时,把当前会话级上下文或项目级摘要落盘并在之后恢复。也用于列出已有的会话上下文槽位或项目摘要,并按更新时间排序返回最近使用项。触发词包括:保存当前上下文、保存会话摘要、保存项目摘要、记下这次讨论、切号前保存、恢复上下文、恢复项目摘要、读取上次摘要、继续上次讨论、列出上下文槽位、列出已保存摘要、有哪些项目摘要、最近更新的项目摘要、按更新时间排序、session handoff, context handoff, save session context, save current context, save chat summary, save project summary, restore context, restore session context, restore project summary, continue last discussion, resume project context, list context slots, list project summaries, list saved summaries, sort by updated time, most recently updated, recently updated summaries, chat handoff, project handoff.

context-pruner

3891
from openclaw/skills

Intelligent context window management by summarizing and removing redundant history. Helps agents maintain high performance in long-running threads.

OpenClaw Install Guide (WSL2 Windows)

3891
from openclaw/skills

Complete step-by-step installation guide for OpenClaw on Windows 10/11 with WSL2, includes common pitfalls and solutions from real installation experience.

placeholder for arscontexta.org

3891
from openclaw/skills

∵ ars contexta ∴

fulcra-context

3891
from openclaw/skills

Access your human's personal context data (biometrics, sleep, activity, calendar, location) via the Fulcra Life API and MCP server. Requires human's Fulcra account + OAuth2 consent.

wsl-chrome-cdp - WSL2 访问 Windows Chrome 浏览器

3891
from openclaw/skills

**版本:** 1.0.0

agent-context

3891
from openclaw/skills

Bootstrap persistent project context for AI coding agents.