Skip to main content

Overview

A context defines the execution environment for a flow—memory scope, reasoning depth, model parameters, and language preferences. While personas define “who” executes a flow, contexts define “how” it’s executed.

Syntax

context <Name> {
  memory: <scope>
  language: <string>
  depth: <level>
  max_tokens: <integer>
  temperature: <float>
  cite_sources: <boolean>
}

Fields

memory (optional)

Type: One of session, persistent, none, ephemeral Defines the memory scope for the execution.
context LongTermContext {
  memory: persistent    // Memory persists across sessions
}

context OneOffTask {
  memory: none         // No memory retention
}

context ChatSession {
  memory: session      // Memory lasts for the session
}

context TemporaryWork {
  memory: ephemeral    // Short-lived memory
}
Memory Scopes:
ScopeLifetimeUse Case
noneNo memoryStateless operations, one-off queries
ephemeralSingle flow executionTemporary working memory
sessionCurrent session/conversationChat contexts, iterative tasks
persistentAcross sessionsLong-term knowledge, user preferences

language (optional)

Type: String (ISO language code) Preferred language for the execution context.
context EnglishContext {
  language: "en"
}

context SpanishReview {
  language: "es"
  depth: exhaustive
}

depth (optional)

Type: One of shallow, standard, deep, exhaustive Defines the reasoning depth and thoroughness of analysis.
context QuickScan {
  depth: shallow       // Fast, surface-level
}

context StandardReview {
  depth: standard      // Balanced depth
}

context DetailedAnalysis {
  depth: deep          // Thorough investigation
}

context ComprehensiveAudit {
  depth: exhaustive    // Maximum detail
}
Depth Levels:
LevelCharacteristicsTypical Use
shallowFast, high-level overviewQuick summaries, previews
standardBalanced depth and speedGeneral purpose tasks
deepThorough, detailed analysisComplex reasoning, research
exhaustiveMaximum detail, multi-passLegal review, critical analysis

max_tokens (optional)

Type: Integer (must be positive) Maximum number of tokens for the model’s response.
context BriefResponses {
  max_tokens: 500      // Short responses
}

context StandardContext {
  max_tokens: 4096     // Typical context window
}

context ExtendedReport {
  max_tokens: 16000    // Long-form content
}
Guidelines:
  • 500-1000: Brief summaries, quick responses
  • 2000-4096: Standard tasks, moderate complexity
  • 8000-16000: Long-form reports, comprehensive analysis
  • 16000+: Extended documents, multi-part responses

temperature (optional)

Type: Float (range: 0.0 to 2.0) Controls randomness/creativity in model outputs. Lower = more deterministic, higher = more creative.
context FactualAnalysis {
  temperature: 0.0     // Deterministic, factual
}

context LegalReview {
  temperature: 0.3     // Mostly deterministic, slight variation
}

context BalancedGeneration {
  temperature: 0.7     // Balanced creativity
}

context CreativeWriting {
  temperature: 1.2     // High creativity
}
Temperature Guidelines:
RangeBehaviorUse Cases
0.0 - 0.3Highly deterministicFacts, analysis, legal, medical
0.4 - 0.7BalancedGeneral purpose, Q&A
0.8 - 1.2CreativeBrainstorming, content generation
1.3 - 2.0Highly creativeExperimental, artistic

cite_sources (optional)

Type: Boolean (default: false) Whether to require source citations in this context.
context ResearchMode {
  cite_sources: true
  depth: deep
}

context CasualChat {
  cite_sources: false
}

Complete Examples

context LegalReview {
  memory: session
  language: "en"
  depth: exhaustive
  max_tokens: 4096
  temperature: 0.3
  cite_sources: true
}
Use Case: Comprehensive legal document analysis requiring accuracy, source tracking, and thorough investigation.

Quick Summary Context

context QuickSummary {
  memory: none
  depth: shallow
  max_tokens: 500
  temperature: 0.5
}
Use Case: Fast, stateless summarization of documents.

Research Context

context AcademicResearch {
  memory: persistent
  language: "en"
  depth: deep
  max_tokens: 8000
  temperature: 0.4
  cite_sources: true
}
Use Case: Long-term research projects with citation requirements and detailed analysis.

Creative Writing Context

context CreativeMode {
  memory: session
  depth: standard
  max_tokens: 4096
  temperature: 1.0
  cite_sources: false
}
Use Case: Creative content generation with higher variability.

Production Context

context Production {
  memory: session
  language: "en"
  depth: standard
  max_tokens: 4096
  temperature: 0.5
}
Use Case: Balanced production environment for general tasks.

Usage with Run Statements

Contexts are activated using the within modifier:
context AnalysisContext {
  depth: deep
  temperature: 0.3
}

flow AnalyzeDocument(doc: Document) -> Report { ... }

run AnalyzeDocument(myDoc)
  as Analyst
  within AnalysisContext    // Execute in this context

Best Practices

1. Match Context to Task Criticality

High-stakes tasks need stricter contexts:
// High-stakes: legal, medical, financial
context CriticalAnalysis {
  depth: exhaustive
  temperature: 0.2
  cite_sources: true
}

// Low-stakes: brainstorming, drafts
context ExploratoryMode {
  depth: standard
  temperature: 0.8
  cite_sources: false
}

2. Memory Scope Tradeoffs

// Persistent: for user-specific knowledge
context UserProfile {
  memory: persistent
  // Remember user preferences, history
}

// Session: for conversation context
context Conversation {
  memory: session
  // Remember within chat, forget after
}

// None: for stateless operations
context StatelessAPI {
  memory: none
  // No state, pure function
}

3. Temperature for Determinism

Lower temperature for consistency:
// Need reproducibility? Use low temperature
context DataAnalysis {
  temperature: 0.1  // Nearly deterministic
  depth: deep
}

// Need variety? Use higher temperature
context ContentIdeas {
  temperature: 1.0  // More creative variation
}

4. Token Budgets

Set appropriate token limits:
context APIEndpoint {
  max_tokens: 1000   // Keep responses concise for APIs
  temperature: 0.5
}

context ReportGeneration {
  max_tokens: 8000   // Allow detailed reports
  depth: deep
}

5. Combine with Personas

Contexts and personas work together:
persona LegalExpert {
  domain: ["contract law"]
  tone: precise
}

context LegalReview {
  depth: exhaustive
  temperature: 0.3
  cite_sources: true
}

run AnalyzeContract(doc)
  as LegalExpert        // Who
  within LegalReview    // How

Common Patterns

Development vs. Production

context Development {
  depth: shallow
  max_tokens: 1000
  temperature: 0.7
}

context Production {
  depth: deep
  max_tokens: 4096
  temperature: 0.5
  cite_sources: true
}

// Switch contexts based on environment
run MyFlow(data)
  as MyPersona
  within Production  // or Development

Multi-Language Support

context EnglishContext {
  language: "en"
  depth: standard
}

context SpanishContext {
  language: "es"
  depth: standard
}

context FrenchContext {
  language: "fr"
  depth: standard
}

Tiered Analysis Depths

context QuickPass {
  depth: shallow
  max_tokens: 1000
}

context StandardPass {
  depth: standard
  max_tokens: 4096
}

context DetailedPass {
  depth: deep
  max_tokens: 8000
}

context ComprehensivePass {
  depth: exhaustive
  max_tokens: 16000
  cite_sources: true
}

// Run multiple passes with increasing depth
run FirstPass(doc) within QuickPass
run SecondPass(doc) within DetailedPass

Type Checking

The AXON type checker validates: Memory scope: Must be one of the valid scopes
Depth level: Must be one of the valid depth levels
Temperature range: Must be between 0.0 and 2.0
Max tokens: Must be positive
Context references: Referenced contexts must exist
context Invalid {
  memory: unlimited           // ❌ Error: unknown memory scope
  depth: superficial          // ❌ Error: unknown depth level
  temperature: 3.0            // ❌ Error: out of range
  max_tokens: -100            // ❌ Error: must be positive
}

run MyFlow(data) within UnknownContext  // ❌ Error: undefined context

Performance Considerations

Depth vs. Speed

// Fast but shallow
context QuickMode {
  depth: shallow
  max_tokens: 500
}

// Slow but thorough
context ThoroughMode {
  depth: exhaustive
  max_tokens: 16000
}

Memory vs. Privacy

// Better personalization, but stores data
context Personalized {
  memory: persistent
}

// Privacy-first, no retention
context Private {
  memory: none
}
  • Persona — Define agent identities
  • Memory — Configure semantic memory stores
  • Flow — Build cognitive pipelines
  • Anchor — Set hard constraints

Build docs developers (and LLMs) love