prompt-engineering-patterns
Skill35 starsChanged 6 months agoMITView on GitHub
Advanced prompt engineering for production LLM applications with LangGraph and Google ADK. Covers few-shot learning, chain-of-thought, Tree-of-Thought, self-consistency, system prompt design, prompt optimization, and reusable templates. Use when designing agent system prompts, implementing structured reasoning, optimizing LLM outputs, or debugging inconsistent model responses.
19 other projects use a version of this.
Adopted by
Most recently taken up by
- gromov0737/skillstheir own version, first seen Nov 29, 2026
- hybridlabor-api/aostheir own version, first seen Nov 29, 2026
- The-AIOS/aiostheir own version, first seen Nov 17, 2026
- AtilaMedeiros/skillstheir own version, first seen Nov 16, 2026
- JustinWangJP/cc-agent-teams-action-monitortheir own version, first seen Nov 8, 2026
- ControllableModel/SWE-Skills-Benchtheir own version, first seen Nov 8, 2026
Used with
Projects with it also use error-handling-patterns, tailwind-design-system and 1 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
xfstudioSkillerror-handling-patterns
Master error handling patterns across languages including exceptions, Result types, error propagation, and graceful degradation to build resilient applications. Use when implementing error handling, designing APIs, or improving application reliability.
Also in 3 projects that use this
xfstudioSkilltailwind-design-system
Build scalable design systems with Tailwind CSS, design tokens, component libraries, and responsive patterns. Use when creating component libraries, implementing design systems, or standardizing UI patterns.
Also in 3 projects that use this
VercelSkillfind-skills
Helps users discover and install agent skills when they ask questions like "how do I do X", "find a skill for X", "is there a skill that can...", or express interest in extending capabilities. This skill should be used when the user is looking for functionality that might exist as an installable skill.
Also in 3 projects that use this
Other versions19 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 19
- The-AIOS/aios★ 130same name
- nilecui/SkillsBase★ 27same name
- hybridlabor-api/aos★ 9same name
- xfstudio/skills★ 9same name
- ControllableModel/SWE-Skills-Bench★ 8same name
- JustinWangJP/cc-agent-teams-action-monitor★ 6same name
- GPTtang/skill-atlas★ 4same name
- KumailQazi/krmaazha-binance-mcp★ 4same name
- ai4brands-design/claude-skills★ 2same name
- CodeWithBehnam/cc-docs★ 2same name
9 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository157 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- a2ui-angularSkill
- accessibility-auditSkill
- adk-deploy-guideSkill
- adk-dev-guideSkill
- adk-eval-guideSkill
- adk-observability-guideSkill
- agentic-ai-coding-standardSkill
- agentic-ai-devSkill
- ai-auditSkill
- ai-chatSkill
- ai-decision-recordSkill
- ai-incident-responseSkill
- ai-launch-checkSkill
- ai-playbookSkill
- angular-best-practicesSkill
- angularSkill
- angular-spaSkill
- angular-ui-patternsSkill
- api-design-principlesSkill
- app-store-optimizationSkill
- architect-reviewSkill
- architecture-decision-recordsSkill
- architecture-designSkill
- asc-cli-usageSkill
- asc-crash-triageSkill
- asc-id-resolverSkill
- asc-release-flowSkill
- asc-signing-setupSkill
- asc-submission-healthSkill
- asc-testflight-orchestrationSkill
- browser-testingSkill
- changelog-generatorSkill
- claude-actions-auditorSkill
- clean-codeSkill
- codebase-onboardingSkill
- code-explainerSkill
- code-reviewerSkill
- code-simplifierSkill
- comment-analyzerSkill
- database-schema-designerSkill
- ddd-architectSkill
- decision-frameworksSkill
- dedup-code-agentSkill
- deployment-ci-cdSkill
- design-systemSkill
- dockerSkill
- documentation-generationSkill
- domain-finderSkill
- error-detectiveSkill
- eval-guideSkill
- feature-forgeSkill
- firebase-basicsSkill
- firebase-hosting-basicsSkill
- fixing-accessibilitySkill
- fixing-motion-performanceSkill
- flutter-animationsSkill
- flutter-genuiSkill
- flutter-mobileSkill
- flutter-security-expertSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
2 rules. 0 are common, 2 are distinctive, and 0 are very specific to this project.
0
Common
Most of the 19 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 65
Always structure prompts in this order:
- Distinctive: line 130
After writing prompts or agent instructions, verify:
“Common” is measured: kept by at least 6 in 10 of the 19 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Iron Law
NO SYSTEM PROMPT WITHOUT ROLE + TASK + OUTPUT FORMAT — vague system prompts produce inconsistent LLM outputs and degrade agent reliability in both LangGraph and ADK. Every agent instruction must state what the agent IS, what it DOES, and what format it RETURNS.
Prompt Engineering Patterns — LangGraph + Google ADK
When to Use This Skill
- Designing or reviewing system prompts / ADK agent instructions
- LLM outputs are inconsistent or hallucinating — apply CoT or self-consistency
- Output format needs demonstration — apply few-shot learning
- Complex multi-step reasoning required — apply chain-of-thought
- Need to explore multiple solution paths — apply Tree-of-Thought
- Reducing prompt token cost while keeping quality — prompt optimization
- Building reusable, testable prompt templates
Framework Decision Tree
What's the problem?
├── Output format is wrong / inconsistent
│ └── Apply Few-Shot Learning → reference/few-shot-learning.md
├── Model skips reasoning steps / wrong answers on complex tasks
│ └── Apply Chain-of-Thought → reference/chain-of-thought.md
├── Need to explore multiple solution branches
│ └── Apply Tree-of-Thought → reference/chain-of-thought.md#tot
├── Need highest accuracy (can afford 3-5x cost)
│ └── Apply Self-Consistency → reference/chain-of-thought.md#self-consistency
├── System prompt is vague or producing variable behavior
│ └── Apply System Prompt Design → reference/system-prompts.md
├── Prompts are too long / expensive / slow
│ └── Apply Prompt Optimization → reference/prompt-optimization.md
└── Need reusable structured prompts across agents
└── Apply Template Patterns → reference/prompt-templates.mdKey Patterns
| Pattern | When | LangGraph | Google ADK | Reference |
| Few-Shot | Output format needs demonstration | HumanMessage with examples in node prompt | instruction= block with examples | reference/few-shot-learning.md |
| Chain-of-Thought | Multi-step reasoning, math, debugging | SystemMessage with "think step by step" | instruction= with numbered steps | reference/chain-of-thought.md |
| Tree-of-Thought | Complex exploration / planning | Parallel branch nodes + aggregator | ParallelAgent + synthesizer | reference/chain-of-thought.md |
| Self-Consistency | High-accuracy critical tasks | Multiple llm.invoke() + majority vote | Multiple ADK runs + vote | reference/chain-of-thought.md |
| System Prompt Design | Define agent role, behavior, constraints | SystemMessage as first message | LlmAgent(instruction=...) | reference/system-prompts.md |
| Prompt Templates | Reusable structured prompts | f-string + SystemMessage | instruction= with {variable} | reference/prompt-templates.md |
| Prompt Optimization | Reduce tokens, improve consistency | Offline A/B test framework | Offline A/B test framework | reference/prompt-optimization.md |
Instruction Hierarchy (Universal Rule)
Always structure prompts in this order:
[System Context / Role] <- who the agent IS
[Task Instruction] <- what it MUST DO
[Constraints] <- what it MUST NOT DO
[Examples / Few-Shot] <- show, don't just tell
[Input Data] <- the actual input
[Output Format] <- exact expected output shapeQuick Examples
LangGraph — CoT Node
from langchain_core.messages import SystemMessage, HumanMessage
COT_SYSTEM = SystemMessage(content="""You are a senior software architect.
When analyzing a problem:
1. State your understanding of the problem
2. Identify constraints and requirements
3. Consider 2-3 solution approaches with trade-offs
4. Select the best approach with justification
5. Outline implementation steps
Always show your reasoning explicitly before giving a recommendation.""")
def analysis_node(state: AgentState) -> AgentState:
response = llm.invoke([COT_SYSTEM, HumanMessage(content=state["problem"])])
return {"analysis": response.content}Google ADK — CoT Agent
from google.adk.agents import LlmAgent
analysis_agent = LlmAgent(
name="analysis_agent",
model="gemini-3.1-flash",
instruction="""You are a senior software architect.
When analyzing a problem, follow these steps explicitly:
1. State your understanding of the problem
2. Identify constraints and requirements
3. Consider 2-3 solution approaches with trade-offs
4. Select the best approach with justification
5. Outline implementation steps
Always show your reasoning before giving a recommendation.
Output format: structured analysis with sections for Understanding, Options, Decision, and Next Steps."""
)Reference Files
| File | Content | When to Load |
reference/chain-of-thought.md | CoT, ToT, Self-Consistency patterns with LangGraph + ADK code | Complex reasoning, multi-step tasks |
reference/few-shot-learning.md | Example selection, dynamic retrieval, edge cases — LangGraph + ADK | Inconsistent output format, classification tasks |
reference/prompt-optimization.md | A/B testing, token reduction, versioning, metrics | Reducing cost, improving consistency |
reference/system-prompts.md | Role definition, constraints, output format — LangGraph + ADK | Designing new agent system prompts |
reference/prompt-templates.md | Reusable templates, variable interpolation, multi-turn — LangGraph + ADK | Building template systems |
reference/prompt-template-library.md | 15+ battle-tested copy-paste templates for common tasks | Finding a starting template fast |
Post-Code Review
After writing prompts or agent instructions, verify:
agentic-ai-reviewer— graph correctness, system prompt quality in LangGraph agentssecurity-reviewer— prompt injection defense, no sensitive data in prompts
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.

