CodingMode
The dynamic execution engine that turns reasoning into executable scripts. It orchestrates tasks through a programmable control loop, allowing for complex logic, state management, and tool manipulation.
{
"mode": "CodingMode",
"config": {
"codeRuntime": "GroovyRuntime"
},
"auto_fix": true,
"model_config": {
"smart": "gpt-4-turbo"
}
}
def result = FileModificationTask.call([
target_file: "src/App.kt",
instructions: "Add logging"
], "Updating main loop")
println "Task Result: " + result
Task Result: ✔ File Updated Successfully
The Execution Loop
Unlike static planning modes, CodingMode operates by generating and executing code in real-time. This allows the agent to use standard programming constructs (loops, conditionals, try-catch) to handle task results.
| Phase | Description |
|---|---|
| Planning | The CodeAgent analyzes the user prompt and history to generate a script. |
| Injection | Cognotik tasks are mapped to functions and injected into the runtime environment. |
| Execution | The script runs via CodeRuntimes (e.g., Groovy), capturing stdout and return values. |
| Reflection | Results are added to the conversation history, allowing the agent to iterate if errors occur. |
Runtime Environment
The following symbols are automatically available within the generated scripts:
- [TaskName] - Every configured task is available as a callable function.
- workingDir - The absolute path to the current workspace.
- smartModel / fastModel - Direct access to LLM clients for sub-reasoning.
- task - The current
SessionTaskobject for UI manipulation.
Kotlin Implementation Skeleton
The core logic from CodingMode.kt handles the bridge between the LLM and the local runtime.
// From CodingMode.kt
override fun handleUserMessage(userMessage: String, task: SessionTask) {
val response = plan(task) // Generates CodeAgent.CodeResult
val tabs = TabbedDisplay(task)
tabs["Code"] = renderMarkdown("```groovy\n${response.code}\n```")
// Execute code and capture output/value
val executionResult = response.result
output(executionResult, tabs, transcript, response)
}
Integration Guide
To use CodingMode in your application, define it in your OrchestrationConfig. This mode is ideal for complex engineering tasks where the agent needs to verify its own work.
val config = OrchestrationConfig(
mode = CognitiveModeType.Coding,
config = CodingMode.CodingModeConfig(
codeRuntime = CodeRuntimes.GroovyRuntime
),
autoFix = true // Allows the agent to loop on execution errors
)