chain-rdeveloper portal
build

AI Service (svc-ai)

Overview

svc-ai is the AI execution engine. It provides LLM model management, agentic graph execution, RAG pipelines, skills, workers, and simulation. All LLM calls go through svc-ai using LiteLLM as the provider abstraction layer. LangGraph drives multi-agent workflow execution.

Internal port: 5000 (also exposed to host in dev for direct access)

Responsibilities

  • LLM provider and model registry management

  • Executing prompts against any registered model via LiteLLM

  • Running multi-agent LangGraph workflows (skills, workers, graphs)

  • Streaming execution results token-by-token over Server-Sent Events

  • RAG pipeline execution (Qdrant vector search)

  • Knowledge graph node-type registry (for svc-core)

  • MCP server template registry (MCP itself is off in every environment — app/mcp/__init__.py)

  • Token usage statistics aggregation

  • Simulation execution

API Domains

See spec/api/svc-ai.md for the full auto-generated reference.

Router prefixDomain
/modelsProvider and model CRUD, availability, validation, lookup
/agentsAgent/graph execution (streaming and batch)
/executeGeneric execution entrypoint
/skillsBuilt-in skill templates and worker agent definitions
/toolsBuilt-in tool registry
/knowledgeGraph node-type definitions; POST /knowledge/retrieve runs the retrieval pipeline directly; POST /knowledge/embed embeds texts for svc-core ingestion
/mcpMCP server templates; probe reports MCP unavailable without connecting
/statsToken usage aggregation
/simulateSimulation execution

LLM Model Registry

Providers (e.g. OpenAI, Anthropic) and their models are stored in postgres-ai. LiteLLM is used to discover available models for a provider and to validate and execute completions. svc-core resolves models by UUID via /models/lookup.

Execution Model

All execution flows through POST /agents/execute or the convenience paths that wrap it:

PathType
POST /agents/execute/streamStreaming SSE version
POST /agents/graphExecute a graph configuration directly
POST /agents/skillExecute a stored Skill as a LangGraph
POST /agents/workerExecute a single custom worker agent
POST /agents/analysisBuilt-in analysis graph (planner → analyzer → validator)
POST /agents/ragBuilt-in RAG pipeline

SSE Streaming Format

data: {"type": "status",  "message": "..."}
data: {"type": "token",   "token": "..."}
data: {"type": "done",    "output": "...", "usage": {...}}
data: {"type": "error",   "message": "..."}

Streaming is supported for model, skill, worker, and graph execution types. agent and pipeline types fall back to a single done frame.

Skills and Workers

  • Built-in skills — named LangGraph graph templates returned by GET /skills/available. Each template specifies the nodes (worker agent definitions) and edges.

  • Built-in workers — named WorkerAgentDefinition instances returned by GET /skills/agents. Workers have a role (e.g. analyzer, reviewer, planner) and a set of default tools.

  • Custom workers — stored in svc-core, executed by passing base_worker to POST /agents/worker. Custom system prompts and tool overrides are merged on top of the base definition.

  • Typed interfaces — workers may declare input_schema / output_schema (FieldSpecs). A non-empty output schema makes the worker return a validated JSON object, so skill graphs can bind {node.field} into downstream nodes and route on it with deterministic conditional edges (branches / route_field) — no LLM router needed. Skills may also declare an interface (typed inputs seeded from the caller, outputs projected into skill_outputs). See the Skills & Workers guide.

Built-in Tools

Registered in the BUILTIN_TOOLS registry, returned by GET /tools/available. Custom webhook tools can be defined inline in execution requests with type="webhook".

Retrieval (RAG) Pipeline

Knowledge retrieval is handled by the context-rich pipeline in app/knowledge/retrieval.py. It runs inside every graph execution as the knowledge nodes — __knowledge_plan__, a lane per kind of knowledge (__domain_retrieval__, __temporal_retrieval__, __reasoning_retrieval__) and __retrieval_join__ — and is also exposed directly as POST /knowledge/retrieve. See Knowledge Retrieval and Agent Graph for the full guides.

Stages (each a swappable strategy object):

  1. Query planning — the system LLM expands the question into rephrasings, sub-questions and a keyword variant, plus literal entity hints. Falls back to keyword extraction without an LLM.

  2. Graph retrieval — for graph KBs, entity text search in Neo4j and a neighbourhood walk into relationship facts. Entity names found here seed extra lexical queries against the vector KBs.

  3. Hybrid vector retrieval — dense (embedding) and lexical (Qdrant full-text MatchText, BM25-style scoring) legs for every query, fused with reciprocal-rank fusion.

  4. Reranking and the relevance gate — a listwise LLM judge, told what each searched knowledge base is for, rates the head; a passage rated below min_relevance is dropped. A judge that fails keeps every passage unjudged, marked so, and is reported (optional; rerank).

  5. Neighbour expansion — adjacent chunks of each selected passage are fetched and merged into a coherent window, each chunk's carried overlap with the one before dropped (documents.join_chunks).

  6. Packing — per-document / per-KB caps, near-duplicate removal and a token budget; passages get stable [S#] citation ids and are rendered as Markdown for downstream agents.

Tunables live in RetrievalConfig (app/models/spec.py) and arrive from svc-core as spec.retrieval. mode selects pipeline (deterministic only), agentic (legacy per-KB tool loop) or hybrid (pipeline evidence seeds an agentic gap-filling pass; default).

Structured citations (KB, document id, page, chunk span, snippet) are emitted as retrieval_citations in graph state, streamed as a citations SSE frame when the retrieval node completes, and merged ahead of tool-derived citations in the final response, each with its kind (source_ledger.TOOL_KINDS). The done frame and ExecuteResponse also carry cited_citations, what the answer itself cites.

Ingestion is owned by svc-core: documents are parsed by Docling, chunked (512 tokens, 64 overlap), embedded through svc-ai's POST /knowledge/embed (svc-core has no LLM egress) with the backend's embedding model (app/services/embeddings.py: Titan Text Embeddings V2 on Bedrock, text-embedding-3-small on direct; GET /knowledge/embedding names it), and upserted into a per-KB Qdrant collection carrying a full-text index on text plus document_id / chunk_index indexes.

The built-in RAG graph (POST /agents/rag) remains available for simple single-collection retrieval.

Runtime Dependencies

  • postgres-ai — model registry, LLM invocation records (ai-network)

  • Qdrant — vector storage for RAG (ai-network)

  • MinIO — knowledge document storage (ai-network)

  • Docling — document parsing (ai-network)

  • Neo4j — graph knowledge base (ai-network)

  • Amazon Bedrock — model calls in deployed environments; the OpenAI / Anthropic APIs when INFERENCE_BACKEND=direct (ai-egress-network)

  • Brave Search, web pages and feeds — web search, url_fetch, website sources (ai-egress-network; https on 443 to public addresses only)

Configuration

VariableDescription
ANTHROPIC_API_KEYAnthropic API key
DATABASE_URLpostgres-ai connection string
QDRANT_URLQdrant address (http://qdrant:6333)
MINIO_ENDPOINTMinIO address (minio:9000)
DOCLING_URLDocling address (http://docling:5001)
NEO4J_URINeo4j Bolt URI (bolt://neo4j:7687)
ENVIRONMENTdevelopment / production

Networks

  • backend-network — receives traffic from svc-core

  • ai-network — Qdrant, MinIO, Docling, Neo4j, postgres-ai (internal)

  • ai-egress-network — svc-ai's only route out: model calls, web search, page and feed fetches, tool calls

  • otel-network — OTLP traces to Tempo