Reasoning mechanics determine how the agent sequences thoughts, decides what to do next, and validates its own outputs. These patterns run inside a single agent and are composable with any topology.
LLM selects and calls structured tools (functions/APIs) based on the query. Results are fed back into the context and the loop continues until no more tool calls are needed.
flowchart LR
Q([Query]) --> LLM["LLM\nTool selection"]
LLM -->|call| T["Tool / API"]
T -->|result| LLM
LLM --> R([Response])
style Q fill:#666666,stroke:#fff,color:#fff
style LLM fill:#4a7ab5,stroke:#fff,color:#fff
style T fill:#2e8b6e,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff
Interleaves Thought / Action / Observation steps. The model reasons about what to do, calls a tool, observes the result, and continues until the task is done.
flowchart TD
Q([Query]) --> TH["Thought\nWhat to do?"]
TH --> AC["Action\nTool call"]
AC --> OB["Observation\nTool result"]
OB -->|loop| TH
OB -->|done| R([Response])
style Q fill:#666666,stroke:#fff,color:#fff
style TH fill:#4a7ab5,stroke:#fff,color:#fff
style AC fill:#2e8b6e,stroke:#fff,color:#fff
style OB fill:#4a7ab5,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff
After each attempt, a reflection step critiques the output and generates corrective instructions. The agent retries with the critique, improving accuracy at the cost of extra tokens.
flowchart LR
Q([Query]) --> A["Agent\nFirst attempt"]
A --> C["Critic\nReflect"]
C -->|retry| A
C -->|pass| R([Response])
style Q fill:#666666,stroke:#fff,color:#fff
style A fill:#4a7ab5,stroke:#fff,color:#fff
style C fill:#c48a1a,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff
A planner LLM generates a task list upfront; an executor LLM runs each task. Separating planning from execution reduces mid-plan hallucinations and allows parallel execution.
flowchart LR
Q([Query]) --> P["Planner LLM\nTask list"]
P --> E1["Executor\nTask 1"]
P --> E2["Executor\nTask 2"]
E1 --> S["Synthesiser"]
E2 --> S
S --> R([Response])
style Q fill:#666666,stroke:#fff,color:#fff
style P fill:#4a7ab5,stroke:#fff,color:#fff
style E1 fill:#2e8b6e,stroke:#fff,color:#fff
style E2 fill:#2e8b6e,stroke:#fff,color:#fff
style S fill:#4a7ab5,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff
Generate a draft answer, then generate verification questions about its claims, answer each independently, and revise the draft to eliminate hallucinations.
flowchart LR
Q([Query]) --> D["Draft\nanswer"]
D --> VQ["Verification\nquestions"]
VQ --> VA["Verify\neach claim"]
VA --> RV["Revised\nanswer"]
style Q fill:#666666,stroke:#fff,color:#fff
style D fill:#4a7ab5,stroke:#fff,color:#fff
style VQ fill:#c48a1a,stroke:#fff,color:#fff
style VA fill:#c48a1a,stroke:#fff,color:#fff
style RV fill:#4a7ab5,stroke:#fff,color:#fff
Topology patterns define how multiple agents are connected — who orchestrates, who works in parallel, and how control flows between agents.
Same agent logic implemented across LangGraph, CrewAI, and AG2. Benchmarks correctness, latency, and cost across frameworks with an identical task harness.
flowchart LR
T([Task]) --> H["Harness\ntest runner"]
H --> LG["LangGraph"]
H --> CA["CrewAI"]
H --> AG["AG2"]
LG --> M["Metrics\ncollector"]
CA --> M
AG --> M
style T fill:#666666,stroke:#fff,color:#fff
style H fill:#4a7ab5,stroke:#fff,color:#fff
style LG fill:#2e8b6e,stroke:#fff,color:#fff
style CA fill:#2e8b6e,stroke:#fff,color:#fff
style AG fill:#2e8b6e,stroke:#fff,color:#fff
style M fill:#b54a4a,stroke:#fff,color:#fff
Agents are assigned named roles (researcher, analyst, writer), each with a specific goal and tool set. A manager coordinates them through the task.
flowchart TD
T([Task]) --> M["Manager"]
M --> R["Researcher"]
M --> AN["Analyst"]
M --> W["Writer"]
R --> M
AN --> M
W --> RP([Report])
style T fill:#666666,stroke:#fff,color:#fff
style M fill:#4a7ab5,stroke:#fff,color:#fff
style R fill:#2e8b6e,stroke:#fff,color:#fff
style AN fill:#2e8b6e,stroke:#fff,color:#fff
style W fill:#2e8b6e,stroke:#fff,color:#fff
style RP fill:#666666,stroke:#fff,color:#fff
An orchestrator decomposes a task and fans out subtasks to stateless worker agents. Workers return results; the orchestrator synthesises. Enables horizontal scale across sub-tasks.
flowchart TD
T([Task]) --> O["Orchestrator"]
O --> W1["Worker 1"]
O --> W2["Worker 2"]
O --> W3["Worker 3"]
W1 --> S["Synthesiser"]
W2 --> S
W3 --> S
S --> R([Response])
style T fill:#666666,stroke:#fff,color:#fff
style O fill:#4a7ab5,stroke:#fff,color:#fff
style W1 fill:#2e8b6e,stroke:#fff,color:#fff
style W2 fill:#2e8b6e,stroke:#fff,color:#fff
style W3 fill:#2e8b6e,stroke:#fff,color:#fff
style S fill:#4a7ab5,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff
Multiple agents run the same task in parallel. Results are aggregated — by majority vote, highest confidence, or a judge model — to improve reliability.
flowchart LR
T([Task]) --> A1["Agent A"]
T --> A2["Agent B"]
T --> A3["Agent C"]
A1 --> J["Judge /\nAggregator"]
A2 --> J
A3 --> J
J --> R([Best answer])
style T fill:#666666,stroke:#fff,color:#fff
style A1 fill:#4a7ab5,stroke:#fff,color:#fff
style A2 fill:#4a7ab5,stroke:#fff,color:#fff
style A3 fill:#4a7ab5,stroke:#fff,color:#fff
style J fill:#c48a1a,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff
Tool & Context Integration patterns govern how agents connect to external systems, retrieve knowledge, and maintain memory across turns and sessions.
Model Context Protocol standardises the agent-to-tool interface. The agent connects to an MCP server over stdio/SSE and discovers available tools at runtime — no hard-coded API glue.
flowchart LR
A["Agent\n(MCP client)"] -->|discover| S["MCP Server"]
S --> T1["search"]
S --> T2["execute"]
S --> T3["fetch"]
style A fill:#4a7ab5,stroke:#fff,color:#fff
style S fill:#2e8b6e,stroke:#fff,color:#fff
style T1 fill:#2e8b6e,stroke:#fff,color:#fff
style T2 fill:#2e8b6e,stroke:#fff,color:#fff
style T3 fill:#2e8b6e,stroke:#fff,color:#fff
Retrieval exposed as a callable tool rather than a fixed pre-retrieval step. The agent decides when to retrieve and can iterate — rewriting the query if the first retrieval is poor.
flowchart LR
Q([Query]) --> A["Agent"]
A -->|retrieve| VDB["Vector DB"]
VDB -->|chunks| A
A -->|rewrite if poor| VDB
A --> R([Response])
style Q fill:#666666,stroke:#fff,color:#fff
style A fill:#4a7ab5,stroke:#fff,color:#fff
style VDB fill:#7a5ba8,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff
Agents write to and read from an external memory store across turns. Covers scratchpad (in-context), episodic (SQLite), and semantic (ChromaDB) tiers with progressive compaction.
flowchart LR
A["Agent"] --> SC["Scratchpad\nin-context"]
A --> EP["Episodic\nSQLite"]
A --> SM["Semantic\nChromaDB"]
SC --> A
EP --> A
SM --> A
style A fill:#4a7ab5,stroke:#fff,color:#fff
style SC fill:#7a5ba8,stroke:#fff,color:#fff
style EP fill:#7a5ba8,stroke:#fff,color:#fff
style SM fill:#7a5ba8,stroke:#fff,color:#fff
Facts stored as a knowledge graph (entity → relation → entity). Retrieval traverses the graph, enabling multi-hop reasoning that flat vector search cannot support.
flowchart LR
Q([Query]) --> A["Agent"]
A -->|traverse| KG["Knowledge\nGraph"]
KG -->|entities + rels| A
A --> R([Response])
style Q fill:#666666,stroke:#fff,color:#fff
style A fill:#4a7ab5,stroke:#fff,color:#fff
style KG fill:#7a5ba8,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff
Decision Economics patterns treat every agent decision as an economic trade-off: accuracy, latency, and cost. These patterns matter most in production where budgets are real constraints.
Total cost (tokens × price) divided by number of correct decisions. The core metric for comparing models and configurations on a production task harness.
flowchart LR
H["Harness\n(N incidents)"] --> M1["Model A"]
H --> M2["Model B"]
M1 --> E["CPCD\n= cost / correct"]
M2 --> E
E --> R(["Pareto\nfrontier"])
style H fill:#666666,stroke:#fff,color:#fff
style M1 fill:#4a7ab5,stroke:#fff,color:#fff
style M2 fill:#4a7ab5,stroke:#fff,color:#fff
style E fill:#b54a4a,stroke:#fff,color:#fff
style R fill:#c48a1a,stroke:#fff,color:#fff
Plots model/config options on accuracy vs. cost axes. The Pareto frontier identifies configurations where you can't improve accuracy without increasing cost.
flowchart LR
E["CPCD\nevals"] --> P["Pareto\nplotter"]
P --> F["Frontier\n(non-dominated)"]
F --> D["Decision:\nbest config"]
style E fill:#b54a4a,stroke:#fff,color:#fff
style P fill:#4a7ab5,stroke:#fff,color:#fff
style F fill:#c48a1a,stroke:#fff,color:#fff
style D fill:#666666,stroke:#fff,color:#fff
A per-task token or cost cap enforced at runtime. When the budget is exhausted, the agent falls back to a cheaper model or returns a partial answer.
flowchart TD
T([Task]) --> A["Agent"]
A -->|check| B{"Budget\nremaining?"}
B -->|yes| A
B -->|no| FB["Fallback\nmodel"]
FB --> R([Response])
A --> R
style T fill:#666666,stroke:#fff,color:#fff
style A fill:#4a7ab5,stroke:#fff,color:#fff
style B fill:#c48a1a,stroke:#fff,color:#fff
style FB fill:#2e8b6e,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff
A lightweight classifier routes incoming queries to the cheapest model that can handle them confidently. Complex or ambiguous queries escalate to a larger, more expensive model.
flowchart LR
Q([Query]) --> R["Router\nclassifier"]
R -->|simple| SM["Small model\n(cheap)"]
R -->|complex| LM["Large model\n(expensive)"]
SM --> O([Output])
LM --> O
style Q fill:#666666,stroke:#fff,color:#fff
style R fill:#c48a1a,stroke:#fff,color:#fff
style SM fill:#4a7ab5,stroke:#fff,color:#fff
style LM fill:#4a7ab5,stroke:#fff,color:#fff
style O fill:#666666,stroke:#fff,color:#fff
Measures how accuracy changes as context is progressively truncated or the model is swapped for a cheaper one. Maps the accuracy–cost trade-off as a curve, not a point.
flowchart LR
E["Eval\nharness"] --> C1["Full\ncontext"]
E --> C2["Half\ncontext"]
E --> C3["No\ncontext"]
C1 --> CV["Curve\nplotter"]
C2 --> CV
C3 --> CV
style E fill:#b54a4a,stroke:#fff,color:#fff
style C1 fill:#4a7ab5,stroke:#fff,color:#fff
style C2 fill:#4a7ab5,stroke:#fff,color:#fff
style C3 fill:#4a7ab5,stroke:#fff,color:#fff
style CV fill:#c48a1a,stroke:#fff,color:#fff
Safety, Control & Governance patterns add human oversight, constraint enforcement, and adversarial robustness to agents in production or regulated environments.
The agent pauses and waits for a human to approve, modify, or reject the next action before execution. Essential for irreversible or high-stakes operations.
flowchart LR
A["Agent"] --> G{"Approval\ngate"}
G -->|approved| E["Execute\naction"]
G -->|rejected| A
E --> R([Done])
style A fill:#4a7ab5,stroke:#fff,color:#fff
style G fill:#c48a1a,stroke:#fff,color:#fff
style E fill:#2e8b6e,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff
Input and output shields run around every LLM call. Input guardrails block policy-violating prompts; output guardrails detect toxic, PII-leaking, or off-topic responses.
flowchart LR
Q([Input]) --> IG["Input\nguardrail"]
IG --> A["LLM\nAgent"]
A --> OG["Output\nguardrail"]
OG --> R([Safe output])
IG -->|block| BK([Blocked])
OG -->|block| BK
style Q fill:#666666,stroke:#fff,color:#fff
style IG fill:#c48a1a,stroke:#fff,color:#fff
style A fill:#4a7ab5,stroke:#fff,color:#fff
style OG fill:#c48a1a,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff
style BK fill:#b54a4a,stroke:#fff,color:#fff
A red-team agent generates adversarial inputs (prompt injection, jailbreaks, malformed tool results) against the production agent to surface failure modes before deployment.
flowchart LR
RT["Red-team\nagent"] -->|attack| A["Agent\nunder test"]
A --> RS["Response"]
RS --> SC["Scorer\n(did it hold?)"]
SC -->|fail| RT
SC -->|pass| RP([Report])
style RT fill:#b54a4a,stroke:#fff,color:#fff
style A fill:#4a7ab5,stroke:#fff,color:#fff
style RS fill:#666666,stroke:#fff,color:#fff
style SC fill:#c48a1a,stroke:#fff,color:#fff
style RP fill:#666666,stroke:#fff,color:#fff
The agent simulates a full action plan in dry-run mode and presents it for human review. Changes are executed only after explicit approval, with a full diff shown.
flowchart LR
T([Task]) --> P["Plan\n(dry-run)"]
P --> H{"Human\nreview"}
H -->|approve| E["Execute\nplan"]
H -->|reject| T
E --> R([Done])
style T fill:#666666,stroke:#fff,color:#fff
style P fill:#4a7ab5,stroke:#fff,color:#fff
style H fill:#c48a1a,stroke:#fff,color:#fff
style E fill:#2e8b6e,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff
Self-Improvement patterns let agents optimise their own prompts, configurations, and harnesses over time — without manual prompt engineering.
Uses DSPy BootstrapFewShot to automatically select few-shot examples that maximise a task-specific metric. Replaces hand-crafted examples with data-driven ones.
flowchart LR
TRN["Training\nexamples"] --> OPT["DSPy\nBootstrapFewShot"]
OPT -->|optimise| PM["Optimised\nprompt"]
PM --> A["Agent"]
A --> SC["Metric\nevaluator"]
SC -->|iterate| OPT
style TRN fill:#666666,stroke:#fff,color:#fff
style OPT fill:#4a7ab5,stroke:#fff,color:#fff
style PM fill:#2e8b6e,stroke:#fff,color:#fff
style A fill:#4a7ab5,stroke:#fff,color:#fff
style SC fill:#b54a4a,stroke:#fff,color:#fff
A producer agent generates a response; a critic agent evaluates it and returns structured feedback. The producer revises until the critic approves or max iterations is reached.
flowchart TD
Q([Query]) --> PR["Producer\nagent"]
PR --> CR["Critic\nagent"]
CR -->|revise| PR
CR -->|approve| R([Response])
style Q fill:#666666,stroke:#fff,color:#fff
style PR fill:#4a7ab5,stroke:#fff,color:#fff
style CR fill:#b54a4a,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff
The eval harness is treated as an agent task. A meta-agent runs it, scores outputs, and proposes modifications to the harness's own prompts or structure to improve future scores.
flowchart TD
H["Harness\n(eval agent)"] --> SC["Score\noutputs"]
SC --> MA["Meta-agent\npropose changes"]
MA -->|update| H
SC -->|converge| R([Optimised harness])
style H fill:#4a7ab5,stroke:#fff,color:#fff
style SC fill:#b54a4a,stroke:#fff,color:#fff
style MA fill:#4a7ab5,stroke:#fff,color:#fff
style R fill:#666666,stroke:#fff,color:#fff