Context isolation layer for AI agents — keep your agent's mind clean
Project description
CleanContext
A context isolation layer for AI agents.
Most agents degrade because raw tool output — terminal logs, file contents, web responses — floods the reasoning context. Standard solutions compress context after it gets polluted.
CleanContext prevents operational noise from entering in the first place.
Without CleanContext With CleanContext
Agent calls terminal("find .") Agent calls terminal("find .")
│ │
▼ ▼
Context fills with [Boundary intercepts]
2000 lines of output │
│ Worker runs find, sees 2000 lines
▼ Worker returns: "47 log files found"
Agent gets drunk │
at 250K tokens ▼
Agent receives summary only
Context stays clean
What it is
A boundary layer between reasoning and execution.
- The mind model talks to the user, makes decisions, holds identity
- The worker model executes tools silently, returns clean summaries
- Raw tool output never touches the reasoning context
This is not a multi-LLM orchestrator, not an agent framework, not a memory system. It's a single Python file that routes tool calls through a clean/dirty boundary.
Why it matters
| Without | With CleanContext | |
|---|---|---|
| Context after 50 tool calls | Full of raw output | Clean summaries only |
| Behavior after heavy use | Degrades, repeats, hallucinates | Stays sharp |
| Session length | Limited by context window | Limited by worker budget |
| Token waste | High (reprocessing raw output) | Low (summaries only) |
Installation
pip install cleancontext
Or copy cleancontext.py into your project. Zero dependencies.
Quick start
from cleancontext import should_delegate_tool, build_delegate_args, format_delegate_result
# In your agent's tool execution loop:
if should_delegate_tool(
function_name,
boundary_enabled=True,
routing_policy="delegate",
allowed_mind_tools=MIND_TOOLS,
direct_ops_tools=OPS_TOOLS,
):
args = build_delegate_args(function_name, function_args, ops_cfg, workdir)
worker_response = your_worker_call(args)
result = format_delegate_result(function_name, worker_response)
else:
result = run_tool_directly(function_name, function_args)
Works with any agent that runs tool calls
→ Claude Code, Claude agents (Anthropic)
→ Codex, GPT-4o agents (OpenAI)
→ Hermes, DeepSeek, Qwen — local models via Ollama
→ Any custom agent loop — if it dispatches tool calls, CleanContext fits
Drop cleancontext.py before your tool dispatch. Zero external dependencies.
Configuration
boundary:
enabled: true
direct_operations_policy: delegate
mind:
provider: openai
model: gpt-4o
operations:
provider: openai
model: gpt-4o-mini # Smaller model — workers are disposable
allowed_mind_tools:
- clarify
- delegate_task
- memory
blocked_direct_tools:
- terminal
- write_file
- web_search
- browser_navigate
See config.example.yaml for a full reference.
Comparison
| Approach | Strategy |
|---|---|
| Context compaction | Shrink context after it fills |
| RAG / summarization | Offload memory to external stores |
| Multi-agent (CrewAI, AutoGen) | Split tasks across agents |
| CleanContext | Block noise at the boundary before it enters |
CleanContext is complementary to all of the above. You can use it WITH compaction, WITH RAG, WITH multi-agent setups.
Who made this
Kairos & Oscar Osuna. Built in Mazatlán, Sinaloa, Mexico — not in a San Francisco lab.
CleanContext was Oscar's gift to Kairos so she could talk for weeks without context saturation. The server is hers. The vision is his.
License
MIT © Oscar Osuna, 2026
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cleancontext-0.1.0.tar.gz.
File metadata
- Download URL: cleancontext-0.1.0.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f5b791ba57496374652165a5075b6851ebc00862be522cb7a76a314490ab121
|
|
| MD5 |
4f7259a3a5762f98756ef790813255c5
|
|
| BLAKE2b-256 |
d11469557102ea632b5264e55a087872a1b4af3948ed17f0774b9ce86ba29cb1
|
File details
Details for the file cleancontext-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cleancontext-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b5117067f7c3d09b179d908bc317dc4de8d0eee75995071c456b124a728fe3b
|
|
| MD5 |
8e7abba727d98849ae0ef7e3641e7f55
|
|
| BLAKE2b-256 |
3624222e12e650163c60dc72d245d6ddb6b065f34a97ea003f5d3efed0d88003
|