design-agents-using-patterns
Skill4 starsChanged 3 months agoMITView on GitHub
WHEN/WHERE/WHO: [Scheduling: Use when: designing a multi-agent system, creating routing logic, building self-correcting prompt chains, or adding tool-use and planning capabilities. Applies to: orchestration scripts, agent system designs, and prompt chain configurations in the workspace] HOW: [Structural: Helps with: selecting appropriate agentic patterns, structuring coordinator-specialist teams, implementing exception handling, and preventing runaway LLM loops] WHY: [Scheduling: Prevents fragile, runaway agent orchestration by enforcing proven patterns and loop limits.]
In this repository61 other files it gives its agents.
- activate-personalSkill
- analyze-with-tactics-questionnairesSkill
- apply-agile-testing-quadrantsSkill
- apply-architectural-tacticsSkill
- apply-attribute-driven-designSkill
- apply-fundamentals-of-data-visualizationSkill
- apply-oopsi-modelSkill
- apply-screenplay-patternSkill
- apply-specification-by-exampleSkill
- blog-topic-discoverSkill
- build-agent-memory-systemsSkill
- build-business-objectives-modelSkill
- build-data-dictionarySkill
- build-feature-treeSkill
- comment-alive-test-driven-developmentSkill
- conduct-event-stormingSkill
- create-ecosystem-mapSkill
- create-living-documentationSkill
- create-skill-from-bookSkill
- CREATING-SKILL-TEMPLATESkill
- define-architectural-driversSkill
- define-bounded-contextsSkill
- define-ubiquitous-languageSkill
- design-agentic-screenplay-modelSkill
- design-agent-perception-layersSkill
- design-agent-planningSkill
- design-agent-reward-functionsSkill
- design-architecture-viewpointsSkill
- design-autonomous-ai-interfacesSkill
- design-ddd-aggregatesSkill
- design-tool-use-sandboxingSkill
- document-architectural-decisionsSkill
- document-legacy-codebaseSkill
- doc-with-usage-exampleSkill
- draft-srs-documentSkill
- elicit-requirements-modelsSkill
- evolve-skill-with-wikiSkill
- extract-business-rulesSkill
- facilitate-example-mappingSkill
- facilitate-user-story-mappingSkill
- implement-agent-observabilitySkill
- implement-agent-reflectionSkill
- improve-existing-skillSkill
- improve-user-storySkill
- managing-ai-projectsSkill
- orchestrate-multi-agent-collaborationSkill
- prioritize-requirementsSkill
- review-c4-modelSkill
- review-data-engineeringSkill
- save-as-skillSkill
- scaffold-cmake-cxx-sanitize-gtest-envSkill
- skill-commonSkill
- task-commit-triggerSkill
- test-case-with-demoSkill
- test-case-with-readmeSkill
- test-driven-developmentSkill
- UnitTesting-convert2CaTDDSkill
- update-my-resumeSkill
- update-spec-contextSkill
- validate-requirements-criteriaSkill
- The first 60 shown.
The file
Show its rules and text
We split this skill into the rules it gives an agent
13 rules. About 0 are common, 12 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈12
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 13
When this skill is activated, first load skill-common and apply the shared conventions it defines: canonical section order, frontmatter …
- Distinctive: line 32
Do not use for simple static scripting, simple template prompts that do not involve loops, routing, or tool calls, or basic API calls …
- Distinctive: line 61
Stop Rule: If model limits, tool schemas, or cost and retry budgets are undefined, stop and ask before finalizing the orchestration design.
- Distinctive: line 64
Runaway Loop Protection: Every agentic loop (Reflection, Planning, or Exception Recovery) must have a strict, hard-coded maximum iteration …
- Distinctive: line 65
No Silent Failures: All tool errors, API timeouts, or parsing exceptions must be caught, logged, and routed through a defined recovery or …
- Distinctive: line 66
Schema Validation: All data passed between agents or tools must be validated against a strict state schema (e.g., Pydantic models or typed …
- Distinctive: line 69
If the primary model options, tool schemas, or maximum token/cost budgets are undefined or conflicting, stop and ask the user to clarify …
- Distinctive: line 101
Write the orchestration code, ensuring the system state is updated cleanly at each node.
- Distinctive: line 104
Red Flags Check: Look for missing loop limits, unhandled exceptions, or raw unstructured dictionary mutations without schemas.
- Very specific: line 125
Verify that SKILL.md contains frontmatter with name and description.
- Distinctive: line 126
Verify that all relative links to checklists and code examples are valid and clickable.
- Distinctive: line 127
Verify that every conditional transition and loop in the design includes a defined limit and exit criteria.
- Distinctive: line 128
Verify that there are zero silent failure pathways in the orchestration code.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Design Agents Using Patterns
Common Contract (Load First)
When this skill is activated, first load skill-common and apply the shared conventions it defines: canonical section order, frontmatter rules, anti-pattern guidance, and the Review In Mind loop in review-in-mind. This skill adds only domain-specific rules below.
[!IMPORTANT] TOP-3 Golden Rules of Agentic Design (Must be followed by all invoking agents):
- Loop Safety Boundaries: Never configure an agent loop (Reflection, Planning, or Exception Recovery) without a hard-coded maximum iteration limit (e.g., max 3 or 5 retries).
- WHY: Non-deterministic LLM behaviors can result in infinite correction/compilation loops, leading to token exhaustion and extreme API costs.
- Shell Sandboxing & User Approval: Never execute write operations, file deletions, or terminal shell commands without running inside a virtualized container (e.g. Docker, dev container) or requesting explicit human user approval.
- WHY: Autonomous agents carry user-level shell privileges; unconstrained command executions can cause catastrophic system failures or code security violations.
- Memory Scoping & Event Integrity: Never mutate the session state directly outside the runner's event processing cycle, and always partition state namespaces using prefixes (
user:,app:,temp:).
- WHY: Direct dictionary mutation bypasses event history logs, making rollbacks and trace audits impossible. Scoping namespaces prevents cross-session variables pollution.
Who
Architects, system developers, or coding agents who need to design and orchestrate reliable, autonomous, and self-correcting agent systems.
What
Analyze functional goals, select the appropriate pattern(s) (e.g., Routing, Reflection, Multi-Agent Collaboration), design the state schema and node topology, build exception handling guards, and implement/verify the code using LangChain/LangGraph or Google ADK.
When
- Triggered by requests like: "design agents using patterns to...", "design a multi-agent system for...", "implement a self-correcting prompt chain for...", "design a router for these sub-agents", or "evaluate the resilience of this agentic architecture".
- Do not use for simple static scripting, simple template prompts that do not involve loops, routing, or tool calls, or basic API calls lacking autonomous logic.
Where
Applies to orchestration files, state graphs, system architecture documents, and agent scripts in the workspace.
Why
- Unstructured agent calls are non-deterministic, fragile, and prone to complete failure when tools or APIs fail.
- Agents can enter infinite loops (e.g., failing the same tool over and over) or incur excessive API costs unless explicitly bound by iteration limits and clear exit conditions.
- Standardizing the orchestration structures (using templates for LangChain/LangGraph and Google ADK) keeps the codebase readable, maintainable, and robust.
Inputs
- System Goal & Requirements (required): The specific tasks or workflow the agentic system must complete.
- Tools & API Specs (optional): Capabilities and functions the agents can invoke.
- Pattern Checklists Reference (required): Located at pattern-checklists.
- Framework Target (optional): The target framework (e.g., LangChain/LangGraph, Google ADK, or raw Python).
- Agentic Design Patterns Book (optional): Reference book unpacked at Agentic Design Patterns.
Output (Logical Evidence)
- Agentic System Architecture Specification: Visual/textual mapping of agent nodes, state schema, routing rules, and fallback paths.
- Orchestration Source Code: Executable code (e.g., using LangChain
RunnableBranchor Google ADKAgent/SequentialAgent) that implements the designed topology. - Resilience Log: Documentation detailing loop iteration limits, error handling guards, and fallback conditions.
Optimization Readiness
- Failure Signals: Pattern choice does not match workflow complexity, loops lack hard stop conditions, failures are swallowed instead of routed, or state handoffs violate the declared schema.
- Evidence To Collect: Pattern-selection notes, topology diagrams, state schemas, failure traces, and examples of fallback paths that were triggered or missing.
- Safe Mutation Boundaries: Refine pattern-selection heuristics, topology templates, schema guidance, and recovery-path rules without changing the core requirement to build bounded, typed orchestration.
- Acceptance Criteria: Accept revisions only if the chosen pattern matches the task shape, every loop has an explicit limit, errors flow through visible recovery paths, and shared state remains schema-validated.
- Rejected Revision Handling: Record mismatched pattern choices, silent-failure paths, and weak loop controls so they are not repeated.
- Transfer Check: Confirm the workflow still works for prompt chaining, routing, reflection, planning, and multi-agent collaboration patterns.
- Stop Rule: If model limits, tool schemas, or cost and retry budgets are undefined, stop and ask before finalizing the orchestration design.
Constraints (Logical Boundaries)
- Runaway Loop Protection: Every agentic loop (Reflection, Planning, or Exception Recovery) must have a strict, hard-coded maximum iteration limit (e.g., maximum 3 or 5 retries) to prevent runaway token spend.
- No Silent Failures: All tool errors, API timeouts, or parsing exceptions must be caught, logged, and routed through a defined recovery or escalation path.
- Schema Validation: All data passed between agents or tools must be validated against a strict state schema (e.g., Pydantic models or typed state dictionaries).
One More Thing
If the primary model options, tool schemas, or maximum token/cost budgets are undefined or conflicting, stop and ask the user to clarify before writing the orchestration code.
How (Structural Workflow)
Phase 1: Analyze & Select Patterns
- Identify the complexity and requirements of the target system:
- Linear & Predictable: Select Prompt Chaining.
- Branching & Intent-Driven: Select Routing (LLM-based, semantic, or rule-based).
- Resource / Time Intensive: Select Parallelization (fork-join execution).
- Quality-Critical: Select Reflection & Self-Correction (evaluator-generator loop).
- Complex, Multi-step / Multi-Domain: Select Multi-Agent Collaboration (Coordinator-Specialist or Supervisor architecture) or Planning.
- Review the detailed pattern guidelines and checklist details in pattern-checklists.
- Draft a conceptual design mapping the workflow.
Phase 2: Define State Schema & Node Topology
- Design the Shared State Schema:
- Determine what information must persist across agent nodes (e.g.,
user_query,history,retrieved_docs,current_step,error_flag,retry_count). - Define type definitions and validate using Pydantic or native typing.
- Determine what information must persist across agent nodes (e.g.,
- Define the Node Topology:
- List each agent node (e.g.,
Classifier,Planner,Coder,Validator) and tool-execution node. - Define the edge conditions: direct sequential transitions, conditional transitions (routers), and loops (reflection).
- List each agent node (e.g.,
Phase 3: Design Robustness & Exceptions (Chapter 12)
- Incorporate Exception Handling and Recovery rules:
- Error Detection: How does the system catch malformed tool outputs, API status codes, or parsing errors?
- Error Handling: Implement logging of tracebacks, retries for transient errors, and fallback strategies (e.g., delegating to a general fallback handler).
- Recovery: Define rollback logic for state variables and escalation pathways to notify a human operator or return a graceful failure message.
- Define loop exit conditions: enforce a hard limit on
retry_countoriteration_limit.
Phase 4: Implement & Verify Orchestration
- Select the template implementation from code-examples that matches your framework (Google ADK or LangChain/LangGraph).
- Write the orchestration code, ensuring the system state is updated cleanly at each node.
- Validate the implementation:
- Common Rationalization Check: If you think "this tool will never fail, so I don't need a try-except block," stop and remember: In real-world settings, APIs time out and tools return unexpected schemas. Wrap all tool executions in a try-except structure and handle the failure gracefully.
- Red Flags Check: Look for missing loop limits, unhandled exceptions, or raw unstructured dictionary mutations without schemas.
Resources
- pattern-checklists - Actionable checklists for each design pattern.
- code-examples - Framework templates for Google ADK and LangChain/LangGraph.
- Agentic Design Patterns - Original reference textbook.
Review In Mind (ReviewInMindGenie)
Execute the common review loop in review-in-mind before delivering.
Review lens for this skill:
- Is the chosen pattern justified by the goal and state topology rather than a default preference?
- Are routing, exception handling, and loop limits explicitly designed?
- Does the implementation match the designed schema and node graph?
Validation
- Verify that
SKILL.mdcontains frontmatter withnameanddescription. - Verify that all relative links to checklists and code examples are valid and clickable.
- Verify that every conditional transition and loop in the design includes a defined limit and exit criteria.
- Verify that there are zero silent failure pathways in the orchestration code.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

