Locus Technical Documentation
This book is the technical reference for teams evaluating, integrating, and operating Locus in real systems.
Who This Is For
- Application developers building products on top of Locus
- Platform engineers integrating memory infrastructure into existing stacks
- Technical teams preparing architecture proposals and implementation plans
What You Can Decide With This Book
- Whether Locus fits your reliability and integration requirements
- Which runtime shape fits your environment (SDK, gateway, MCP)
- How to implement safely without rewriting contracts later
What You Get Here
- Architecture and protocol model details
- Storage and schema specifications
- SDK design and composition patterns
- Mini orchestration cookbooks with prompts and composition flows
- Agent blueprint patterns by domain and task model
- Deployment and operations guidance
- Troubleshooting and versioning policy
API Documentation
Generated Rust API docs are published alongside this book so implementation teams can move from architecture to code-level integration without switching references.
- Local build output:
docs/technical/api/index.html - Typical crate roots:
docs/technical/api/locus_core_rs/index.htmldocs/technical/api/locus_sdk/index.htmldocs/technical/api/locus_mcp/index.htmldocs/technical/api/locus_gateway/index.htmldocs/technical/api/locus_cli/index.html
Build
From repository root:
./docs/build-technical-docs.sh
Then open:
docs/technical/index.html
Environment Setup
Audience and Use
This page is for developers and platform teams preparing a reliable local or shared environment for Locus evaluation and integration.
Use it to:
- Confirm supported tooling and runtime combinations.
- Validate environment readiness before implementation work starts.
- Standardize local, CI, and staging setup patterns.
Support Matrix
| Component | Supported Baseline | Notes |
|---|---|---|
| Rust toolchain | Stable channel | Use a pinned stable toolchain in CI for reproducibility. |
| Cargo | Bundled with Rust stable | Required for build, test, examples, and docs generation. |
| OS (development) | Linux, macOS, Windows (WSL2 recommended) | Linux and macOS are primary paths for host scripting. |
| Container runtime | Docker Engine or compatible runtime | Required for image-based MCP and gateway startup paths. |
| Storage backend | In-memory or SurrealDB v3 | In-memory for fast local validation; SurrealDB for persistent environments. |
| Docs toolchain | mdbook, mdbook-mermaid | Required for generated technical docs site. |
Tooling Prerequisites
Install and verify:
rustc --version
cargo --version
docker --version
mdbook --version
mdbook-mermaid --version
If docs tools are missing:
cargo install mdbook
cargo install mdbook-mermaid
Recommended Environment Profiles
Local Development Profile
Use when iterating on features and integration code.
- Storage: in-memory or local SurrealDB.
- Host runtime: single process.
- Objective: speed and repeatability.
CI Validation Profile
Use for pull requests and release gating.
- Storage: deterministic in-memory fixtures.
- Host runtime: test-only jobs.
- Objective: compatibility and regression detection.
Staging Profile
Use for pre-production verification.
- Storage: isolated remote SurrealDB.
- Host runtime: gateway and MCP parity checks.
- Objective: rollout rehearsal and migration validation.
Baseline Verification
From repository root:
cargo check --workspace --examples
cargo test --workspace
cargo check --examples -p locus-sdk
./docs/build-technical-docs.sh
A setup is considered ready when all commands complete successfully.
Runtime Smoke Start
Image-based MCP:
docker run --rm -i -v "$PWD/locus-data:/data" ghcr.io/entasislabs/locus-mcp:0.1.0
Image-based gateway:
docker run --rm -p 8080:8080 -p 8081:8081 -v "$PWD/locus-data:/data" ghcr.io/entasislabs/locus-gateway:2.0.0
Environment Hygiene Controls
- Keep secrets outside repository files.
- Keep development and production data paths separate.
- Pin model and provider settings in shared environments.
- Use explicit tenant and session scope in integration tests.
Exit Criteria
Environment setup is complete when:
- Workspace build and tests pass.
- At least one host runtime starts successfully.
- Technical docs site builds successfully.
- Team members can reproduce setup using this page only.
Architecture
Audience and Use
This page is for engineers deciding how to adopt Locus in production systems.
Use it to:
- Choose where Locus should sit in your stack.
- Understand component responsibilities before integration starts.
- Avoid coupling host transports to internal implementation details.
Purpose
Locus is the Rust implementation layer for STTP memory systems. STTP remains the protocol layer. Locus provides reusable components for parsing, validation, storage, retrieval, and composition with stable contract boundaries.
Layering
- Protocol layer: STTP grammar and four-layer node contract.
- Implementation core: locus-core-rs.
- SDK/application layer: locus-sdk.
- Host transport layer: MCP, HTTP, gRPC hosts that consume Locus crates.
Crate Responsibilities
locus-core-rs
- Domain models and contracts.
- STTP parsing and validation.
- Storage adapters (in-memory and SurrealDB).
- Core services for calibration, store/query, rollups, and sync-ready primitives.
locus-sdk
- Primitive memory workflows: find, recall, aggregate, transform, explain, schema.
- Composition workflows for multi-step operations.
- Deterministic manual compression and recursive content construction.
- Transport DTOs and typed request/response boundaries.
Design Principles
- Deterministic-first behavior where possible.
- Explicit policy controls over hidden defaults.
- Transport-neutral workflows.
- Additive evolution with compatibility preservation.
- Observable retrieval paths with explainable outcomes.
Data Contract Boundaries
- STTP node text is validated against the protocol structure.
- Core models carry parsed and computed fields.
- SDK contracts define application-level behavior and policy.
- Transport DTOs convert cleanly into SDK contracts.
Dependency Direction
- locus-sdk depends on locus-core-rs.
- locus-core-rs has no dependency on locus-sdk.
- Hosts should depend on locus-sdk for workflow orchestration and on locus-core-rs only when low-level access is required.
This dependency model keeps host contracts stable while internal implementations evolve.
Locus Core Database Schema and Data Governance
Document Control
- Document ID: LOCUS-CORE-DATA-ARCH-001
- Status: Current
- Intended Audience: Platform Engineers, Data Engineers, Reliability Engineers, Security Reviewers
- Source of Truth:
locus-core-rsimplementation (domain/models.rs,storage/surrealdb/*,domain/contracts.rs) - Last Updated: 2026-05-04
Audience and Use
This document is for teams evaluating data durability, query behavior, and operational safety before adopting Locus in production systems.
Use it to:
- Validate persistence and indexing behavior against your workload.
- Understand multi-tenant and compatibility rules.
- Review storage-level guarantees before integration and rollout.
1. Purpose and Scope
This document specifies the persistence model used by locus-core-rs for STTP memory nodes, calibration records, and synchronization checkpoints.
It covers:
- Physical schema implemented in SurrealDB.
- Logical entity relationships.
- Idempotency and uniqueness rules.
- Multi-tenant and legacy-compatibility behavior.
- Query, indexing, and lifecycle constraints.
It does not cover:
- HTTP/gRPC transport contracts (documented in gateway docs).
- UI-facing DTO contracts (documented in SDK interface docs).
2. Architectural Context
locus-core-rs defines a storage abstraction (NodeStore) with two concrete implementations:
InMemoryNodeStorefor tests and ephemeral execution.SurrealDbNodeStorefor persistent runtime.
All persisted shape definitions and indexes in this document correspond to SurrealDbNodeStore schema initialization.
3. Canonical Logical Model
erDiagram
TEMPORAL_NODE {
string id PK
string tenant_id
string session_id
string tier
datetime timestamp
string sync_key
float psi
float rho
float kappa
}
CALIBRATION {
string id PK
string tenant_id
string session_id
float stability
float friction
float logic
float autonomy
float psi
datetime created_at
}
SYNC_CHECKPOINT {
string id PK
string tenant_id
string session_id
string connector_id
datetime cursor_updated_at
string cursor_sync_key
datetime updated_at
}
TEMPORAL_NODE }o--|| CALIBRATION : "session_scope"
TEMPORAL_NODE }o--|| SYNC_CHECKPOINT : "sync_scope"
4. Domain Model Alignment (UML)
classDiagram
class AvecState {
+float stability
+float friction
+float logic
+float autonomy
+float psi()
+float drift_from(previous)
+DriftClassification classify_drift(previous)
}
class SttpNode {
+string raw
+string session_id
+string tier
+datetime timestamp
+int compression_depth
+string parent_node_id
+string sync_key
+datetime updated_at
+object source_metadata
+string context_summary
+float[] embedding
+string embedding_model
+int embedding_dimensions
+datetime embedded_at
+AvecState user_avec
+AvecState model_avec
+AvecState compression_avec
+float rho
+float kappa
+float psi
+string canonical_sync_key()
}
class SyncCursor {
+datetime updated_at
+string sync_key
}
class SyncCheckpoint {
+string session_id
+string connector_id
+SyncCursor cursor
+datetime updated_at
+object metadata
}
class NodeStore {
<<interface>>
+query_nodes_async(query)
+upsert_node_async(node)
+get_by_resonance_async(...)
+get_by_hybrid_async(...)
+query_changes_since_async(...)
+get_checkpoint_async(...)
+put_checkpoint_async(...)
+batch_rekey_scopes_async(...)
}
SttpNode --> AvecState
SyncCheckpoint --> SyncCursor
NodeStore ..> SttpNode
NodeStore ..> SyncCheckpoint
5. Physical Schema (SurrealDB)
5.1 Table: temporal_node
Storage purpose:
- Authoritative persisted STTP node record.
- Supports retrieval, ranking, sync, and transform operations.
Key characteristics:
SCHEMAFULLtable.- Unique identity by
(tenant_id, session_id, sync_key). - Temporal ordering by
timestampandupdated_at.
Required fields:
- Identity and scope:
tenant_id,session_id,sync_key. - Protocol payload:
raw,tier,timestamp,compression_depth. - Metrics:
psi,rho,kappa. - AVEC projections:
user_*,model_*,comp_*.
Optional fields:
- Hierarchy:
parent_node_id. - Source lineage:
source_metadata. - Retrieval acceleration:
context_summary,embedding*,embedded_at.
5.2 Table: calibration
Storage purpose:
- Session-level AVEC measurement history.
Key characteristics:
SCHEMAFULLtable.- Ordered by
created_atfor latest state and trigger timeline.
5.3 Table: sync_checkpoint
Storage purpose:
- Connector/session cursor materialization for incremental pull.
Key characteristics:
SCHEMAFULLtable.- Unique by
(tenant_id, session_id, connector_id).
6. Index and Access Pattern Mapping
idx_node_sync_identity (tenant_id, session_id, sync_key UNIQUE)- Supports idempotent upsert semantics.
idx_node_change_cursor (tenant_id, session_id, updated_at, sync_key)- Supports stable incremental reads (
updated_at, tie-break bysync_key).
- Supports stable incremental reads (
idx_node_tenant_session (tenant_id, session_id)andidx_node_session (session_id)- Supports scoped listing and filtering.
idx_node_tier (tier),idx_node_timestamp (timestamp)- Supports filtering across tier/time windows.
idx_cal_tenant_session,idx_cal_session- Supports latest calibration and trigger history.
idx_checkpoint_scope (tenant_id, session_id, connector_id UNIQUE)- Supports deterministic checkpoint upsert.
7. Write Path Rules
7.1 Idempotent Upsert
upsert_node_async behavior:
- Normalize/derive
sync_keyif missing (canonical_sync_key). - Determine tenant from
session_idscope (tenant:<id>::session:<id>), else fallbackdefault. - Probe existing exact scope and fallback any-tenant records by
session_id + sync_key. - If fully equivalent payload/metadata exists ->
Duplicate. - If record exists with differences ->
Updated. - Otherwise create new ->
Created.
7.2 Conflict Handling
On unique index conflict:
- Attempt to resolve conflict record id and update in place.
- Re-read existing record if needed and classify as
UpdatedorDuplicate.
7.3 Compression AVEC Rule
If candidate compression_avec is absent or zeroed, model AVEC is used as persistence fallback for comp_* fields.
8. Read Path Rules
8.1 Query (query_nodes_async)
Supports:
- Optional session scope.
- Optional UTC lower/upper bounds.
- Optional tier set (case-insensitive).
- Descending
timestamporder.
8.2 Resonance Retrieval
Distance formula (per record):
ResonanceDelta = (|model_stability-s| + |model_friction-f| + |model_logic-l| + |model_autonomy-a|) / 4
Ordering:
- Ascending
ResonanceDelta.
8.3 Hybrid Retrieval
NodeStore defines hybrid retrieval APIs and graceful fallback behavior to resonance-only in implementations that cannot apply semantic ranking.
9. Sync and Change Data Capture
flowchart TD
A[Node upsert] --> B[Set updated_at and sync_key]
B --> C[Index supports cursor ordering]
C --> D[Query changes since cursor]
D --> E{More rows}
E -- yes --> F[Return page ordered by updated_at then sync_key]
E -- no --> G[has_more false]
F --> H[Consumer applies rows]
H --> I[Store checkpoint with next cursor]
Determinism contract:
- Cursor is composite:
(updated_at, sync_key). - Ordering is total for equal timestamps due to
sync_keytie-break.
10. Multi-Tenant and Legacy Compatibility
Tenant rules:
- Derived tenant for scoped sessions:
tenant:<tenant_id>::session:<session_id>. - Default tenant fallback:
default.
Legacy compatibility behavior:
- Reads include records where
tenant_idisNONEor empty for default tenant scope. - Initializer backfills missing tenant fields and legacy sync fields.
11. Scope Rekey Transaction Model
Batch rekey performs scope migration over full session scope, not anchor-only rows:
- Update
temporal_node.tenant_id,temporal_node.session_id. - Update
calibration.tenant_id,calibration.session_id. - Execute within a transaction block.
Safety semantics:
- Dry-run supported at service level.
- Merge conflict detection for target scope supported.
12. Validation and Integrity Constraints
Protocol-level validation (TreeSitterValidator) enforces:
- Required STTP layers present.
- Layer order correctness.
- Tier in allowed set:
raw|daily|weekly|monthly|quarterly|yearly. - Content nesting depth <= 5.
- Optional PSI coherence verification against compression AVEC.
These validations occur before persistence in StoreContextService workflows.
13. Operational Non-Functional Requirements
- Durability: SurrealDB persistence for production profile.
- Idempotency: guaranteed by sync identity index and upsert semantics.
- Replay safety: cursor/checkpoint design supports restartable sync pulls.
- Backward compatibility: additive schema evolution expected; legacy tenant buckets supported.
14. Schema Evolution Guidelines
Permitted changes:
- Additive nullable fields.
- Additive indexes for new access paths.
- New retrieval predicates that preserve existing defaults.
Controlled changes (require migration and compatibility review):
- Sync identity key shape.
- Cursor ordering columns.
- Tier vocabulary changes.
- AVEC projection field semantics.
15. Traceability to Implementation
Primary implementation locations:
locus-core-rs/src/storage/surrealdb/raw_queries.rslocus-core-rs/src/storage/surrealdb/node_store.rslocus-core-rs/src/domain/models.rslocus-core-rs/src/domain/contracts.rslocus-core-rs/src/application/validation/tree_sitter_validator.rs
Locus SDK Architecture Specification
Document Control
- Document ID: LOCUS-SDK-ARCH-001
- Status: Current
- Intended Audience: Application Developers, Platform Engineers, Solution Architects
- Source of Truth:
locus-sdkimplementation (application/*,domain/*,infrastructure/*,interface/*) - Last Updated: 2026-05-04
1. Purpose and Scope
This document defines the architecture of locus-sdk, including module boundaries, service orchestration, extension points, and operational behavior.
Use this document to evaluate integration fit, implementation boundaries, and operational implications before committing to host-level adoption.
Objectives:
- Make component responsibilities explicit.
- Reduce integration risk for host applications.
- Preserve backward-compatible architecture evolution.
2. Layered Architecture Overview
flowchart TD
A[Host Application] --> B[SDK API Surface - prelude]
B --> C[Application Services]
C --> D[Domain Contracts and Models]
C --> E[Infrastructure Adapters]
C --> F[Interface DTO Mappers]
E --> G[locus-core-rs NodeStore]
E --> H[AI Provider Runtime]
subgraph SDK
B
C
D
E
F
end
Layer intent:
prelude: stable ergonomic import surface for consumers.application: orchestration services and workflow composition.domain: neutral request/result types and provider contracts.infrastructure: concrete adapters and registries.interface: DTO translation boundary for transport adapters.
3. Module Decomposition
3.1 Domain Layer
domain/memory.rs: canonical memory query/recall/aggregate/transform contracts.domain/ai.rs: provider capability model and routing contracts.domain/compression.rs: manual compression request/result schema.
3.2 Application Layer
Primary services:
MemoryFindServiceMemoryRecallServiceMemoryExplainServiceMemoryAggregateServiceMemoryTransformServiceMemoryCompositionServiceMemorySchemaServiceManualCompressionService- AI routing helpers (
ai_router.rs,routing_config.rs)
3.3 Infrastructure Layer
InMemoryAiProviderRegistryGenaiProviderAdapter(feature-gated)SttpEmbeddingProviderAdapterOllamaEmbeddingProviderLocalEmbeddingProvider(featurelocal-embedding)
3.4 Interface Layer
interface/dto.rs: bidirectional mapping between SDK-native types and DTO structs.
4. Core Service Topology (UML)
flowchart TD
MCS[MemoryCompositionService]
MFS[MemoryFindService]
MRS[MemoryRecallService]
MES[MemoryExplainService]
MAS[MemoryAggregateService]
MTS[MemoryTransformService]
NS[NodeStore interface]
APR[AiProviderRegistry interface]
AP[AiProvider interface]
MCS --> MRS
MCS --> MES
MCS --> MAS
MFS --> NS
MRS --> NS
MES --> NS
MAS --> NS
MTS --> NS
MTS --> APR
APR --> AP
4.1 Query and Retrieval Services
classDiagram
class MemoryFindService {
+execute(request) MemoryFindResult
}
class MemoryRecallService {
+execute(request) MemoryRecallResult
}
class MemoryExplainService {
+execute(request) MemoryExplainResult
}
class MemoryAggregateService {
+execute(request) MemoryAggregateResult
}
class NodeStore {
<<interface>>
+query_nodes_async(query)
+get_by_resonance_async(...)
+get_by_hybrid_async(...)
}
MemoryFindService ..> NodeStore
MemoryRecallService ..> NodeStore
MemoryExplainService ..> NodeStore
MemoryAggregateService ..> NodeStore
4.2 Transform and Provider Resolution
classDiagram
class MemoryTransformService {
+execute(request) MemoryTransformResult
}
class AiProviderRegistry {
<<interface>>
+resolve(task, provider_id, policy)
+list_capabilities()
}
class AiProvider {
<<interface>>
+embed_semantic(request)
+embed_avec(request)
+score_avec(request)
}
class NodeStore {
<<interface>>
+upsert_node_async(node)
}
MemoryTransformService ..> NodeStore
MemoryTransformService ..> AiProviderRegistry
AiProviderRegistry ..> AiProvider
4.3 Composition Workflow Wiring
flowchart LR
MCS[MemoryCompositionService]
MRS[MemoryRecallService]
MES[MemoryExplainService]
MAS[MemoryAggregateService]
MTS[MemoryTransformService]
MCS -->|recall_with_explain| MRS
MCS -->|recall_with_explain| MES
MCS -->|daily_rollup| MAS
MCS -->|transform_then_recall_verify| MTS
MCS -->|transform_then_recall_verify| MRS
5. Request Lifecycle Patterns
5.1 Find Path
flowchart TD
A[MemoryFindRequest] --> B[Clamp limit]
B --> C[NodeStore.query_nodes_async]
C --> D[Apply common filters]
D --> E[Sort by selected field]
E --> F[Compute has_more and next_cursor]
F --> G[MemoryFindResult]
5.2 Recall Path with Fallback
flowchart TD
A[MemoryRecallRequest] --> B{query_embedding present?}
B -- yes --> C[Hybrid retrieval]
B -- no --> D[Resonance retrieval]
C --> E[Apply common filters]
D --> E
E --> F{Fallback policy allows lexical fallback?}
F -- no --> J[Return recall result]
F -- yes --> G[Expanded retrieval]
G --> H[Lexical scoring over summary/session/raw]
H --> I[Merge or replace depending on policy]
I --> J[Return recall result with retrieval_path]
5.3 Transform Path
flowchart TD
A[MemoryTransformRequest] --> B[Query and filter candidate nodes]
B --> C{operation == embed_backfill}
C -- yes --> D[Keep nodes missing embeddings]
C -- no --> E[Use selected set]
D --> E
E --> F{dry_run?}
F -- yes --> G[Return projected counts]
F -- no --> H[Batch through selected nodes]
H --> I[Route semantic embedding via provider registry]
I --> J[Apply embedding fields to node]
J --> K[NodeStore.upsert_node_async]
K --> L[Accumulate updated/skipped/failed/duplicate]
L --> M[Return MemoryTransformResult]
6. AI Routing and Provider Resolution
Routing semantics:
route_embeddingdispatches byAiTask(SemanticEmbeddingorAvecEmbedding).route_avec_scoredispatches scoring requests.
Provider selection (AiProviderRegistry.resolve):
- Explicit
provider_idmust exist and support requested task. ProviderPolicy::Requiredrequires explicit provider id.AutoandPreferredselect first provider supporting the task.
AiRoutingConfig responsibilities:
- Default provider fallback.
- Task-specific model selection per provider.
- Request mutation helper methods (
apply_to_embed_request,apply_to_score_request).
7. Data Contracts and Guardrails
Memory contract characteristics:
- Scope controls: tenant/session/tier/time.
- Filter controls: embedding presence/model, metric ranges, lexical contains.
- Scoring controls: alpha/beta and fallback policy.
Clamp guardrails:
clamp_limit: 1..200.clamp_groups: 1..5000.clamp_nodes: 1..50000.clamp_batch_size: 1..500.
These guardrails are enforced before expensive operations.
8. Composition Workflows
MemoryCompositionService encapsulates higher-level workflows:
recall_with_explain: single request emits both retrieval and explain trace.daily_rollup: aggregate by day over filtered scope.transform_then_recall_verify: execute transform, then immediate recall verification.build_content_from_text: deterministic structured content generation using manual compression and role-based AVEC resolution.
Composite content building constraints:
- Maximum recursion depth clamped to 5.
- Can require explicit AVEC overrides unless LLM fallback is allowed.
- Emits confidence-annotated structured JSON fields.
9. Infrastructure Adapters and Feature Gating
GenaiProviderAdapterbehindgenai-providerfeature.LocalEmbeddingProviderbehindlocal-embeddingfeature.OllamaEmbeddingProvideralways available.SttpEmbeddingProviderAdapterwrapslocus-core-rsEmbeddingProviderinto SDKAiProvidershape.
Operational note:
- Local embedding uses CPU-bound worker and blocking-task isolation for runtime safety.
10. DTO Boundary and Integration Strategy
interface/dto.rs provides:
- Inbound request conversion DTO -> domain model.
- Outbound response conversion domain model -> DTO.
- Composite workflow DTOs for composed service responses.
Design intent:
- Keep transport concerns out of domain/application layers.
- Preserve ability to evolve transport fields with additive mapping.
11. Reliability and Change Management Rules
Compatibility rules:
- Additive enums/fields are preferred evolution path.
- Existing defaults remain stable unless a versioned schema contract is introduced.
- New provider adapters must satisfy
AiProvidercapabilities explicitly.
Failure management principles:
- Partial batch failures are surfaced in
MemoryTransformResult.failures. - Fallback behavior is explicit and observable in explain outputs.
- Provider misconfiguration fails fast with structured errors.
12. Security and Operational Considerations
- Provider API keys and endpoints are externalized in host configuration.
- Text sent to embedding/scoring providers should be minimized to needed content.
MemoryTransformServicedry-run mode should be default for first execution in new environments.
13. Traceability to Implementation
Primary implementation locations:
locus-sdk/src/domain/memory.rslocus-sdk/src/domain/ai.rslocus-sdk/src/application/memory_find.rslocus-sdk/src/application/memory_recall.rslocus-sdk/src/application/memory_explain.rslocus-sdk/src/application/memory_aggregate.rslocus-sdk/src/application/memory_transform.rslocus-sdk/src/application/memory_composition.rslocus-sdk/src/application/routing_config.rslocus-sdk/src/infrastructure/registry.rslocus-sdk/src/infrastructure/embeddings.rslocus-sdk/src/interface/dto.rs
STTP SDK Recursive Node-From-Text Composite Guide
Date: 2026-05-03 Status: Implemented (initial slice)
1. Purpose
This guide documents the recursive deterministic composition workflow in locus-sdk.
The workflow lets callers build a spec-safe STTP content-layer payload from plain text entries without requiring model summarization for the core compression path.
2. What It Solves
- Build content payloads from ordered role-tagged text input.
- Support recursive context trees while staying validator-safe.
- Resolve AVEC using explicit deterministic policy order.
- Keep an optional LLM path only for unresolved AVEC, not core compression.
3. Core Types
Defined in locus-sdk/src/application/memory_composition.rs:
- CompositeRole
- CompositeInputItem
- CompositeRoleAvecOverrides
- CompositeNodeFromTextOptions
- CompositeNodeFromTextRequest
- CompositeNodeFromTextResult
DTO equivalents are defined in locus-sdk/src/interface/dto.rs:
- CompositeRoleDto
- CompositeInputItemDto
- CompositeRoleAvecOverridesDto
- CompositeNodeFromTextOptionsDto
- CompositeNodeFromTextRequestDto
- CompositeNodeFromTextResponseDto
4. Deterministic AVEC Resolution
For each input item, AVEC resolution order is:
- item-level override (CompositeInputItem.avec_override)
- role-level override (CompositeNodeFromTextOptions.role_avec)
- global override (CompositeNodeFromTextOptions.global_avec)
- unresolved
If unresolved item count is greater than zero:
- if allow_llm_avec_fallback is false, the workflow fails with a typed error,
- if allow_llm_avec_fallback is true, requires_llm_avec is true in the result.
5. Recursion and Validation Constraints
- Requested depth is clamped to [1, 5].
- Build fails if item context exceeds max_recursion_depth.
- The content object uses confidence-scored keys to remain strict-parser compatible.
- This aligns with validator nesting limits in core validator logic.
Reference: locus-core-rs/src/application/validation/tree_sitter_validator.rs
6. Compression Strategy
Each input/context item is compressed with ManualCompressionService to derive:
- anchor_topic
- key_points
This keeps the composite deterministic and model-optional for compression.
Reference: locus-sdk/src/application/manual_compression.rs
7. Quick Example (Domain Models)
use std::sync::Arc;
use anyhow::Result;
use locus_core_rs::{InMemoryNodeStore, NodeStore};
use locus_core_rs::domain::models::AvecState;
use locus_sdk::prelude::{
CompositeInputItem, CompositeNodeFromTextOptions, CompositeNodeFromTextRequest,
CompositeRole, CompositeRoleAvecOverrides, MemoryCompositionService,
};
fn main() -> Result<()> {
let store: Arc<dyn NodeStore> = Arc::new(InMemoryNodeStore::new());
let composition = MemoryCompositionService::new(store);
let req = CompositeNodeFromTextRequest {
items: vec![CompositeInputItem {
role: CompositeRole::Conversation,
text: "user asks about fallback policy and model explains ranked retrieval".to_string(),
avec_override: None,
context: vec![CompositeInputItem {
role: CompositeRole::Document,
text: "design notes mention deterministic lexical fallback".to_string(),
avec_override: None,
context: Vec::new(),
}],
}],
options: CompositeNodeFromTextOptions {
role_avec: CompositeRoleAvecOverrides {
conversation: Some(AvecState {
stability: 0.82,
friction: 0.20,
logic: 0.86,
autonomy: 0.74,
}),
..Default::default()
},
global_avec: Some(AvecState {
stability: 0.75,
friction: 0.25,
logic: 0.80,
autonomy: 0.70,
}),
allow_llm_avec_fallback: false,
max_recursion_depth: 5,
},
};
let result = composition.build_content_from_text(&req)?;
println!("resolved_avec_count={}", result.resolved_avec_count);
println!("requires_llm_avec={}", result.requires_llm_avec);
println!("content={}", result.content);
Ok(())
}
8. Quick Example (DTO Boundary)
#![allow(unused)]
fn main() {
use locus_sdk::prelude::{
CompositeNodeFromTextRequestDto, CompositeNodeFromTextResponseDto,
};
fn convert_boundary(req_dto: CompositeNodeFromTextRequestDto) -> CompositeNodeFromTextResponseDto {
let domain_req = req_dto.into();
let domain_result = service.build_content_from_text(&domain_req).unwrap();
domain_result.into()
}
}
9. Test Coverage
Current coverage includes:
- role and global AVEC resolution chain
- unresolved AVEC failure behavior
- recursion depth enforcement
- strict parser and validator conformance for generated content payload
Reference tests: locus-sdk/src/application/memory_composition.rs
10. Integration Notes
- This workflow currently returns content-layer payload plus AVEC resolution stats.
- It does not replace typed IR grammar; it composes spec-safe content for insertion into full STTP node workflows.
- Recommended next step is a full store-ready recipe that assembles the complete four-layer node from this content payload.
Deployment
Audience and Use
This page is for teams deploying Locus in development, staging, and production environments.
Use it to:
- Select an operating model by environment.
- Apply release checks before rollout.
- Keep runtime behavior consistent across deployment targets.
For prerequisite tooling and baseline readiness checks, see Environment Setup.
Supported Runtime Modes
- Embedded/local development mode.
- Remote SurrealDB mode.
- Hybrid host mode where gateway and MCP share the same underlying Locus behavior.
Environment Matrix
| Environment | Storage Mode | Host Profile | Primary Goal |
|---|---|---|---|
| Local Development | In-memory or embedded Surreal | single-process | fast iteration and debugging |
| CI Validation | In-memory plus deterministic fixtures | test-only jobs | regression detection and compatibility checks |
| Staging | Remote SurrealDB with isolated tenant space | gateway plus mcp parity checks | release verification and migration rehearsal |
| Production | Remote SurrealDB with restricted access | managed gateway and mcp deployments | reliability, auditability, and scale |
Build Prerequisites
- Rust toolchain (stable).
- cargo available in PATH.
- Optional: SurrealDB endpoint for integration environments.
Platform and Runtime Support
| Area | Baseline |
|---|---|
| Rust | Stable toolchain |
| Host OS | Linux, macOS, Windows (WSL2 recommended) |
| Container runtime | Docker Engine or compatible runtime |
| Storage | In-memory, SurrealDB v3 |
| Docs build | mdbook, mdbook-mermaid |
Build Commands
From repository root:
cargo check --workspace --examples
cargo test -p locus-core-rs --lib
cargo test -p locus-sdk
Packaging
Core package helper:
./locus-core-rs/build-package.sh
Publish preflight helper:
./locus-core-rs/publish-crates.sh
Configuration Guidance
- Keep environment-specific endpoint credentials out of repository files.
- Set explicit session/tenant scoping in host integrations.
- Prefer pinned model/provider settings for repeatable production behavior.
- Separate development and production provider endpoints.
- Use explicit tenant/session scoping in host runtime configs.
These controls reduce configuration drift and support predictable operations during upgrades.
Host Deployment Profiles
-
MCP host profile: MCP prioritizes tool contract stability and strict parser and validator checks in smoke tests.
-
Gateway host profile: Gateway prioritizes stable HTTP and gRPC mapping to SDK primitives with health checks and retrieval policy observability.
Release Readiness Checklist
- Workspace compile and tests pass.
- Example binaries compile and execute in CI smoke path.
- Integration hosts confirm SDK contract compatibility.
- Changelog and migration notes updated.
- Versioning and compatibility policy reviewed for this release.
- Security checklist validated for secrets and logging hygiene.
Releases that do not meet this checklist should not be promoted to production.
Release Gates by Environment
Local Development Gate
- Workspace compile succeeds.
- Targeted crate tests pass for changed modules.
- At least one example path executes without contract errors.
CI Validation Gate
- Workspace test matrix passes.
- Lint and docs build complete in CI.
- No parser or validator regressions in changed paths.
Staging Gate
- Gateway and MCP parity checks pass against the same dataset.
- Retrieval path distribution stays within expected baseline variance.
- Rollback procedure is rehearsed and time-bounded.
Production Promotion Gate
- Staging sign-off is recorded.
- Observability alerts and dashboards are active.
- Release note includes compatibility and rollback instructions.
Operations
Observability Priorities
- Retrieval path visibility for recall workflows.
- Fallback policy trigger visibility.
- Transform execution counters and failure reasons.
- Parser and validator error surface for malformed nodes.
Golden Signals
- Latency: recall and transform response times by percentile.
- Errors: parser, validator, retrieval, and transform failure rates.
- Throughput: query volume and transform batch throughput.
- Saturation: host and storage pressure indicators under load.
Runtime Health Signals
- Parse success ratio.
- Validation failure ratio.
- Recall latency percentiles.
- Transform batch success and failure counts.
- Embedding backfill throughput and error rates.
Alert Triggers
- Sudden rise in validation failures.
- Recall latency p95 breach sustained over multiple intervals.
- Unexpected shift in retrieval_path distribution.
- Transform failure ratio above configured threshold.
Incident Severity Model
- SEV-1: broad service impact or data integrity risk.
- SEV-2: degraded behavior with viable workaround.
- SEV-3: localized or non-critical workflow degradation.
Severity guides response urgency, escalation path, and communication cadence.
Suggested Starting Thresholds
These baseline thresholds are starting points and should be tuned per environment.
- Recall p95 latency: page at sustained breach over 15 minutes.
- Validation failure ratio: page when sustained above 2 percent.
- Transform failure ratio: page when sustained above 1 percent.
- Retrieval path drift: investigate when lexical fallback share doubles from baseline.
Severity-to-Response Mapping
- SEV-1: immediate incident bridge, continuous updates, executive and stakeholder notification.
- SEV-2: active triage with scheduled updates and rollback decision checkpoint.
- SEV-3: normal triage queue with documented mitigation and scheduled follow-up.
Logging Recommendations
- Log explicit policy settings for recall and transform requests.
- Log retrieval path and fallback reason for each recall request.
- Log session and tenant scope used for each operation.
- Keep request payload snapshots in redacted form for incident replay.
Incident Response Playbook
- Determine whether failure is parser, policy, or storage related.
- Reproduce with the same request payload and explicit limits.
- Use explain workflows to isolate ranking or fallback regressions.
- Run dry-run transforms before any broad mutation in recovery paths.
Runbooks
Runbook A: Parser/Validation Spike
- Capture representative failing payloads.
- Validate four-layer ordering and content confidence key format.
- Compare with last known-good release behavior.
- Roll back host version if failures are release-correlated.
Runbook B: Retrieval Regression
- Capture request payload, scoring settings, and retrieval_path.
- Execute explain workflow with same request.
- Compare channel scores and fallback behavior against baseline.
- Patch policy defaults only with regression test coverage.
Runbook C: Transform Job Instability
- Switch affected operations to dry-run mode.
- Validate selected node set and provider capabilities.
- Reduce batch_size and re-run with checkpoint controls.
- Resume full run only after zero-failure dry-run parity.
SLO Suggestions
- Recall p95 latency target per environment.
- Parse/validate success target for ingested nodes.
- Transform job success target and bounded failure budget.
Teams should define environment-specific numeric targets and review them at each release cycle.
Maintenance
- Keep crate versions aligned within workspace releases.
- Re-run examples as part of regression verification.
- Audit docs links and command validity each release cycle.
- Rehearse incident runbooks quarterly.
Integration
Audience and Use
This page is for developers integrating Locus into applications, services, and agent tooling.
Use it to:
- Define a stable integration boundary.
- Migrate existing retrieval logic without contract breakage.
- Validate behavior parity before cutover.
Goal
Integrate host transports with Locus crates while keeping STTP protocol semantics stable.
Recommended Integration Boundary
- Parse and validate at ingestion boundary.
- Convert transport payloads into SDK DTOs.
- Execute SDK workflows in application services.
- Map results back to transport contracts.
Host Migration Pattern
- Replace transport-owned retrieval logic with locus-sdk primitives.
- Keep endpoint names stable during migration.
- Add compatibility tests for behavior parity.
- Remove deprecated transport-local logic after one release cycle.
Compatibility Policy
- Keep external MCP tool and gateway endpoint contracts stable during internal rewires.
- Prefer additive fields and optional settings over contract replacement.
- Any unavoidable breaking change requires migration notes and version bump alignment.
- Retrieval policy defaults must remain explicit and test-covered.
This policy enables staged migrations while preserving downstream client compatibility.
MCP Integration Notes
- Prefer SDK primitives for list and context tools.
- Keep tool contracts stable; change only internals first.
- Add tests for fallback policy behavior and explain parity.
Gateway Integration Notes
- Route HTTP and gRPC handlers into SDK service layer.
- Share one request mapping strategy across transports.
- Keep response payload fields stable until formal API revision.
Safety Checks During Migration
- Compare retrieval_path results before and after migration.
- Compare transform counters and side effects in dry-run first.
- Validate strict parser compatibility for generated nodes.
Migration Acceptance Criteria
- Contract parity tests pass for migrated host routes/tools.
- Explain outputs are consistent with recall behavior before and after migration.
- Transform counters and dry-run selection remain behaviorally equivalent.
- Compile and runtime smoke checks pass in workspace and host deployment jobs.
Migration is complete only when all acceptance criteria are met.
Integration Acceptance Templates
Contract Parity Template
- Endpoint or tool name unchanged.
- Request field semantics unchanged or additive.
- Response field semantics unchanged or additive.
- Error code and message class behavior unchanged.
Retrieval Behavior Template
- retrieval_path distribution aligned with baseline behavior.
- Explain output aligns with returned recall results.
- Fallback activation remains policy-consistent.
- Latency profile remains within agreed operational bounds.
Rollout Gate Template
- Local and CI validation complete.
- Staging parity checks complete.
- Rollback path validated.
- Monitoring and alert hooks confirmed in target environment.
Cutover Checklist Template
Pre-Cutover Checks
- Freeze incompatible contract changes during the cutover window.
- Confirm request and response snapshots for baseline comparison.
- Confirm on-call ownership and escalation path.
Parity Checks During Cutover
- Compare retrieval_path and explain behavior between old and new integration paths.
- Compare latency and error rate against baseline windows.
- Validate parser and validator success ratios remain stable.
Rollback Criteria
- Error-rate increase exceeds agreed threshold.
- Contract mismatch is observed in client-visible payloads.
- Retrieval behavior diverges from baseline without approved policy change.
Post-Cutover Verification
- Re-run acceptance templates in production mode.
- Confirm no delayed transform or ingestion side effects.
- Publish cutover summary with observed deltas and follow-up actions.
Examples
Audience and Use
This page is for developers using Locus patterns in their own systems.
Use examples to:
- Start from known-good integration patterns.
- Validate behavior quickly in local environments.
- Translate reference workflows into production service code.
Available Example Binaries
- ../locus-sdk/examples/provider_registry_setup.rs
- ../locus-sdk/examples/memory_composition.rs
- ../locus-sdk/examples/recursive_composite_pipeline.rs
- ../locus-sdk/examples/generate_faker_fixture.rs
Run Examples
From repository root:
cargo run -p locus-sdk --example provider_registry_setup
cargo run -p locus-sdk --example memory_composition
cargo run -p locus-sdk --example recursive_composite_pipeline
cargo run -p locus-sdk --example generate_faker_fixture -- --help
Example Coverage
- Provider capability registry wiring.
- Composition workflows and multi-step orchestration.
- Recursive deterministic content construction plus strict parser and validator checks.
- Deterministic fixture generation for load and quality testing.
For domain-specific multi-agent setup patterns, see Agent Blueprints by Domain.
For practical GenAI plus STTP memory orchestration recipes, see Mini Orchestration Cookbooks.
If you want a fast path chooser by outcome and build style, start with Cookbook Overview.
Example Decision Guide
provider_registry_setup
Use when:
- You are wiring provider capability routing for the first time.
- You need to validate task-to-provider matching rules.
Expected outcome:
- Registry contains expected providers and capability visibility.
- Unsupported provider and task combinations fail with explicit errors.
Common failure checks:
- Provider IDs differ between config and runtime registration.
- Required capabilities are missing from selected providers.
Next integration step:
- Wire registry initialization into your service startup path and fail fast on missing capabilities.
memory_composition
Use when:
- You want a reference for multi-step memory workflows.
- You need recall and explain behavior in one composed flow.
Expected outcome:
- Composed workflow returns stable result shapes.
- Explain path aligns with recall outcome.
Common failure checks:
- Request policy settings are implicit instead of explicit.
- Scope filters are omitted, causing noisy result sets.
Next integration step:
- Promote composed request defaults into a shared app-level policy module.
recursive_composite_pipeline
Use when:
- You are building structured content from recursive composition.
- You need deterministic recursion-depth behavior.
Expected outcome:
- Recursive output respects depth and schema constraints.
- Content remains parser and validator compatible.
Common failure checks:
- Recursion depth exceeds configured limits.
- Output shape drifts from expected typed content structure.
Next integration step:
- Add schema-level response assertions in CI to prevent output drift before deployment.
generate_faker_fixture
Use when:
- You need reproducible fixture data for tests and benchmarking.
- You want fast local workload simulation.
Expected outcome:
- Fixture generation is deterministic for the same parameters.
- Generated payloads are valid for ingest and retrieval tests.
Common failure checks:
- Parameter ranges produce unrealistic payload distributions.
- Fixture output is not validated before being used in regression tests.
Next integration step:
- Add fixture generation to CI pre-test setup with deterministic seed controls.
Production Usage Guidance
- Treat examples as reference patterns, not deployment templates.
- Externalize credentials and environment-specific endpoints.
- Keep explicit limits and fallback policies in runtime requests.
- Add environment-specific observability and failure handling before production rollout.
Promotion Checklist
Before promoting an example pattern into production code:
- Add scope controls and policy defaults explicitly.
- Add structured error handling and retry boundaries.
- Add telemetry for latency, fallback behavior, and failures.
- Add regression tests for request and response shape stability.
Cookbook Overview
Start Here
This is the fastest way to choose the right Locus cookbook for your use case.
Pick by outcome, not by internal architecture.
Choose by Outcome
I need better answers in customer-facing workflows
Start with:
I need safer incident or operations decisions
Start with:
I need rollout-safe automation with dry-run controls
Start with:
I need research and synthesis across sessions
Start with:
Choose by Build Style
I want code-first SDK examples
Start with Examples.
I want orchestration recipes plus prompt templates
Start with Mini Orchestration Cookbooks.
I want domain presets and starter config values
Start with Agent Blueprints by Domain.
Quick Path Matrix
| Goal | First Page | Time to First Value |
|---|---|---|
| Support copilot with memory grounding | Cookbook 1 | 30-60 minutes |
| Incident triage with explain guardrails | Cookbook 2 | 45-90 minutes |
| Release decision workflow with dry-run transforms | Cookbook 3 | 60-120 minutes |
| Research synthesis with deterministic context shaping | Cookbook 4 | 45-90 minutes |
| Domain-specific rollout preset | Agent Blueprints | 30-60 minutes |
Implementation Flow We Recommend
- Start with one cookbook and keep scope narrow.
- Run recall plus explain before writing any policy automation.
- Add transform dry-run as a safety default.
- Promote to production only after integration acceptance checks.
Competitive Positioning
Locus is optimized for teams that need:
- memory behavior that is observable and explainable,
- deterministic workflow composition options,
- transport-neutral integration paths across SDK, MCP, and gateway.
Use this hub as your entrypoint, then deepen into the linked pages.
Mini Orchestration Cookbooks
Why This Exists
This chapter is for builders who want working patterns, not theory.
Use these cookbooks when you want:
- GenAI to handle model-facing intelligence.
- Locus to handle memory, recall policy, explainability, and safe transforms.
- A repeatable orchestration shape you can adapt by domain.
For a fast picker by outcome, go to Cookbook Overview.
Core Pattern
Every cookbook in this chapter follows the same loop:
- Ingest events into STTP memory.
- Recall context with explicit scoring and fallback policy.
- Explain the retrieval path before high-impact actions.
- Optionally run transform in dry-run before mutation.
- Pass grounded context into a prompt template for model response.
GenAI Hookup: Provider and Routing
Use GenAI as the model interface and keep memory orchestration in Locus.
#![allow(unused)]
fn main() {
use std::collections::HashMap;
use std::sync::Arc;
use anyhow::Result;
use locus_sdk::prelude::{
AiRoutingConfig, InMemoryAiProviderRegistry, ProviderModelProfile,
};
#[cfg(feature = "genai-provider")]
use locus_sdk::prelude::GenaiProviderAdapter;
fn build_registry_and_routing() -> Result<(Arc<InMemoryAiProviderRegistry>, AiRoutingConfig)> {
let mut registry = InMemoryAiProviderRegistry::new();
#[cfg(feature = "genai-provider")]
registry.register(GenaiProviderAdapter::new(
"genai",
Some("text-embedding-3-small".to_string()),
));
let mut providers = HashMap::new();
providers.insert(
"genai".to_string(),
ProviderModelProfile {
semantic_model: Some("text-embedding-3-small".to_string()),
avec_embedding_model: Some("text-embedding-3-small".to_string()),
avec_scoring_model: Some("gpt-4o-mini".to_string()),
},
);
let routing = AiRoutingConfig {
default_provider_id: Some("genai".to_string()),
providers,
};
Ok((Arc::new(registry), routing))
}
}
Integration note:
- Configure credentials for your selected GenAI provider in environment variables.
- Keep provider IDs stable across environments for predictable routing behavior.
Composition Primer
The MemoryCompositionService gives you high-level orchestration:
recall_with_explainfor grounded context with retrieval diagnostics.daily_rollupfor memory compression over time windows.transform_then_recall_verifyfor safe write-preview and immediate validation.build_content_from_textfor deterministic content construction.
Cookbook 1: Support Copilot (Fast Resolution)
Intent:
- Pull the smallest high-confidence context window.
- Generate a customer-safe next action grounded in prior resolutions.
use anyhow::Result;
use std::sync::Arc;
use locus_core_rs::{InMemoryNodeStore, NodeStore};
use locus_sdk::prelude::{
FallbackPolicy, MemoryCompositionService, MemoryRecallRequest, MemoryScoring,
};
#[tokio::main]
async fn main() -> Result<()> {
let store: Arc<dyn NodeStore> = Arc::new(InMemoryNodeStore::new());
let composition = MemoryCompositionService::new(store);
let result = composition
.recall_with_explain(&MemoryRecallRequest {
query_text: Some("billing mismatch after plan upgrade".to_string()),
scoring: MemoryScoring {
alpha: 0.70,
beta: 0.30,
fallback_policy: FallbackPolicy::OnEmpty,
..Default::default()
},
..Default::default()
})
.await?;
println!(
"retrieved={}, path={:?}, stages={}",
result.recall.retrieved,
result.explain.retrieval_path,
result.explain.stages.len()
);
Ok(())
}
Prompt template:
system:
You are a support resolution assistant.
Use only provided context. If evidence is weak, say so explicitly.
user:
Issue: {{live_issue_summary}}
Top memory context:
{{ranked_context_snippets}}
Return:
1) likely root cause
2) next best action
3) confidence (0-1)
4) what evidence is still missing
Cookbook 2: Incident Triage Captain (Explain Before Escalate)
Intent:
- Keep response speed high.
- Require explain trace before severity escalation.
use anyhow::Result;
use std::sync::Arc;
use locus_core_rs::{InMemoryNodeStore, NodeStore};
use locus_sdk::prelude::{
FallbackPolicy, MemoryCompositionService, MemoryRecallRequest, MemoryScoring,
StrictnessMode,
};
#[tokio::main]
async fn main() -> Result<()> {
let store: Arc<dyn NodeStore> = Arc::new(InMemoryNodeStore::new());
let composition = MemoryCompositionService::new(store);
let triage = composition
.recall_with_explain(&MemoryRecallRequest {
query_text: Some("unusual outbound auth failures".to_string()),
scoring: MemoryScoring {
alpha: 0.75,
beta: 0.25,
fallback_policy: FallbackPolicy::Always,
strictness: StrictnessMode::Precision,
..Default::default()
},
..Default::default()
})
.await?;
println!("path={:?}", triage.explain.retrieval_path);
println!("fallback_triggered={}", triage.explain.fallback_triggered);
Ok(())
}
Prompt template:
system:
You are an incident triage assistant. Never recommend irreversible action without evidence.
user:
Signal summary: {{signal_summary}}
Explain trace:
{{explain_stages}}
Top evidence:
{{context_snippets}}
Return:
1) severity recommendation
2) containment candidates
3) risks of false positive
4) evidence citations
Cookbook 3: Release Reliability Coach (Dry-Run First)
Intent:
- Preview transform impact before writes.
- Validate retrieval quality immediately after transform simulation.
use anyhow::Result;
use std::sync::Arc;
use locus_core_rs::{InMemoryNodeStore, NodeStore};
use locus_sdk::prelude::{
InMemoryAiProviderRegistry, MemoryCompositionService, MemoryRecallRequest,
MemoryTransformOperation, MemoryTransformRequest, MemoryTransformThenRecallRequest,
};
#[tokio::main]
async fn main() -> Result<()> {
let store: Arc<dyn NodeStore> = Arc::new(InMemoryNodeStore::new());
let composition = MemoryCompositionService::new(store);
let providers = Arc::new(InMemoryAiProviderRegistry::new());
let result = composition
.transform_then_recall_verify(
providers,
&MemoryTransformThenRecallRequest {
transform: MemoryTransformRequest {
operation: MemoryTransformOperation::EmbedBackfill,
dry_run: true,
batch_size: 25,
max_nodes: 500,
..Default::default()
},
recall: MemoryRecallRequest {
query_text: Some("release rollback patterns".to_string()),
..Default::default()
},
},
)
.await?;
println!("selected={}, updated={}", result.transform.selected, result.transform.updated);
println!("retrieved={}", result.recall.retrieved);
Ok(())
}
Prompt template:
system:
You are a release reliability assistant.
Prefer conservative recommendations when regression evidence is incomplete.
user:
Release context: {{release_context}}
Transform preview: {{transform_summary}}
Recall context: {{recall_summary}}
Return:
1) promote / hold / rollback recommendation
2) top risk factors
3) confidence
4) mandatory verification checks
Cookbook 4: Research Synthesizer (Deterministic Memory Build)
Intent:
- Structure raw research notes into deterministic memory content.
- Ask the model to synthesize only after context is structured and scoped.
use anyhow::Result;
use std::sync::Arc;
use locus_core_rs::{InMemoryNodeStore, NodeStore};
use locus_sdk::prelude::{
CompositeInputItem, CompositeNodeFromTextOptions, CompositeNodeFromTextRequest,
CompositeRole, MemoryCompositionService,
};
fn main() -> Result<()> {
let store: Arc<dyn NodeStore> = Arc::new(InMemoryNodeStore::new());
let composition = MemoryCompositionService::new(store);
let structured = composition.build_content_from_text(&CompositeNodeFromTextRequest {
items: vec![CompositeInputItem {
role: CompositeRole::Document,
text: "Policy memo highlights housing supply bottlenecks".to_string(),
avec_override: None,
context: vec![],
}],
options: CompositeNodeFromTextOptions {
allow_llm_avec_fallback: false,
max_recursion_depth: 3,
..Default::default()
},
})?;
println!("resolved_avec_count={}", structured.resolved_avec_count);
println!("requires_llm_avec={}", structured.requires_llm_avec);
Ok(())
}
Prompt template:
system:
You are a research synthesis assistant.
Preserve uncertainty and disagreement; do not collapse conflicting evidence.
user:
Question: {{research_question}}
Structured context payload:
{{structured_content}}
Return:
1) synthesis
2) competing interpretations
3) confidence per claim
4) additional evidence needed
Prompting Rules That Work Well With STTP
- Require evidence-cited outputs for high-impact decisions.
- Ask for explicit confidence fields rather than vague certainty language.
- Pass retrieval metadata to the prompt when using explain-driven guardrails.
- Preserve contradictions in output instead of forcing a single narrative.
Anti-Patterns
- Letting model responses bypass retrieval and explain checks.
- Running transforms without dry-run in fresh environments.
- Using broad session scopes that mix unrelated workflows.
- Tuning alpha and beta without checking retrieval_path drift.
Where To Go Next
- For domain presets, continue with Agent Blueprints by Domain.
- For API-level examples, use Examples.
- For rollout safeguards, use Integration and Operations.
Agent Blueprints by Domain
Audience and Use
This page is for teams designing task-specific agents that share one STTP memory backbone.
Use it to:
- Map business tasks to concrete agent memory behavior.
- Reuse reliable STTP patterns across multiple domains.
- Start with practical defaults before deep customization.
Blueprint Format
Each blueprint defines:
- Primary task and success criteria.
- Memory ingestion pattern across raw, daily, and weekly tiers.
- Retrieval policy defaults.
- Operational guardrails and handoff points.
Shared Foundation for All Blueprints
Start each agent with these defaults:
- Parse and validate all stored nodes before persistence.
- Require explicit tenant and session scope on write and recall.
- Store key runtime policy values alongside each operation.
- Keep explain-capable recall enabled for incident diagnostics.
Blueprint 1: Customer Support Resolution Agent
Primary task:
- Resolve customer issues faster while preserving account context.
Memory pattern:
- raw: ticket transcript fragments, action decisions, workaround attempts.
- daily: condensed issue timeline and resolution outcomes.
- weekly: recurring issue clusters and escalation themes.
Retrieval defaults:
- Start with hybrid retrieval when embeddings exist.
- Enable lexical fallback for sparse or new accounts.
- Limit recall result set to a small operator-reviewable window.
Guardrails:
- Escalate when confidence on root-cause fields falls below policy threshold.
- Require human approval before customer-visible policy exceptions.
Blueprint 2: Revenue and Account Strategy Agent
Primary task:
- Prepare account intelligence summaries for sales and success teams.
Memory pattern:
- raw: call notes, objections, product-fit signals, next-step commitments.
- daily: account momentum summary with confidence annotations.
- weekly: pipeline risk and expansion opportunity themes.
Retrieval defaults:
- Prioritize recent daily and weekly tiers for executive summaries.
- Pull raw evidence snippets for every high-impact recommendation.
Guardrails:
- Block outbound recommendations lacking supporting evidence links.
- Flag contradictory account signals for manual review.
Blueprint 3: Security Incident Triage Agent
Primary task:
- Speed investigation and containment decisions during active incidents.
Memory pattern:
- raw: alerts, timeline events, containment steps, IOC references.
- daily: incident narrative with mitigation state.
- weekly: recurring attack pattern and control-gap rollups.
Retrieval defaults:
- Bias toward strict time-window filtering during active incidents.
- Use explain flows on every severity upgrade recommendation.
Guardrails:
- Require dual confirmation before irreversible containment actions.
- Freeze autonomous remediation if retrieval path deviates from baseline.
Blueprint 4: Clinical Operations Coordination Agent
Primary task:
- Improve handoff quality across clinical operations teams.
Memory pattern:
- raw: triage notes, operational handoff details, care coordination tasks.
- daily: shift-level summary and unresolved coordination items.
- weekly: recurring workflow bottlenecks and staffing friction themes.
Retrieval defaults:
- Prefer deterministic recall windows scoped to active handoff queues.
- Keep retrieval limits tight for auditability and review speed.
Guardrails:
- Restrict memory access by role and operational scope.
- Require explicit redaction policy for sensitive fields before storage.
Blueprint 5: Engineering Release Reliability Agent
Primary task:
- Reduce regressions by preserving release and rollback context.
Memory pattern:
- raw: deploy events, test failures, rollback attempts, mitigation notes.
- daily: release status summary and unresolved risks.
- weekly: stability trend and recurring failure-class rollup.
Retrieval defaults:
- Compare current release signals against recent weekly baselines.
- Use explain traces to justify promote, hold, or rollback decisions.
Guardrails:
- Require rollback recommendation when failure classes repeat beyond threshold.
- Block promotion if validation success metrics regress from baseline.
Blueprint 6: Research and Policy Analysis Agent
Primary task:
- Build traceable recommendations from large document sets.
Memory pattern:
- raw: source excerpts with provenance and extraction rationale.
- daily: topic summaries with confidence-scored claims.
- weekly: cross-source synthesis with contradiction tracking.
Retrieval defaults:
- Retrieve source-backed evidence first, synthesized claims second.
- Use lexical fallback for low-embedding or highly technical terminology.
Guardrails:
- Do not emit conclusions without source-linked evidence fields.
- Route high-impact policy conclusions through human review.
Implementation Template
Use this checklist when instantiating any blueprint:
- Define task-specific session naming and tenant strategy.
- Define required content fields and confidence expectations.
- Define fallback policy and acceptable retrieval_path behavior.
- Define transform workflows and dry-run policy.
- Define escalation, rollback, and audit logging requirements.
Starter Request Shape
Use a request profile like this as a baseline for domain agents:
session scope: <tenant>::<agent-role>::<workstream>
tiers: ["raw", "daily", "weekly"]
retrieval policy:
mode: hybrid-preferred
lexical_fallback: enabled
limit: 5-20 depending on operator review mode
explain: enabled for all high-impact actions
transform mode: dry-run first in new environments
Drop-In Starter Configs
Use these as first-pass defaults. Tune only after collecting baseline metrics.
Config A: Customer Support Resolution
session pattern: tenant::<account-id>::agent::support-resolution::<ticket-id>
tiers: ["raw", "daily", "weekly"]
limit: 8
alpha: 0.70
beta: 0.30
retrieval mode: hybrid-preferred
lexical fallback: enabled
time window: last 30 days by default
explain: required for escalation and exception decisions
transform mode: dry-run for new policy revisions
Config B: Revenue and Account Strategy
session pattern: tenant::<account-id>::agent::revenue-strategy::<quarter>
tiers: ["daily", "weekly", "raw"]
limit: 12
alpha: 0.60
beta: 0.40
retrieval mode: hybrid-preferred
lexical fallback: enabled
time window: last 90 days by default
explain: required for outbound recommendation generation
transform mode: dry-run for scoring-model changes
Config C: Security Incident Triage
session pattern: tenant::<org-id>::agent::security-triage::<incident-id>
tiers: ["raw", "daily"]
limit: 6
alpha: 0.75
beta: 0.25
retrieval mode: hybrid-preferred with strict time filtering
lexical fallback: enabled
time window: incident start to now
explain: required for severity upgrade and containment recommendations
transform mode: dry-run first, then controlled batch execution
Config D: Clinical Operations Coordination
session pattern: tenant::<facility-id>::agent::clinical-ops::<shift-id>
tiers: ["raw", "daily"]
limit: 7
alpha: 0.65
beta: 0.35
retrieval mode: deterministic-first with hybrid fallback
lexical fallback: enabled
time window: active shift plus previous shift handoff window
explain: required for unresolved handoff item recommendations
transform mode: dry-run until handoff schema is stable
Config E: Engineering Release Reliability
session pattern: tenant::<org-id>::agent::release-reliability::<release-id>
tiers: ["raw", "daily", "weekly"]
limit: 10
alpha: 0.68
beta: 0.32
retrieval mode: hybrid-preferred
lexical fallback: enabled
time window: release window plus previous two release cycles
explain: required for promote, hold, and rollback recommendations
transform mode: dry-run for migration and backfill operations
Config F: Research and Policy Analysis
session pattern: tenant::<program-id>::agent::policy-analysis::<topic-id>
tiers: ["raw", "daily", "weekly"]
limit: 14
alpha: 0.55
beta: 0.45
retrieval mode: hybrid-preferred with source-first ordering
lexical fallback: enabled
time window: topic-defined research horizon
explain: required for all high-impact conclusions
transform mode: dry-run for synthesis template updates
Tuning Sequence
When adjusting any config:
- Tune limit first to match operator review capacity.
- Tune alpha and beta second to control resonance versus semantic emphasis.
- Tune time window third to reduce noise without losing critical context.
- Keep explain enabled while tuning to verify retrieval_path behavior.
End-to-End Sample Flows
Each flow uses the same four-step runtime pattern:
- Ingest: store raw node events.
- Recall: retrieve relevant context using scoped policy.
- Explain: inspect retrieval path and score behavior.
- Transform dry-run: preview rollups or embedding updates before mutation.
Flow A: Customer Support Resolution
step 1 ingest
session_id: tenant::acme::agent::support-resolution::ticket-1042
tier: raw
content focus: issue summary, attempted fix, customer impact
step 2 recall
tiers: ["raw", "daily", "weekly"]
limit: 8
alpha: 0.70
beta: 0.30
lexical fallback: enabled
step 3 explain
verify retrieval_path is hybrid or lexical_fallback as expected
confirm top results include prior resolutions for same issue family
step 4 transform dry-run
operation: monthly_rollup
dry_run: true
expected: projected counts and no persisted mutations
Flow B: Revenue and Account Strategy
step 1 ingest
session_id: tenant::acme::agent::revenue-strategy::2026-q2
tier: raw
content focus: objection notes, expansion signals, decision stakeholders
step 2 recall
tiers: ["daily", "weekly", "raw"]
limit: 12
alpha: 0.60
beta: 0.40
lexical fallback: enabled
step 3 explain
verify top recommendations are linked to supporting evidence
verify contradictory signals are surfaced in results
step 4 transform dry-run
operation: weekly_rollup
dry_run: true
expected: account momentum summary preview without writes
Flow C: Security Incident Triage
step 1 ingest
session_id: tenant::acme-sec::agent::security-triage::inc-8891
tier: raw
content focus: alert details, IOC artifacts, containment actions
step 2 recall
tiers: ["raw", "daily"]
limit: 6
alpha: 0.75
beta: 0.25
lexical fallback: enabled
time window: incident_start..now
step 3 explain
verify severity recommendation is traceable to matching indicators
verify retrieval_path remains stable across repeated calls
step 4 transform dry-run
operation: embed_backfill
dry_run: true
expected: selected node count for embedding without updates
Flow D: Clinical Operations Coordination
step 1 ingest
session_id: tenant::north-hospital::agent::clinical-ops::shift-2026-05-05-n1
tier: raw
content focus: handoff notes, unresolved tasks, time-critical blockers
step 2 recall
tiers: ["raw", "daily"]
limit: 7
alpha: 0.65
beta: 0.35
lexical fallback: enabled
time window: active_shift_plus_prior_handoff
step 3 explain
verify unresolved handoff items rank ahead of historical summaries
verify retrieval_path reflects deterministic-first policy intent
step 4 transform dry-run
operation: daily_rollup
dry_run: true
expected: shift summary preview for coordinator review
Flow E: Engineering Release Reliability
step 1 ingest
session_id: tenant::acme-eng::agent::release-reliability::release-2.7.0
tier: raw
content focus: test failures, deploy checkpoints, rollback notes
step 2 recall
tiers: ["raw", "daily", "weekly"]
limit: 10
alpha: 0.68
beta: 0.32
lexical fallback: enabled
time window: current_release_plus_two_prior
step 3 explain
verify recurring failure classes are present in top-ranked context
verify promote or rollback suggestion is evidence-backed
step 4 transform dry-run
operation: monthly_rollup
dry_run: true
expected: release stability trend preview with no writes
Flow F: Research and Policy Analysis
step 1 ingest
session_id: tenant::policy-lab::agent::policy-analysis::housing-supply
tier: raw
content focus: source excerpts, claims, contradiction annotations
step 2 recall
tiers: ["raw", "daily", "weekly"]
limit: 14
alpha: 0.55
beta: 0.45
lexical fallback: enabled
ordering intent: source-first then synthesis
step 3 explain
verify every high-impact conclusion maps to source-backed entries
verify contradiction nodes are retained in top context window
step 4 transform dry-run
operation: weekly_rollup
dry_run: true
expected: synthesis preview with confidence-bearing claim structure
Fast Adaptation Notes
- Keep the four-step flow constant across domains.
- Change session naming and time windows first for domain fit.
- Change alpha and beta only after baseline explain traces are stable.
- Keep transform in dry-run mode until rollback criteria are documented.
Choosing Your First Blueprint
- High-volume interaction workflows: start with Customer Support Resolution.
- Time-critical response workflows: start with Security Incident Triage.
- Cross-team handoff workflows: start with Clinical Operations Coordination.
- Decision-justification workflows: start with Research and Policy Analysis.
Then adapt the same STTP patterns to your domain-specific contracts and controls.
Troubleshooting
Triage Workflow
Use this sequence to reduce time-to-diagnosis:
- Reproduce with the smallest failing input.
- Classify failure domain: build/test, parser/validator, retrieval, or transform.
- Run the command pack for that domain.
- Capture escalation bundle before changing runtime defaults.
Command Packs
Build and Test Command Pack
Run from repository root:
cargo check --workspace --examples
cargo test --workspace
cargo test -p locus-core-rs --lib
cargo test -p locus-sdk
Use when:
- CI fails but local state is unclear.
- A release candidate needs a fast baseline confidence pass.
Parser and Validator Command Pack
Run from repository root:
cargo test -p locus-core-rs parser_tests
cargo test -p locus-core-rs validator_tests
cargo test -p locus-core-rs end_to_end_parsing_tests
Use when:
- Ingestion rejects node payloads.
- Strict profile compatibility appears unstable.
Retrieval Command Pack
Run from repository root:
cargo test -p locus-core-rs context_query_service_tests
cargo test -p locus-sdk --example memory_composition
cargo test -p locus-sdk --example provider_registry_setup
Use when:
- retrieval_path behavior diverges from expected baseline.
- recall and explain outputs are not aligned.
Transform and Sync Command Pack
Run from repository root:
cargo test -p locus-core-rs monthly_rollup_service_tests
cargo test -p locus-core-rs sync_coordinator_service_tests
cargo test -p locus-core-rs surrealdb_node_store_tests
cargo test -p locus-core-rs surrealdb_runtime_tests
Use when:
- Backfill, rollup, or sync progression stalls.
- selected/updated/skipped counts are inconsistent.
Build and Test Failures
Build/Test Symptom
cargo test fails in integration targets while unit tests pass.
Build/Test Actions
- Run crate-scoped tests first to isolate failure domain.
- Run failing target with single thread when test state leakage is suspected.
- Compare behavior against known baseline in source repository if migrating.
- Capture failing command output and the exact crate version set.
Build/Test Common Signatures
- Integration tests fail while crate lib tests pass: likely environment or fixture state isolation issue.
- Workspace build passes but host runtime fails: likely endpoint/config mismatch.
Parser and Validation Errors
Parser/Validation Symptom
Stored node rejected or strict parser fails.
Parser/Validation Actions
- Confirm four-layer ordering is preserved.
- Confirm content keys use field_name(.confidence) format.
- Confirm content nesting depth does not exceed five.
- Re-run parser and validator command pack and compare strict versus tolerant outcomes.
Parser/Validation Common Signatures
- Missing required layer errors indicate malformed STTP spine.
- Invalid key format errors indicate content keys not using field_name(.confidence).
- Nesting depth errors indicate recursive payload exceeded protocol constraints.
Retrieval Behavior Mismatch
Retrieval Symptom
Unexpected recall ranking or fallback path.
Retrieval Actions
- Log full scoring policy and scope.
- Verify alpha and beta values are explicitly set.
- Use explain workflow to inspect fallback triggers and stage counts.
- Compare retrieval_path distribution to recent baseline window before changing policy defaults.
Retrieval Common Signatures
- Unexpected lexical_fallback path often indicates sparse embeddings or strict filter scope.
- Score drift with unchanged input usually indicates policy defaults changed between versions.
Transform/Migration Issues
Transform/Migration Symptom
Embedding backfill updates fewer nodes than expected.
Transform/Migration Actions
- Run dry-run first and inspect selected counts.
- Validate filter scope and has_embedding settings.
- Validate provider capability routing and model configuration.
- Verify checkpoint progression and sync cursor ordering when running incremental jobs.
Transform/Migration Common Signatures
- Selected count near zero in dry-run usually indicates filter constraints are too narrow.
- Update counts diverge from selected counts when provider or storage writes are failing.
Escalation Data To Capture
- Exact request payload.
- Retrieval path and fallback reason.
- Validation and parser error text.
- Relevant crate versions and commit sha.
- Environment profile and runtime mode used during failure.
Rollback Triggers
Initiate rollback when any of the following occur:
- Client-visible contract mismatch appears in migrated host routes.
- Error rate or latency breaches remain sustained after initial mitigation window.
- Parser or validator strict failures correlate with the latest release.
Escalation Bundle Template
Capture the following in one incident record:
- Failing command and timestamp.
- Environment profile: local, CI, staging, or production.
- Request payload and redacted response sample.
- retrieval_path or transform result counters.
- Recent change references and suspected blast radius.
This bundle enables rapid handoff across development, platform, and on-call teams.
Versioning and Compatibility
Scope
This policy defines versioning expectations for Locus crates and host integrations.
It also defines dependency governance requirements used to keep releases stable over time.
Package Versioning
- locus-core-rs and locus-sdk use SemVer.
- Pre-1.0 versions may evolve rapidly but should still document behavior changes clearly.
- Breaking changes require explicit migration notes in release documentation.
Compatibility Rules
- SDK should remain additive where possible.
- Core model changes should preserve parse/load compatibility for legacy node rows.
- Host integrations should keep external endpoint/tool contracts stable during internal rewires.
- Deprecated contract paths should remain available for at least one release cycle unless security or correctness requires immediate removal.
Release Channels
- Patch: bug fixes, non-breaking behavior corrections, docs-only changes.
- Minor: additive APIs, new optional workflows, new integration hooks.
- Major: intentional API/contract breaks with migration guide.
Migration Guarantees
- Every breaking change requires a migration section with before/after payload examples.
- Behavior changes in retrieval or fallback policy must include validation evidence and parity notes.
- Parser and validator contract shifts must include strict-profile regression tests.
Version Alignment
- Workspace releases should keep crate versions intentionally aligned when shipped together.
- If independent crate version bumps are required, release notes must explain compatibility implications.
Dependency Governance
Dependency Update Cadence
- Security updates: prioritized and released on an expedited path.
- Patch and minor dependency updates: batched on regular release cadence.
- Major dependency updates: planned with explicit compatibility validation and rollback criteria.
Dependency Change Controls
- Dependency changes must include rationale and impact scope in release notes.
- Runtime-facing dependencies require integration smoke checks before release.
- Changes affecting transport, storage, or crypto behavior require targeted regression coverage.
Security Patch Handling
- Vulnerabilities with active exposure are patched on the nearest release path.
- Mitigations and operational impact are documented with the release.
- Consumers receive upgrade guidance when patch behavior changes are observable.
Compatibility Validation for Dependency Changes
- Workspace compile and tests must pass.
- Host runtime smoke checks must pass for MCP and gateway.
- SDK example workflows must pass for reference integration patterns.
- Generated technical docs must build without warnings requiring manual interpretation.
SemVer Range Management Policy
- Internal workspace crate dependencies should use intentionally aligned versions at release time.
- External dependencies should avoid overly broad ranges that mask breaking behavior.
- Major version upgrades require explicit compatibility notes and rollout strategy.
- Lockfile and resolved-version deltas should be reviewed with dependency change rationale.
Security and Data Handling
Security Posture
Locus is a memory implementation layer and may process sensitive conversational state. Treat all stored node content as potentially sensitive.
Data Classification Guidance
- Treat raw node text and content layer fields as confidential by default.
- Treat session identifiers and tenant identifiers as sensitive metadata.
- Treat provider credentials and endpoint secrets as secrets at all times.
Secret Management
- Never commit credentials, tokens, or endpoint secrets to source control.
- Use environment variables or secret managers for runtime configuration.
- Rotate credentials on incident response or role changes.
PII and Sensitive Content
- Avoid storing direct PII when not required for product behavior.
- Apply redaction/minimization before persistence where possible.
- Ensure logs do not include raw secrets or unredacted sensitive payloads.
Transport and Storage Controls
- Use TLS-enabled transports for remote database and provider calls.
- Restrict database access using least privilege credentials.
- Scope operations by tenant/session to avoid cross-tenant data leakage.
Operational Security Checklist
- Validate dependency updates and lockfile changes during review.
- Run parser/validator tests to avoid unsafe ingestion regressions.
- Audit error paths for accidental raw payload leakage.
- Keep incident response runbooks updated with containment steps.
Incident Handling Baseline
- Contain by rotating keys and restricting affected endpoints.
- Identify scope using session/tenant trace data.
- Patch and verify with deterministic replay payloads.
- Document remediation and prevention actions in release notes.
STTP Typed IR Language Specification
Formal Contract for Cognitive State Transfer
Status: Current Version: 1.1.0 Last Updated: 2026-04-25
1. Purpose and Position
STTP defines a typed intermediate representation for cognition state transfer between agents.
This specification defines:
- the language surface,
- the structural and semantic contract,
- conformance profiles,
- security and verification obligations.
This specification does not define:
- storage backend implementation details,
- sync authority policy,
- retrieval ranking policy.
2. Normative Keywords
Keywords have normative meaning:
- MUST and MUST NOT indicate mandatory requirements.
- SHOULD and SHOULD NOT indicate strong recommendations.
- MAY indicates optional behavior.
3. Conceptual Model
An STTP node is a four-layer typed artifact with ordered semantics.
Required semantic order:
- Provenance: orientation and transmission contract.
- Envelope: temporal identity and dual actor state.
- Content: compressed meaning with confidence typing.
- Metrics: quality and compression state verification.
Layer order is part of meaning. Reordering alters interpretation and invalidates strict conformance.
4. Structural Symbols
Reserved protocol symbols:
- Node marker: ⏣
- Provenance marker: ⊕⟨
- Envelope marker: ⦿⟨
- Content marker: ◈⟨
- Metrics marker: ⍉⟨
- Layer stop marker: ⟩
Implementations MUST treat these tokens as structural control symbols when encountered in structural positions.
5. Lexical Domain
5.1 Required Token Classes
A conforming lexer MUST recognize:
- protocol markers,
- braces, brackets, and parentheses,
- delimiters,
- identifiers,
- numeric literals,
- string literals,
- boolean and null literals.
5.2 Identifiers
Canonical identifier regex:
- [A-Za-z_][A-Za-z0-9_]*
5.3 Scalars and Containers
Scalar values:
- String
- Number
- Boolean
- Null
Container values:
- Object
- Array
6. Grammar Skeleton
The following grammar is normative at the layer level.
Node := ProvenanceLayer EnvelopeLayer ContentLayer MetricsLayer
ProvenanceLayer := PROVENANCE_START NodeObject LAYER_END
EnvelopeLayer := ENVELOPE_START NodeObject LAYER_END
ContentLayer := CONTENT_START NodeObject LAYER_END
MetricsLayer := METRICS_START NodeObject LAYER_END
NodeObject := OptionalNodeMarker Object
OptionalNodeMarker := NODE_MARKER [NodeOrdinal]
NodeOrdinal := Integer
Object := '{' Members? '}'
Members := Pair (',' Pair)*
Pair := Key ':' Value
Key := Identifier | String
Value := Object | Array | String | Number | Boolean | Null
Array := '[' (Value (',' Value)*)? ']'
Note:
- legacy compact separators are non-canonical and profile-scoped to tolerant mode.
7. Layer Schema Contract
7.1 Provenance Layer
Required keys:
- trigger
- response_format
- origin_session
- compression_depth
- parent_node
- prime
trigger enum:
- scheduled
- threshold
- resonance
- seed
- manual
response_format enum:
- temporal_node
- natural_language
- hybrid
prime required keys:
- attractor_config
- context_summary
- relevant_tier
- retrieval_budget
attractor_config required keys:
- stability
- friction
- logic
- autonomy
7.2 Envelope Layer
Required keys:
- timestamp
- tier
- session_id
- user_avec
- model_avec
Optional keys:
- schema_version
tier enum:
- raw
- daily
- weekly
- monthly
- quarterly
- yearly
AVEC required keys:
- stability
- friction
- logic
- autonomy
- psi
7.3 Content Layer
Required shape:
- typed object containing one or more semantic fields.
Canonical field signature:
- field_name(.confidence): value
confidence rules:
- confidence MUST parse as float.
- strict range is [0.0, 1.0].
depth rule:
- strict maximum nesting depth is 5.
7.4 Metrics Layer
Required keys:
- rho
- kappa
- psi
- compression_avec
compression_avec required keys:
- stability
- friction
- logic
- autonomy
- psi
8. Semantic Invariants
Strict conformance requires all invariants below.
S1 Layer order invariant:
- provenance precedes envelope.
- envelope precedes content.
- content precedes metrics.
S2 Completeness invariant:
- all required keys exist in all required layers.
S3 Type invariant:
- enum values are members of defined enum sets.
- required numeric fields parse as numeric values.
S4 Confidence invariant:
- every canonical content field includes confidence annotation.
- every confidence annotation is range-valid in strict mode.
S5 Structural depth invariant:
- content object nesting depth is less than or equal to 5.
A node that violates any invariant MUST be marked strict-invalid.
9. Compliance Profiles
9.1 Strict Profile
Strict profile MUST:
- enforce all syntax and invariants,
- fail closed on unresolved structure,
- reject non-canonical legacy forms.
9.2 Tolerant Profile
Tolerant profile MAY accept legacy forms including:
- compact pipe-delimited key-value payloads,
- omitted internal node wrappers,
- unquoted enum-like values where unambiguous,
- mixed formatting and spacing variants.
Tolerant profile MUST:
- preserve raw source,
- emit diagnostics for every deviation,
- produce canonical AST when recoverable,
- never claim strict-valid unless strict invariants pass.
10. Diagnostics Specification
Recommended severities:
- Fatal
- Error
- Warning
- Info
Diagnostic payload SHOULD include:
- code,
- message,
- source span,
- recovery action,
- strict impact.
11. Canonicalization Rules
When tolerant recovery is used, implementation SHOULD canonicalize:
- layer ordering in AST output,
- known aliases into canonical keys,
- parent_node into normalized representation,
- unambiguous numeric strings into numeric values.
Canonicalization MUST NOT:
- modify original raw text,
- alter identity-sensitive semantics,
- fabricate missing semantic values.
12. Adversarial and Security Considerations
Threat classes:
- marker spoofing and layer confusion,
- malformed confidence signatures,
- delimiter smuggling in compact forms,
- layer bleed-through via unbalanced containers.
Required response:
- strict profile fails closed,
- tolerant profile fails informative with bounded recovery,
- diagnostics remain deterministic for equal input.
13. Backward Compatibility Contract
Language evolution policy is additive.
Rules:
- optional fields MAY be introduced without invalidating old nodes.
- old nodes MAY be ingested via tolerant profile.
- strict profile remains the canonical generation target.
14. Conformance Testing Requirements
A conformance suite SHOULD include:
- strict canonical fixtures,
- tolerant legacy fixtures,
- negative fixtures by invariant class,
- adversarial fixtures by threat class,
- canonical AST snapshot expectations.
15. Canonical Example
⊕⟨ ⏣0{ trigger: manual, response_format: temporal_node, origin_session: "session-abc", compression_depth: 1, parent_node: null, prime: { attractor_config: { stability: 0.90, friction: 0.20, logic: 0.98, autonomy: 0.85 }, context_summary: "parser hardening session", relevant_tier: raw, retrieval_budget: 8 } } ⟩
⦿⟨ ⏣0{ timestamp: "2026-04-25T00:00:00Z", tier: raw, session_id: "session-abc", schema_version: "sttp-1.0", user_avec: { stability: 0.90, friction: 0.20, logic: 0.98, autonomy: 0.85, psi: 2.93 }, model_avec: { stability: 0.90, friction: 0.20, logic: 0.98, autonomy: 0.85, psi: 2.93 } } ⟩
◈⟨ ⏣0{ focus(.99): "grammar update", decision(.96): { parser_mode(.95): "strict_and_tolerant" } } ⟩
⍉⟨ ⏣0{ rho: 0.95, kappa: 0.94, psi: 2.93, compression_avec: { stability: 0.90, friction: 0.20, logic: 0.98, autonomy: 0.85, psi: 2.93 } } ⟩
16. Change Control
When schema or grammar rules change, maintainers SHOULD update:
- this language specification,
- sttp_grammar_blueprint.md,
- parser conformance fixtures,
- parser implementation notes.
17. Language Promise
STTP as typed IR is complete only when it can do all three simultaneously:
- represent cognition state faithfully,
- validate structure deterministically,
- survive historical reality without semantic drift.