The 18 Core Patterns
Lár is built on the philosophy of "Code as Graph". We have created 18 robust engineering patterns that strictly correspond to the examples in the repository.
Each pattern below includes a link to the source code.
Standard Patterns
1. Simple Triage
The "Hello World" of Agents.
See Example
* Mechanism: LLMNode (Classifier) -> RouterNode -> ToolNode (Handler).
* Use Case: Customer support routing (Billing vs Tech), Email sorting.
* Why: Deterministic routing is safer than letting an LLM decide "what to do" implicitly.
2. RAG Researcher
Retrieval Augmented Generation with State.
See Example
* Mechanism: ToolNode (Retriever) -> LLMNode (Answer Generator).
* Key Feature: The ToolNode output merges into state, providing context for the LLMNode.
3. Self-Correction
The "Unreliable Witness" fix.
See Example
* Mechanism: Generator -> Validator -> Error? -> Refiner.
* Use Case: Code generation (run -> syntax error -> fix).
* Key Feature: Uses ClearErrorNode to reset state after a fix before retrying.
4. Human-in-the-Loop
Pausing for approval.
See Example
* Mechanism: LLMNode (Propose Plan) -> Wait (Stop Execution) -> User Input -> ToolNode (Execute).
* Use Case: Deploying code, spending money, sending sensitive emails.
5. Parallel Execution (Basic)
Fan-Out Aggregation. See Example * Mechanism: Running multiple logical branches that merge back. * Note: This is simulated parallelism. For true threading, see Pattern 14.
6. Structured Output
Strict JSON Enforcement.
See Example
* Mechanism: LLMNode -> JSONParser -> API.
* Use Case: Extracting data for APIs.
* Why: Guarantees the output is machine-readable, preventing downstream crashes.
Intermediate Patterns
7. Multi-Agent Handoff
The Manager-Worker topology.
See Example
* Mechanism: Manager (Router) -> Worker A / Worker B -> Manager.
* Use Case: Complex projects (e.g., Writer <-> Editor).
* Why: Specialization. A "Coder" prompt performs better than a "Generalist" prompt.
8. Meta-Prompt Optimizer
Self-Modifying Agents. See Example * Mechanism: An agent that rewrites its own system prompt based on results. * Use Case: Optimizing instructions for specific tasks.
9. Corporate Swarm
Stress Testing.
See Example
* Mechanism: Programmatically generating a graph with 60+ nodes.
* Why: Proves Lár's graph engine scales O(1) with complexity, unlike chain-based frameworks.
10. Security Firewall
Architecture-Level Safety.
See Example
* Mechanism: Input -> Guardrail Node -> Router (Block/Allow) -> Agent.
* Why: Blocks jailbreaks before they reach the expensive model.
11. Reward Code Agent
Forward-Defined Logic. See Example * Mechanism: Code-first logic design.
12. Support Helper
Lightweight Assistant. See Example * Mechanism: Specific tool usage for customer support data.
13. Mini Swarm Pruner
Dynamic Graph management. See Example * Mechanism: Dynamically removing nodes from execution.
Advanced & Ops Patterns
14. Parallel Newsroom
True Threaded Parallelism.
See Example
* Mechanism: BatchNode([Worker A, Worker B]).
* Use Case: Fetching 5 URLs at once using ThreadPoolExecutor.
15. Parallel Corporate Swarm
Concurrent Branch Execution.
See Example
* Mechanism: Scaling the Swarm (Pattern 9) with BatchNode for 50x speedup.
16. Integration Builder
Just-in-Time Tools.
See Example
* Mechanism: User -> @lar/IDE_INTEGRATION_PROMPT.md -> New ToolNode.
* Use Case: Wrappers for CoinCap, Stripe, Linear.
17. The A/B Tester
Agentic Evaluation.
See Example
* Mechanism: BatchNode (Model A, Model B) -> JudgeNode (Evaluator).
* Use Case: Testing a new prompt against an old one.
18. The Time Traveller
State Serialization.
See Example
* Mechanism: Save state.json -> Stop Process -> Load state.json -> Resume.
* Use Case: Serverless deployments (stopping to save cost), Crash recovery.