r/Python • u/MikeBenis_B • 5h ago
News We cut agent skill-retrieval tokens by 97.6% with typed .og graphs โ meet Hachi [Pre-release]
We researched a sub-file graph format (ObjectGraph) that cuts agent skill-retrieval tokens by up to 97%, then built Hachi around it [Pre-release, Open-Source]
After researching why personal AI agents bloat context windows and go rogue as their skill libraries grow, we published a paper on ObjectGraph (.og) (arXiv:2604.27820)โa typed, sub-file node graph format that cuts skill-retrieval token usage by up to 97.6% compared to dumping full markdown skill files into context.
We then built Hachi (Apache-2.0) around that format: a personal AI agent where every capability, permission boundary, and self-learned skill is governed in code rather than system prompts.
Why ObjectGraph (.og) reduces token usage
Most agents load entire SKILL.md or prompt libraries linearly. In Hachi, capabilities are structured as .og node graphs with a lightweight routing index:
Sub-file node retrieval: The agent reads a ~30-token routing index first, then fetches only the exact
::denseor::fullnode a task needs (97.6% fewer tokens vs. dump-all once libraries scale past ~30k tokens).Bounded, versioned self-learning: When the agent writes a new capability (
save_skill), it bumps semver, appends a changelog, runs a linter + dense-budget check, and attaches executable::assertionpreconditionsโpreventing context bloat and silent overwrites.
Built-in Runtime Governance (In Code, Not Prompts)
Beyond token savings, Hachi closes two common agent failure modes in the execution path:
Pre-flight cost & token caps: Before every LLM call, the ReAct loop projects worst-case token spend against per-turn, per-session, and daily caps and blocks runaway loops before they fire.
Call-time permission guards: Filesystem, shell, SSRF-checked URLs, and ChromaDB memory writes pass through
PermissionGate(sandbox/guided/unrestricted) at execution time, with untrusted content quarantined before entering long-term memory.
Stack & Surfaces
Interfaces: Textual TUI, FastAPI gateway (REST + SSE), React web UI, Telegram/Slack/Discord/WhatsApp, plus an OpenAI-compatible
/v1/chat/completionsendpoint.Models & Tools: 62 built-in tools (files, shell, browser, vision, voice, Google Workspace, Notion, Slack, MCP) supporting Anthropic, OpenAI-compatible, OpenRouter, Groq, DeepSeek, Gemini, and local Ollama.
Engineering: 4,300+ tests,
import-linterarchitectural layer contracts in CI, and OS keyring credential storage.
Quickstart (Install from Source)
Requires Python 3.11+ and uv (no API key needed to run the test suite or reproduce the benchmark):
git clone [https://github.com/OpenGigantic/hachi](https://github.com/OpenGigantic/hachi) && cd hachi
uv sync
uv run hachi quickstart # configure provider, validate key, set safety tier
uv run hachi # launch TUI (`uv run hachi serve` for web UI)
uv run hachi skill benchmark # reproduce the .og token-savings numbers