| name | opendev-coding-agents |
| title | Building AI Coding Agents for the Terminal |
| version | 0.0.2 |
| engine | skillxiv-v0.0.2-claude-opus-4.6 |
| license | MIT |
| url | https://arxiv.org/abs/2603.05344 |
| keywords | ["Agent Systems","Coding","Tool Use","Context Management","Compound AI"] |
| description | Designs terminal-based AI coding agents through workload-specialized model routing, where distinct models handle planning, thinking, critique, and execution tasks. Implements extended ReAct loop with context compaction and approval gates for safe command execution. |
Building AI Coding Agents for the Terminal: Compound Model Architecture and Context Management
Terminal-based AI coding agents must overcome three challenges: managing context across sessions exceeding token budgets, preventing destructive operations when executing arbitrary shell commands, and extending capabilities without prompt bloat. OpenDev solves these through a compound AI architecture: rather than a single LLM, use specialized model routing where each cognitive task (planning, thinking, critique, execution) binds to potentially different models.
Core Concept
Instead of one LLM handling everything, decompose into five specialized roles:
- Planner: Strategy and high-level reasoning
- Thinker: Chain-of-thought analysis when stuck
- Critic: Verification and reflection
- Executor: Tool calling and command generation
- Vision: Image/screenshot understanding
Each role independently configured, lazily initialized, and optimized for its workload. This enables cost, latency, and capability optimization per task. A complex reasoning step uses an expensive model; a simple command uses a fast model.
Architecture Overview
- Workload-Specialized Routing: Router dispatches tasks to appropriate models
- Extended ReAct Cycle: Pre-check, thinking, critique, action, execution, post-processing
- Context Engineering: Compaction, event-driven reminders, dual memory (episodic + working)
- Safety Gates: Approval checks for destructive operations
- Lazy Initialization: Models loaded only when needed
- Token Budget Management: Adaptive message drainage and older observation reduction
Implementation Steps
Implement a compound AI agent system with specialized model routing and extended ReAct execution.
Model Router and Lazy Loading
import torch
from typing import Dict, Optional, Any
from dataclasses import dataclass
@dataclass
class ModelConfig:
name:
task:
model_id:
max_tokens:
temperature:
cost_per_1k_tokens:
latency_ms_estimate:
:
():
.models: [, ] = {}
.model_configs = {
: ModelConfig(
name=,
task=,
model_id=,
max_tokens=,
temperature=,
cost_per_1k_tokens=,
latency_ms_estimate=
),
: ModelConfig(
name=,
task=,
model_id=,
max_tokens=,
temperature=,
cost_per_1k_tokens=,
latency_ms_estimate=
),
: ModelConfig(
name=,
task=,
model_id=,
max_tokens=,
temperature=,
cost_per_1k_tokens=,
latency_ms_estimate=
),
: ModelConfig(
name=,
task=,
model_id=,
max_tokens=,
temperature=,
cost_per_1k_tokens=,
latency_ms_estimate=
),
: ModelConfig(
name=,
task=,
model_id=,
max_tokens=,
temperature=,
cost_per_1k_tokens=,
latency_ms_estimate=
)
}
.loaded_models = ()
():
task .model_configs:
ValueError()
config = .model_configs[task]
config.name .loaded_models:
.models[config.name] = ._load_model(config)
.loaded_models.add(config.name)
.models[config.name], config
():
()
() -> :
model, config = .get_model(task_type)
system_prompts = {
: ,
: ,
: ,
: ,
:
}
response = ._invoke_model(
model,
system_prompts.get(task_type, ),
prompt,
max_tokens=config.max_tokens,
temperature=config.temperature
)
response
():