Syntax Overview
Syntax Overview
Section titled “Syntax Overview”CTX (Context Language) is a structured query language designed for AI agents, not humans. Every statement follows a consistent pattern that agents can parse, generate, and reason about with minimal tokens.
Statement Structure
Section titled “Statement Structure”STATEMENT = OPERATOR PLANE[:VERB] TARGET [FILTERS] [PAYLOAD]| Component | Required | Description |
|---|---|---|
| Operator | ✅ | What to do (? search, > call, + store, etc.) |
| Plane | ✅ | Where to do it (t tools, k knowledge, m memory, s skills, a agents, i inspection, l llm) |
| Verb | ❌ | Pipeline action (:clarify, :handoff, :escalate, etc.) |
| Target | ❌ | What to operate on (tool name, search query, memory key) |
| Filters | ❌ | Constraints (#tag, @7d, ^3, *project, &json) |
| Payload | ❌ | Additional data (key=value pairs or quoted strings) |
Quick Examples
Section titled “Quick Examples”?k "auth" #code @7d ^3│ │ │ │ │ └── limit: return 3 results│ │ │ │ └────── time: last 7 days│ │ │ └─────────── tag: "code"│ │ └────────────────── target: search for "auth"│ └───────────────────── plane: knowledge└─────────────────────── operator: search
>t github.issues.create title="Fix SSE" ^5│ │ │ ││ │ │ └── payload: key=value pairs│ │ └────────────────────── target: tool name│ └──────────────────────── plane: tools└────────────────────────── operator: call
+m auth-decision #arch "JWT for API, session tokens for WS"│ │ │ │ ││ │ │ │ └── payload: quoted description│ │ │ └──────── tag: "arch"│ │ └────────────────────── target: memory key│ └──────────────────────── plane: memory└────────────────────────── operator: storeSeven Operators
Section titled “Seven Operators”| Symbol | Name | Purpose |
|---|---|---|
? | search | Semantic search or discovery |
! | lookup | Exact lookup by ID or name |
> | call | Execute a tool or skill |
+ | store | Create or write data |
~ | update | Modify existing data |
- | delete | Remove data |
^ | delegate | Delegate to another agent |
Seven Planes
Section titled “Seven Planes”| Symbol | Name | Purpose |
|---|---|---|
t | tools | MCP tool discovery, inspection, and execution |
k | knowledge | Semantic search across ingested documents |
m | memory | 5-layer persistent memory with decay and consensus |
s | skills | Reusable agent workflows and capabilities |
a | agents | Agent discovery, delegation, and communication |
i | inspection | Runtime introspection of the CTX system itself |
l | llm | Direct LLM inference and embedding |
Operator × Plane Validity Matrix
Section titled “Operator × Plane Validity Matrix”Not every operator works on every plane. Invalid combinations are rejected at parse time with a typed error code (INVALID_OP_PLANE).
k knowledge | t tools | m memory | s skills | a agents | i inspection | l llm | |
|---|---|---|---|---|---|---|---|
? search | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
! lookup | ✅ | ✅ | ✅ | ✅ | ✅ | — | — |
> call | — | ✅ | — | ✅ | — | — | ✅ |
+ store | ✅ | ✅ | ✅ | ✅ | — | ✅ | — |
~ update | ✅ | ✅ | ✅ | ✅ | — | — | — |
- delete | ✅ | ✅ | ✅ | ✅ | ✅ | — | — |
^ delegate | — | — | — | — | ✅ | — | — |
Key constraints:
>kand>mare blocked — data planes aren’t callable^(delegate) only works on thea(agents) plane+iallows writing inspection data;?iallows querying it
Targets
Section titled “Targets”Targets identify what the operation acts on. They can be:
Quoted strings — for search queries:
?k "mesh decimation algorithm"Dotted identifiers — for tool names:
>t github.issues.create!t godot.assets.decimate_meshSimple identifiers — for memory keys:
+m auth-decision-m dragon-pipelinePayloads
Section titled “Payloads”Payloads provide additional data. Two formats:
Key-value pairs — for tool arguments:
>t github.issues.create title="Fix SSE" state="open"Quoted strings — for descriptions or content:
+m auth-decision #arch "JWT for API, session tokens for WebSocket"Parsing
Section titled “Parsing”The CTX parser (CTXParser) converts raw text into a typed AST (CTXStatement):
import { CTXParser } from '@agentctx/core';
const parser = new CTXParser();const stmt = parser.parse('?k "mesh decimation" #pipeline @7d ^3');
// Result:// {// operator: "?",// plane: "k",// target: "mesh decimation",// filters: [// { type: "tag", value: "pipeline" },// { type: "time", value: "7d" },// { type: "limit", value: "3" }// ],// raw: "?k \"mesh decimation\" #pipeline @7d ^3"// }Multi-Statement Parsing
Section titled “Multi-Statement Parsing”Parse multiple newline-separated statements (comments supported):
const stmts = parser.parseMulti(` // Discover and call a tool ?t github.assets >t github.issues.list state="open" ^5`);// Returns: CTXStatement[]- Operators & Planes → — deep dive into each operator and plane
- Filters → — tag, time, limit, project, format, and more
- Pipeline Verbs → — ISA verbs for multi-step workflows