CognitiveMode
The autonomous control loop that orchestrates task execution, manages reasoning state, and defines the agent's problem-solving persona.
Core Architecture
Stateful
Strategy Engine
⚙️ OrchestrationConfig.json
{
"mode": "AdaptivePlanningMode",
"schema_strategy": "ScientificMethod",
"auto_fix": true,
"model_config": {
"smart": "gpt-4-turbo",
"fast": "gpt-3.5-turbo"
}
}
→
🧠 Live Transcript
State: Hypothesis Testing
graph TD
A[Analyze Error] --> B{Hypothesis?}
B -->|Network| C[Check DNS]
B -->|Code| D[Run Linter]
C --> E[Refute Hypothesis]
E --> A
A[Analyze Error] --> B{Hypothesis?}
B -->|Network| C[Check DNS]
B -->|Code| D[Run Linter]
C --> E[Refute Hypothesis]
E --> A
Thinking: Network checks passed. Switching strategy to Code Analysis.
Executing: RunCodeTask...
Architectural Patterns
| Mode Name | Architecture | Best Use Case |
|---|---|---|
| WaterfallMode | Plan -> Review -> Execute |
Well-defined problems where the user must approve the entire roadmap before execution begins. |
| ConversationalMode | Listen -> Act -> Reply |
Interactive debugging, exploratory sessions, or simple "Chat with Code" workflows. |
| AdaptivePlanningMode | Loop(Think -> Act -> Reflect) |
Complex, ambiguous goals requiring research, trial-and-error, and self-correction. |
| HierarchicalPlanningMode | Tree(Decompose -> Delegate) |
Massive projects. Breaks goals into sub-goals and spawns sub-tasks to handle them. |
Reasoning Personas
Strategies define the internal state structure and the "thinking style" injected into the Mode's loop.
| Strategy | Internal State | Reasoning Style |
|---|---|---|
| Project Manager | ReasoningState |
Generalist. Tracks short-term vs. long-term goals and manages a task queue. |
| Scientific Method | ScientificState |
Debugger. Formulates hypotheses, tracks facts, and attempts to falsify theories. |
| Agile Developer | AgileState |
Coder. Follows a TDD loop: Test Failing -> Implementing -> Refactoring. |
| Critical Auditor | AuditState |
Security. Adversarial mindset designed to find flaws rather than fix them. |
| Creative Writer | NarrativeState |
Author. Manages themes, outlines, and tone for long-form content generation. |
Custom Mode Skeleton
class MyCustomMode(val config: OrchestrationConfig) {
fun run(task: SessionTask, userPrompt: String, availableTasks: List) {
// 1. Initialize Strategy (The "Brain")
val strategy = CognitiveSchemaStrategy.ScientificMethod
var state = strategy.initialize(userPrompt, emptyList(), config, task, describer)
// 2. Execution Loop
while (!isComplete(state)) {
// A. Get Guidance
val guidance = strategy.getTaskSelectionGuidance(state)
// B. Select & Execute Task
val tool = availableTasks.first { it.canHandle(guidance) }
val result = tool.execute(task, guidance, config)
// C. Update State (Reflection)
state = strategy.update(state, listOf(result), null, emptyList(), config, task, describer)
// D. Observability
task.transcript().write("## Step Complete: ${strategy.formatState(state)}".toByteArray())
}
}
}
Integration Guide
Configuration
Reference the mode and strategy in your OrchestrationConfig.
val config = OrchestrationConfig(
mode = CognitiveMode.AdaptivePlanningMode,
overrides = mapOf(
"schema_strategy" to "AgileDeveloper"
),
autoFix = true
)
Observability Standards
- Mermaid Diagrams: Visualize the state machine in the transcript for user transparency.
- Collapsed Details: Use
<details>tags for raw JSON state dumps to keep the UI clean. - Graceful Degradation: If the LLM hallucinates, the mode must catch the error and attempt to simplify the prompt.