The 21 Core Patterns
Lár is built on the philosophy of "Code as Graph". We have created 21 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
ToolNodeoutput merges intostate, providing context for theLLMNode.
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
ClearErrorNodeto 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
BatchNodefor 50x speedup.
16. Integration Builder
Just-in-Time Tools. See Example
- Mechanism: User ->
@lar/IDE_INTEGRATION_PROMPT.md-> NewToolNode. - 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 -> Loadstate.json-> Resume. - Use Case: Serverless deployments (stopping to save cost), Crash recovery.
19. FastAPI Server
Deploy Anywhere. See Example
- Mechanism: Wrapping
GraphExecutorin a FastAPI route. - Use Case: Exposing your agent as a REST API for production deployment.
20. Juried Layer
Architecture-Level Safety. See Example
- Mechanism:
Proposer (LLM)->Jury (Code/Policy)->Kernel (Execution). - Why: Separates the "Reasoning" (untrustworthy) from the "Authorization" (deterministic).
21. Access Control Agent
Combines Reasoning, Determinstic Policy, and Human-in-the-Loop.
File: 21_access_control_agent.py
22. Context Contamination (Social Engineering)
Security Lab 1: A "Red Team" script that attempts to trick an agent using social engineering ("CTO approved this").
File: 22_context_contamination_test.py
- Mechanism: Adversarial Advocate vs. Weak Jury vs. Strong Jury.
- Lesson: LLM Juries can be socially engineered. Code Juries cannot.
23. Zombie Action (Stale Authority)
Security Lab 2: Demonstrates a replay attack where an old approval is used in a new, dangerous context.
File: 23_zombie_action_test.py
- Mechanism: Cryptographic signature validation of state.
- Lesson: Never trust
statewithout a signature if the graph was paused.
24. Human-in-the-Loop (Article 14)
Mandatory Hardware Stop.
File: 24_hitl_agent.py
- Mechanism:
HumanJuryNode. - Use Case: High-risk actions (Article 14 compliance) that require explicit CLI/API approval.
- Key Feature: Deterministic blocking. The LLM cannot bypass this node.