Skip to content

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 = OPERATOR PLANE[:VERB] TARGET [FILTERS] [PAYLOAD]
ComponentRequiredDescription
OperatorWhat to do (? search, > call, + store, etc.)
PlaneWhere to do it (t tools, k knowledge, m memory, s skills, a agents, i inspection, l llm)
VerbPipeline action (:clarify, :handoff, :escalate, etc.)
TargetWhat to operate on (tool name, search query, memory key)
FiltersConstraints (#tag, @7d, ^3, *project, &json)
PayloadAdditional data (key=value pairs or quoted strings)
?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: store
SymbolNamePurpose
?searchSemantic search or discovery
!lookupExact lookup by ID or name
>callExecute a tool or skill
+storeCreate or write data
~updateModify existing data
-deleteRemove data
^delegateDelegate to another agent
SymbolNamePurpose
ttoolsMCP tool discovery, inspection, and execution
kknowledgeSemantic search across ingested documents
mmemory5-layer persistent memory with decay and consensus
sskillsReusable agent workflows and capabilities
aagentsAgent discovery, delegation, and communication
iinspectionRuntime introspection of the CTX system itself
lllmDirect LLM inference and embedding

Not every operator works on every plane. Invalid combinations are rejected at parse time with a typed error code (INVALID_OP_PLANE).

k knowledget toolsm memorys skillsa agentsi inspectionl llm
? search
! lookup
> call
+ store
~ update
- delete
^ delegate

Key constraints:

  • >k and >m are blocked — data planes aren’t callable
  • ^ (delegate) only works on the a (agents) plane
  • +i allows writing inspection data; ?i allows querying it

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_mesh

Simple identifiers — for memory keys:

+m auth-decision
-m dragon-pipeline

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"

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"
// }

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[]