INTENT COMPILATION & MCP

Como Dominar o Agent Intent Compiler: Compilando Linguagem Natural em DAGs Tipados e Eliminando Injeção de Prompt

Why feeding raw user strings into agent tool loops leads to prompt injection vulnerabilities and token blowouts, and how to compile prompts into deterministic, typed DAG execution stages in sub-millisecond local Python.

The Fragility of Stochastic Tool Calling

Modern agent frameworks delegate tool selection and parameter generation entirely to the LLM. In production, this introduces severe vulnerabilities:

The Solution: agent-intent-compiler

By compiling prompts prior to execution, agent-intent-compiler provides:

  1. Sub-Millisecond Sanitizer: Traverses AST syntax and analyzes Shannon entropy to halt hidden payloads.
  2. Typed Slot Compiler: Maps intent into strict Pydantic v2 schemas.
  3. Kahn's Algorithm DAG Stager: Prevents cycle loops and groups independent tasks for parallel execution.
  4. Cryptographic SHA-256 Merkle Root: Issues a tamper-proof verification seal for every execution plan.

Quickstart Implementation

pip install agent-intent-compiler
from agent_intent_compiler import IntentCompiler, MCPAdapter

compiler = IntentCompiler()
plan = compiler.compile("Migrate the production PostgreSQL database schema and verify table constraints")

print("Plan ID:", plan.plan_id)
print("Intent:", plan.intent_type)
print("Stages:", plan.execution_order)
print("Merkle Receipt:", plan.merkle_root)

# Convert directly to Model Context Protocol (MCP) tool requests
mcp_requests = MCPAdapter.to_mcp_requests(plan)
print(f"Generated {len(mcp_requests)} MCP JSON-RPC calls.")

Frequently Asked Questions

Why is compiling natural language before tool invocation crucial for AI agents?
Compiling natural language transforms unstructured prompts into typed, verified execution stages, halting prompt injections and saving over 60% of LLM reasoning tokens.
How does agent-intent-compiler prevent circular execution loops?
It uses Kahn's topological sorting algorithm on execution nodes, immediately catching cyclic dependencies before any subprocess or tool is triggered.