Skip to main content

Module context_template

Module context_template 

Source
Expand description

Context template models.

Provides data structures for user-defined context templates that format memories and statistics for hooks and MCP tool responses.

§Variable Types

Context templates support two types of variables:

  1. Auto-variables: Automatically populated from memory context

    • {{memories}} - List of memories for iteration
    • {{memory.id}}, {{memory.content}}, etc. - Individual memory fields (in iteration)
    • {{statistics}} - Memory statistics object
    • {{total_count}}, {{namespace_counts}} - Statistics fields
  2. User-variables: Custom variables provided at render time

    • Any {{variable}} not in the auto-variable list

§Iteration Syntax

Templates support iteration over collections using {{#each}}...{{/each}}:

{{#each memories}}
- **{{memory.namespace}}**: {{memory.content}}
{{/each}}

Structs§

ContextTemplate
A user-defined context template.
TemplateVariable
A variable in a context template.
TemplateVersion
Version metadata for a context template.

Enums§

OutputFormat
Output format for rendered templates.
VariableType
Type of template variable.

Constants§

AUTO_VARIABLES
Auto-variable names recognized by the system.
AUTO_VARIABLE_PREFIXES
Auto-variable prefixes for iteration context.

Functions§

default_required 🔒
Default value for required field (true for user variables, false for auto).
default_version 🔒
Default version number.
is_auto_variable
Checks if a variable name is an auto-variable.