ACP Intelligence Layer
The Intelligence Layer provides the "brain" for AI agents, enabling them to understand code structure, adhere to architectural patterns, and retrieve semantically relevant context.
Overview
Unlike standard LLM interactions which treat code as text, the ACP Intelligence Layer treats code as a structured graph. It uses:
- AST Analysis: To understand syntax and structure.
- Semantic Search (RAG): To understand intent and meaning.
- Architecture Guardian: To enforce governance and patterns.
Diagram: ACP Intelligence Architecture — AST Analysis feeds into Semantic Search (RAG), which is governed by the Architecture Guardian.
1. AST Analysis Engine
The Abstract Syntax Tree (AST) engine allows agents to query code structure rather than just matching text.
Capabilities
- Symbol Extraction: Identifies functions, classes, interfaces, and variables.
- Dependency Graphing: Maps imports and usage across files.
- Scope Analysis: Understands variable visibility and scope.
Supported Languages: Rust, Go, Python, TypeScript/JavaScript, Dart (Flutter).
Usage
Agents use the ast_query tool to ask questions like:
"Find all public functions in
auth_service.rsthat return aResult." "Show me whereUserProfilestruct is instantiated."
2. Intelligent Context Extraction
Feeding the right context to an LLM is critical for performance and cost. The Context Extractor assembles the optimal prompt payload.
Scoring Algorithm
The extractor ranks code chunks based on:
- Direct Relevance: The cursor position or active file.
- Definition: Code that defines symbols used in the focus area.
- Use: Code that uses symbols defined in the focus area.
- Semantic Similarity: Code with similar meaning (via RAG).
- Recency: Recently edited files.
Token Budgeting
The extractor trims low-priority context to fit within the model's context window (e.g., 1M tokens for Gemini 2.0 Flash, 200k for Claude Sonnet 4.5) while preserving critical definitions.
3. Architecture Guardian
The Guardian ensures that AI-generated code (and human code) adheres to Olympus Cloud's strict architectural standards.
Rule Enforcement
The Guardian checks code against a set of architecture-rules.yaml definitions:
- Layer Boundaries: "Handlers cannot import Repositories directly."
- Service Isolation: "Auth Service cannot import Commerce Service types."
- Pattern Compliance: "All gRPC handlers must implement the
defererror logger."
Workflow
The Architecture Guardian runs automatically on all AI-generated code and can optionally be enabled for human-authored code via CI. Violations with Severity: Error block the change entirely, while Severity: Warning issues are flagged but do not block.
- Pre-Generation: Agents query the Guardian to understand constraints.
- Post-Generation: The Guardian analyzes the proposed code change.
- Blocking: If a violation (
Severity: Error) is found, the change is rejected with a correction prompt.
4. Semantic Search (RAG)
Powered by Cloudflare Vectorize and Workers AI.
Indexing Pipeline
- Ingestion: Git push triggers a Cloud Build job.
- Chunking: Code is split by logical blocks (functions/classes) rather than arbitrary lines.
- Embedding:
bge-base-en-v1.5(or similar) creates vector embeddings. - Storage: Vectors are stored in Cloudflare Vectorize.
Retrieval
Agents utilize semantic_search to answer high-level questions:
"How do I implement a new payment provider?" "What is the standard pattern for distributed locking?"
The system returns relevant code snippets and documentation, ranking them by cosine similarity.
Related Documentation
- AI Agents - The agents using this intelligence.
- REST API Examples - How to interact with ACP via the REST API.