Context stacks provide reproducible, structured prompts for LLM interactions. In v0.3.20, SPINE executors can load context stacks from YAML scenario files for consistent prompt building.
┌─────────────────────────────────────────────────────────────┐
│ Context Stack │
├─────────────────────────────────────────────────────────────┤
│ global │ operator, brand identity │
│ character │ speaker persona, target audience │
│ command │ task specification, success criteria │
│ constraints │ tone, format, do/don't rules │
│ context │ background info, references │
│ input │ user request │
└─────────────────────────────────────────────────────────────┘
Scenario files are YAML configurations that define context stacks:
# scenarios/research.yaml
name: "Research Task"
description: "Context stack for research-focused tasks"
context_stack:
global:
operator: "AdaptiveArts.ai"
brand: "Technical Research Initiative"
character:
speaker: "Senior Research Analyst"
audience: "Technical stakeholders"
command:
task: "Conduct comprehensive research on the given topic"
success: |
- All sources verified and cited
- Key findings synthesized
- Recommendations provided
constraints:
tone: "Professional, analytical"
format: "Structured report with sections"
do:
- "Cite all sources"
- "Identify contradictions"
- "Provide actionable insights"
dont:
- "Make unsupported claims"
- "Skip source verification"
context:
background: "Research conducted for strategic planning"
references:
- "Company knowledge base"
- "Industry reports"
# Use a specific scenario for all tasks
python -m spine.orchestrator run --project /path \
--executor subagent \
--scenario scenarios/research.yaml
# Role-specific scenarios
python -m spine.orchestrator run --project /path \
--executor claude-code \
--role-scenario "architect:scenarios/architecture.yaml" \
--role-scenario "reviewer:scenarios/code-review.yaml" \
--role-scenario "implementer:scenarios/coding.yaml"
# Disable context stacks (use legacy prompts)
python -m spine.orchestrator run --project /path \
--executor subagent \
--no-context-stacks
from spine.orchestrator.context_stack import (
ContextStack,
load_context_stack,
get_default_scenario,
)
# Load from YAML file
stack = load_context_stack("scenarios/research.yaml")
# Add task-specific context
stack = stack.with_task_context(
task_title="Analyze competitor landscape",
task_description="Research top 5 competitors in the AI space",
role="researcher",
task_id="task-001",
)
# Build prompts
system_prompt = stack.build_system_prompt()
user_prompt = stack.build_user_prompt("Focus on pricing strategies")
SPINE provides default scenarios for common roles:
| Role | Default Focus |
|---|---|
architect |
System design, architectural decisions |
implementer |
Code implementation, best practices |
reviewer |
Code review, quality assurance |
researcher |
Research, analysis, synthesis |
Access default scenarios:
from spine.orchestrator.context_stack import get_default_scenario
# Get default scenario for a role
scenario_path = get_default_scenario("architect")
stack = load_context_stack(scenario_path)
SPINE includes sample templates in _templates/scenarios/:
| Template | Purpose |
|---|---|
sample-research.yaml |
Research task template |
sample-code-review.yaml |
Code review template |
sample-content-generation.yaml |
Content creation template |
sample-analysis-pipeline.yaml |
Multi-step analysis template |
System-wide configuration that applies to all interactions:
global:
operator: "Company Name" # Who operates this system
brand: "Product/Initiative" # Brand identity
Defines the AI’s persona and audience:
character:
speaker: "Senior Engineer" # AI's role/persona
audience: "Development team" # Who receives the output
The core task specification:
command:
task: "What to do" # Clear task description
success: "Success criteria" # How to measure completion
Boundaries and guidelines:
constraints:
tone: "Professional" # Communication style
format: "Markdown report" # Output format
do: # Things to include
- "Cite sources"
- "Provide examples"
dont: # Things to avoid
- "Make assumptions"
- "Skip validation"
Background information:
context:
background: "Project context" # Situational info
references: # Reference materials
- "docs/architecture.md"
- "Previous analysis"
The actual user request (typically added at runtime):
input:
user_request: "Analyze the authentication module"
from spine.orchestrator.executors import SubagentExecutor, SubagentConfig
config = SubagentConfig(
agent_dir=project_path / ".claude" / "agents",
role_scenarios={
"architect": "scenarios/architecture.yaml",
"reviewer": "scenarios/code-review.yaml",
},
default_scenario="scenarios/default.yaml",
use_context_stacks=True,
)
executor = SubagentExecutor(config)
from spine.orchestrator.executors import ClaudeCodeExecutor, ClaudeCodeConfig
config = ClaudeCodeConfig(
model="opus",
role_scenarios={"researcher": "scenarios/research.yaml"},
use_context_stacks=True,
)
executor = ClaudeCodeExecutor(config)
| Benefit | Description |
|---|---|
| Reproducibility | Same scenario = same prompt structure |
| Separation | Task logic separate from prompt engineering |
| Versioning | YAML files can be version-controlled |
| Reusability | Share scenarios across projects |
| Consistency | Uniform AI behavior across tasks |
| ← Back to Docs | Executors |