Writing a Method Template
A method template in QitOS is an Agent + Critic pair implementing a well-known agentic reasoning pattern. This guide walks through creating one from scratch.What Makes a Method Template
Every method template consists of:- Recipe implementation —
qitos/recipes/<method_name>/__init__.pywith AgentModule, Critic, and State - Template assets —
templates/<method_name>/with config, docs, and scaffold code - Tests —
tests/test_<method_name>.py - CLI registration — Entry in
_METHOD_TEMPLATESdict inqitos/cli.py
Directory Structure
Step 1: Define State
Create a dataclass tracking method-specific fields: Illustrative fragment (not a standalone program; use the complete example linked on this page).EngineResult.state after execution and is accessible to the Critic at each step.
Step 2: Implement AgentModule
SubclassAgentModule with build_system_prompt() and reduce():
Illustrative fragment (not a standalone program; use the complete example linked on this page).
Key points
build_system_prompt()receivestask(str) andstate(dict). Use state to inject context like reflections, proposals, or task ledgers.reduce()receives the currentDecisionandstate, and returns a dict of state updates. The engine merges this into the running state.- Always handle
state=Nonegracefully (first step).
Step 3: Implement Critic
SubclassCritic with evaluate() returning CriticResult:
Illustrative fragment (not a standalone program; use the complete example linked on this page).
CriticResult actions
Key fields
instruction_patch: String injected into the next prompt to guide the agentstate_patch: Dict merged into state to update method-specific fieldsscore: Float (0-1) indicating quality; used by qita for visualization
Step 4: Create Template Assets
agent.py
Illustrative fragment (not a standalone program; use the complete example linked on this page).config.yaml
paper.md
Step 5: Register in CLI
Add to_METHOD_TEMPLATES in qitos/cli.py:
Illustrative fragment (not a standalone program; use the complete example linked on this page).
qit list-templates output.
Step 6: Write Tests
Minimum test coverage: Illustrative fragment (not a standalone program; use the complete example linked on this page).Checklist
Before submitting a method template PR:- Agent subclasses
AgentModulewithbuild_system_prompt()andreduce() - Critic subclasses
Criticwithevaluate()returningCriticResult - State dataclass with method-specific fields
-
templates/<method_name>/has__init__.py,agent.py,config.yaml,paper.md - Method name added to
_METHOD_TEMPLATESinqitos/cli.py - Tests cover Agent, Critic, and State with edge cases (minimum 15 tests)
- paper.md explains mapping from paper to QitOS and key differences
-
pytest tests/test_<method_name>.pypasses - Full test suite
pytest tests/ -qshows no regressions
