What is a method template?
A method template combines:| Component | Role |
|---|---|
| State | A StateSchema subclass with pattern-specific fields (reflections, drafts, refinement counts) |
| Critic | A Critic subclass that drives the pattern’s loop by returning retry, continue, or stop at the right times |
| Agent | An AgentModule subclass with pattern-aware build_system_prompt(), prepare(), and reduce() |
Self-Refine
The Self-Refine pattern (Madaan et al. 2023) iterates: generate → critique → refine until quality meets a threshold or max refinements are reached.When to use it
- Text generation tasks where quality matters more than speed
- Summarization, translation, code generation with self-evaluation
- Any task where iterative improvement reliably produces better output
Quick start
How it works
- Generate: The agent produces an initial draft.
- Critique:
SelfRefineCriticevaluates the draft quality using heuristic scoring (longer drafts after more refinements score higher; very short drafts are penalized). In production, replace heuristics with an LLM-based scorer. - Refine: If the score is below
quality_thresholdand refinements remain, the critic returnsretrywith aninstruction_patchasking the agent to improve. The agent sees its previous draft and the critique in the next prompt. - Accept: When the score meets the threshold or
max_refinementsis reached, the critic returnscontinueorstop.
SelfRefineCritic parameters
| Parameter | Default | Description |
|---|---|---|
max_refinements | 3 | Maximum refinement iterations |
quality_threshold | 0.7 | Minimum score (0.0–1.0) to accept the draft |
SelfRefineState fields
| Field | Type | Description |
|---|---|---|
draft | str | Current draft text |
refinement_count | int | Number of refinements so far |
max_refinements | int | Refinement budget |
critique_history | List[str] | Accumulated critiques |
Customizing the quality scorer
The built-in critic uses heuristics. For production use, subclass and overrideevaluate():
Reflexion
The Reflexion pattern (Shinn et al. 2023) iterates: act → evaluate → reflect → retry with memory. On failure, the critic generates a verbal reflection stored in state and injected into future prompts.When to use it
- Debugging and error-correction tasks where the agent must learn from failures
- Tasks where different strategies should be tried after failure
- Multi-attempt problems (coding, reasoning) where reflections improve subsequent attempts
Quick start
How it works
- Act: The agent takes an action toward the task.
- Evaluate:
ReflexionCriticchecks for failures (errors, non-zero return codes, empty results). - Reflect: On failure, the critic generates a verbal reflection from the error context and returns
retrywith the reflection as aninstruction_patch. The reflection is stored instate.reflections. - Retry with memory: The agent’s
build_system_prompt()includes all previous reflections, so the LLM can avoid repeating the same mistakes.
ReflexionCritic parameters
| Parameter | Default | Description |
|---|---|---|
max_reflections | 3 | Maximum reflection iterations before forced stop |
success_threshold | 0.6 | Minimum score to consider the trajectory successful |
ReflexionState fields
| Field | Type | Description |
|---|---|---|
reflections | List[str] | Accumulated verbal reflections |
reflection_count | int | Number of reflections generated |
max_reflections | int | Reflection budget |
last_action_success | bool | Whether the last step succeeded |
attempt | int | Current attempt number |
LATS
The LATS pattern (Zhou et al. 2023) applies Monte Carlo Tree Search to language agents: select → expand → evaluate → backpropagate. Failed trajectories generate reflections that guide future exploration away from similar mistakes.When to use it
- Tasks requiring systematic exploration of multiple solution paths
- Logic puzzles, coding challenges, and multi-step reasoning
- Problems where trying different strategies improves success
Quick start
How it works
- Simulate: The agent takes an action, producing a result.
- Evaluate:
LATSCriticcomputes a reward from the result (errors → low reward, FINAL ANSWER → high reward). - Reflect: Failed paths (reward < 0.3) generate reflections stored in
state.reflections. - Guide: On retry, the critic provides an
instruction_patchthat includes reflections and UCB1-style exploration guidance. - Stop: When a path succeeds (reward ≥ success_threshold) or
max_simulationsis reached.
LATSCritic parameters
| Parameter | Default | Description |
|---|---|---|
max_simulations | 5 | Maximum simulation iterations |
exploration_weight | 1.41 | UCB1 exploration constant (c) |
success_threshold | 0.8 | Reward value for early stopping |
LATSState fields
| Field | Type | Description |
|---|---|---|
simulations_done | int | Number of simulations completed |
max_simulations | int | Simulation budget |
exploration_weight | float | UCB1 c parameter |
best_reward | float | Best reward found so far |
best_answer | str | Answer from the best trajectory |
failed_paths | List[str] | Descriptions of failed paths |
reflections | List[str] | Reflections from failures |
MoA (Mixture-of-Agents)
The MoA pattern (Wang et al. 2024) runs multiple proposers independently and synthesizes their outputs: propose → aggregate. Diversity of proposals improves quality, even when individual proposers are weaker models.When to use it
- Tasks benefiting from diverse perspectives or creative responses
- Analysis, evaluation, and synthesis problems
- Quality improvement through ensemble reasoning
Quick start
How it works
- Collect:
MoACriticchecks if enough proposals have been gathered. If not, it returnsretrywith an instruction to gather more proposals. - Aggregate: When all proposals are collected, the critic prompts for synthesis.
- Output: When synthesis is complete and meets the quality threshold, the critic returns
stop.
qitos.kit.patterns.moa.build_moa_system().
MoACritic parameters
| Parameter | Default | Description |
|---|---|---|
proposer_count | 3 | Expected number of proposals |
max_rounds | 1 | Maximum proposal-aggregation rounds |
quality_threshold | 0.6 | Minimum score to accept synthesis |
MoARecipeState fields
| Field | Type | Description |
|---|---|---|
proposals | List[Dict] | Collected proposals with proposer and content |
synthesis | str | Final synthesized answer |
round_count | int | Current round number |
max_rounds | int | Round budget |
proposer_count | int | Expected proposal count |
Magentic-One
The Magentic-One pattern (Furtado et al. 2024) uses an orchestrator with a dual-ledger architecture: plan → delegate → track progress → re-plan when stuck. The orchestrator maintains a Fact Bank and Task Ledger, delegates to specialist agents, and re-plans when progress stalls.When to use it
- Complex, multi-step tasks requiring coordination of different capabilities
- Tasks where an orchestrator needs to adapt its plan based on intermediate results
- Open-ended problems with research, coding, and analysis subtasks
Quick start
How it works
- Plan: The orchestrator creates a task ledger and gathers initial facts.
- Delegate: At each step, a subtask is assigned to a specialist.
- Track:
ProgressCriticevaluates whether new facts have been gathered or tasks completed. - Re-plan: If no progress is detected for
max_stallsconsecutive steps, the critic returnsretrywith re-planning guidance. - Stop: When a FINAL ANSWER is provided, or when stall budget is exhausted.
ProgressCritic parameters
| Parameter | Default | Description |
|---|---|---|
max_stalls | 3 | Maximum consecutive no-progress steps |
progress_threshold | 0.5 | Minimum score to consider progress |
MagenticOneState fields
| Field | Type | Description |
|---|---|---|
fact_bank | List[str] | Accumulated facts and educated guesses |
task_ledger | List[str] | Current plan of subtasks |
completed_tasks | List[str] | Finished subtasks |
stall_count | int | Consecutive no-progress steps |
max_stalls | int | Stall budget before forced stop |
specialist_calls | int | Number of specialist delegations |
current_subtask | str | Currently active subtask |
Scaffolding a new agent
Use theqit new CLI command to scaffold a new agent project from the built-in cookiecutter template:
src/agent.py— Agent class with State, init_state, build_system_prompt, reduceconfigs/default.yaml— Default model and step configurationtests/test_agent.py— Basic smoke testssnowl_compat.py— Snowl evaluation compatibility adaptereval_config.yaml— Evaluation configuration
Building your own method template
To create a custom method template, follow the same Agent + Critic pattern:- Define a state that extends
StateSchemawith your pattern’s tracking fields - Implement a critic that returns
retrywithinstruction_patchandstate_patchwhen the pattern requires iteration - Implement an agent whose
build_system_prompt()injects pattern context from state
