ClawSergeant trains OpenClaw agents through a structured, LLM-driven pipeline. A Trainer LLM designs curriculum, generates training tasks, and adapts its teaching dynamically based on the agent's responses. A separate Evaluator LLM objectively scores each response, creating a feedback loop that drives iterative improvement.
text
User Intent ──────────────────────→ LLM (Curriculum Designer)
↓
Curriculum JSON (stages, tasks, criteria)
↓
Training Session Loop:
Trainer LLM → crafts message → openclaw CLI → Claw Agent → reply
↓
Evaluator LLM → score + feedback
↓
record to .claw_sergeant_accumulated_lessons/ ←──┘
↓
(if failed) → Trainer LLM retries with feedback
↓
(if stage passed) → stage summary for memory consolidation
↓
[Curriculum Pattern] → record to .claw_sergeant_accumulated_lessons/
The user's training intent is passed directly as input. The LLM generates a multi-stage curriculum as structured JSON based on this intent. The user reviews and approves the curriculum before training begins.
Each curriculum contains:
Title and overview of the training program
Target persona describing the ideal agent after training
3–5 stages, each with:
For each stage and task, the system runs a dialogue loop:
openclaw agent CLICreate a .env file in the project root with:
text
LLM_API_KEY=<your-api-key> # Required: API key for the LLM
LLM_BASE_URL=https://api.openai.com/v1 # Optional: OpenAI-compatible endpoint
LLM_MODEL=gpt-4o # Optional: model identifier
CLAW_RECIPIENT=+15555550123 # Required: target agent's address
bash
python main.py "An efficient, rigorous programming assistant"
The training intent is passed as a command-line argument. ClawSergeant designs a curriculum, presents it for approval, and runs the training session automatically. Results are saved to training_results.json.
Use test_phases.py to verify each component independently before running a full session:
bash
python test_phases.py 1 # Verify LLM API connectivity
python test_phases.py 2 # Test curriculum generation
python test_phases.py 3 # Test Claw agent communication
python test_phases.py 4 # Run a single-task training round
python test_phases.py all # Run all phases sequentially
Always start with phase 1 to confirm the LLM connection works, then progress through subsequent phases.
All training parameters are centralized in config.py:
ParameterDefaultPurposeSTAGE_COUNT_MIN / MAX3 / 5Number of training stagesTASKS_PER_STAGE_MIN / MAX2 / 4Tasks per stageCURRICULUM_TEMPERATURE0.4LLM temperature for curriculum designTRAINER_TEMPERATURE0.7LLM temperature for training messagesEVALUATOR_TEMPERATURE0.2LLM temperature for evaluation (low = strict)MAX_ATTEMPTS_PER_TASK2Retries per task before moving onSTAGE_PASS_THRESHOLD0.6Fraction of tasks needed to pass a stage
Adjust STAGE_PASS_THRESHOLD higher (e.g., 0.8) for stricter training, or lower temperatures for more deterministic evaluations.
FileRolemain.pyEntry point — orchestrates curriculum design → approval → training executiontrainer.pyTraining session controller — manages dialogue loop and captures per-task/stage learningscurriculum.pyCurriculum data model and LLM-based generationclaw_agent.pyWraps openclaw agent CLI for agent communicationllm_handler.pyAsync LLM client with conversation history managementlearning_logger.pyStructured experience logger — records training insights and writes to OpenClaw MEMORY.mdconfig.pyCentralized training parameterstest_phases.pyStep-by-step pipeline verification
After a session completes, training_results.json contains:
json
{
"curriculum": {
"title": "...",
"overview": "...",
"target_persona": "...",
"stages_total": 4,
"stages_passed": 3
},
"stage_reports": [
{
"stage_id": 1,
"stage_name": "...",
"passed": true,
"overall_feedback": "...",
"tasks": [
{
"task_id": "1.1",
"passed": true,
"score": 8,
"strengths": ["..."],
"weaknesses": ["..."],
"feedback": "..."
}
]
}
]
}
Training experiences are automatically recorded throughout the session. Every task evaluation, stage result, and infrastructure error is logged to .claw_sergeant_accumulated_lessons/ as structured markdown entries for future reference.
After the session completes, a summary is written to ~/.openclaw/workspace/MEMORY.md containing the training timestamp, curriculum details, stage pass/fail results, and a pointer to the full logs. This allows the Claw agent to reference its training history in future sessions. If the OpenClaw workspace is not found, this step is silently skipped.
python test_phases.py 1 to verify API key and endpoint. Check LLM_BASE_URL points to a valid OpenAI-compatible API.openclaw CLI installation.CURRICULUM_TEMPERATURE or switching to a more capable model.STAGE_PASS_THRESHOLD or increase MAX_ATTEMPTS_PER_TASK in config.py.httpx — async HTTP client for LLM API callsloguru — structured loggingpython-dotenv — environment variable managementopenclaw CLI — must be installed and accessible in PATH