Skip to main content

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:
  1. Recipe implementation — qitos/recipes/<method_name>/__init__.py with AgentModule, Critic, and State
  2. Template assets — templates/<method_name>/ with config, docs, and scaffold code
  3. Tests — tests/test_<method_name>.py
  4. CLI registration — Entry in _METHOD_TEMPLATES dict in qitos/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).
State is stored in EngineResult.state after execution and is accessible to the Critic at each step.

Step 2: Implement AgentModule

Subclass AgentModule 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() receives task (str) and state (dict). Use state to inject context like reflections, proposals, or task ledgers.
  • reduce() receives the current Decision and state, and returns a dict of state updates. The engine merges this into the running state.
  • Always handle state=None gracefully (first step).

Step 3: Implement Critic

Subclass Critic 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 agent
  • state_patch: Dict merged into state to update method-specific fields
  • score: 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).
This makes it appear in 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).
Aim for at least 15 tests per template covering Agent, Critic, State, and edge cases.

Checklist

Before submitting a method template PR:
  • Agent subclasses AgentModule with build_system_prompt() and reduce()
  • Critic subclasses Critic with evaluate() returning CriticResult
  • State dataclass with method-specific fields
  • templates/<method_name>/ has __init__.py, agent.py, config.yaml, paper.md
  • Method name added to _METHOD_TEMPLATES in qitos/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>.py passes
  • Full test suite pytest tests/ -q shows no regressions

Existing Templates for Reference