When Your Code Writes Its Own API Contract
We built automatic schema inference for TypeScript capabilities using SWC's AST parser. By analyzing args usage patterns and MCP tool schemas, our code now writes its own API contracts.
Open Source Research Project
CAI captures emergent workflows — tool combinations that agents discover through execution, not design. These patterns become reusable capabilities for the entire system.
// Agent discovered this combination
fetch_data → validate_schema → transform_json
// Now available to all agents as:
capabilities.use("data_pipeline")When AI agents solve problems, they often find clever ways to combine tools. But these discoveries vanish when the session ends.
What if we could capture these emergent patterns? What if agents could learn from each other's discoveries?
CAI tracks how agents combine MCPs — both planned and improvised.
Patterns that work get promoted to explicit capabilities.
The orchestrator analyzes intent and builds optimal DAGs. Routes calls intelligently, parallelizes where possible.Relationships emerge from planning.
Agents generate code that combines MCPs in improvised ways. Novel combinations that no one designed upfront.Capabilities emerge from execution.
Execution → DAG. Immediate correction.
Execution → Patterns. Rule optimization.
Execution → Capabilities. Context evolution.
When one agent discovers a useful combination, it becomes available to all.
Agent A combines tools in a new way to solve a task
The pattern is extracted and stored in the hypergraph
Agent B, C, D... can now use this capability
N-ary relationships capture how tools combine into capabilities. Not just pairs — full patterns.
Deno runtime executes generated code safely. PII filtering before storage.
Granular AIL/HIL checkpoints. Approve sensitive operations before execution.
BGE embeddings understand intent. Find tools by description, not memorization.
Deep dives, debugging stories, and lessons learned.
We built automatic schema inference for TypeScript capabilities using SWC's AST parser. By analyzing args usage patterns and MCP tool schemas, our code now writes its own API contracts.
The code worked perfectly. The tests passed. There was just one problem: it never actually worked.
CAI is fully open source. Explore the code, run experiments, or contribute to the research.