Skip to main content

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:

  1. AST Analysis: To understand syntax and structure.
  2. Semantic Search (RAG): To understand intent and meaning.
  3. 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.rs that return a Result." "Show me where UserProfile struct 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:

  1. Direct Relevance: The cursor position or active file.
  2. Definition: Code that defines symbols used in the focus area.
  3. Use: Code that uses symbols defined in the focus area.
  4. Semantic Similarity: Code with similar meaning (via RAG).
  5. 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 defer error logger."

Workflow

info

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.

  1. Pre-Generation: Agents query the Guardian to understand constraints.
  2. Post-Generation: The Guardian analyzes the proposed code change.
  3. 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

  1. Ingestion: Git push triggers a Cloud Build job.
  2. Chunking: Code is split by logical blocks (functions/classes) rather than arbitrary lines.
  3. Embedding: bge-base-en-v1.5 (or similar) creates vector embeddings.
  4. 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.