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.md
Key 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 shape
Quick 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 agents
security-reviewer — prompt injection defense, no sensitive data in prompts
1---2name: prompt-engineering-patterns3description: 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.4---56## Iron Law78**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.**910# Prompt Engineering Patterns — LangGraph + Google ADK1112## When to Use This Skill1314- Designing or reviewing system prompts / ADK agent instructions15- LLM outputs are inconsistent or hallucinating — apply CoT or self-consistency16- Output format needs demonstration — apply few-shot learning17- Complex multi-step reasoning required — apply chain-of-thought18- Need to explore multiple solution paths — apply Tree-of-Thought19- Reducing prompt token cost while keeping quality — prompt optimization20- Building reusable, testable prompt templates2122## Framework Decision Tree2324```25What's the problem?26├── Output format is wrong / inconsistent27│ └── Apply Few-Shot Learning → reference/few-shot-learning.md28├── Model skips reasoning steps / wrong answers on complex tasks29│ └── Apply Chain-of-Thought → reference/chain-of-thought.md30├── Need to explore multiple solution branches31│ └── Apply Tree-of-Thought → reference/chain-of-thought.md#tot32├── Need highest accuracy (can afford 3-5x cost)33│ └── Apply Self-Consistency → reference/chain-of-thought.md#self-consistency34├── System prompt is vague or producing variable behavior35│ └── Apply System Prompt Design → reference/system-prompts.md36├── Prompts are too long / expensive / slow37│ └── Apply Prompt Optimization → reference/prompt-optimization.md38└── Need reusable structured prompts across agents39 └── Apply Template Patterns → reference/prompt-templates.md40```4142## Key Patterns4344| Pattern | When | LangGraph | Google ADK | Reference |45|---------|------|-----------|------------|-----------|46| Few-Shot | Output format needs demonstration | `HumanMessage` with examples in node prompt | `instruction=` block with examples | `reference/few-shot-learning.md` |47| Chain-of-Thought | Multi-step reasoning, math, debugging | `SystemMessage` with "think step by step" | `instruction=` with numbered steps | `reference/chain-of-thought.md` |48| Tree-of-Thought | Complex exploration / planning | Parallel branch nodes + aggregator | `ParallelAgent` + synthesizer | `reference/chain-of-thought.md` |49| Self-Consistency | High-accuracy critical tasks | Multiple `llm.invoke()` + majority vote | Multiple ADK runs + vote | `reference/chain-of-thought.md` |50| System Prompt Design | Define agent role, behavior, constraints | `SystemMessage` as first message | `LlmAgent(instruction=...)` | `reference/system-prompts.md` |51| Prompt Templates | Reusable structured prompts | f-string + `SystemMessage` | `instruction=` with `{variable}` | `reference/prompt-templates.md` |52| Prompt Optimization | Reduce tokens, improve consistency | Offline A/B test framework | Offline A/B test framework | `reference/prompt-optimization.md` |5354## Instruction Hierarchy (Universal Rule)5556Always structure prompts in this order:5758```59[System Context / Role] <- who the agent IS60[Task Instruction] <- what it MUST DO61[Constraints] <- what it MUST NOT DO62[Examples / Few-Shot] <- show, don't just tell63[Input Data] <- the actual input64[Output Format] <- exact expected output shape65```6667## Quick Examples6869### LangGraph — CoT Node70```python71from langchain_core.messages import SystemMessage, HumanMessage7273COT_SYSTEM = SystemMessage(content="""You are a senior software architect.74When analyzing a problem:751. State your understanding of the problem762. Identify constraints and requirements773. Consider 2-3 solution approaches with trade-offs784. Select the best approach with justification795. Outline implementation steps8081Always show your reasoning explicitly before giving a recommendation.""")8283def analysis_node(state: AgentState) -> AgentState:84 response = llm.invoke([COT_SYSTEM, HumanMessage(content=state["problem"])])85 return {"analysis": response.content}86```8788### Google ADK — CoT Agent89```python90from google.adk.agents import LlmAgent9192analysis_agent = LlmAgent(93 name="analysis_agent",94 model="gemini-3.1-flash",95 instruction="""You are a senior software architect.96When analyzing a problem, follow these steps explicitly:971. State your understanding of the problem982. Identify constraints and requirements993. Consider 2-3 solution approaches with trade-offs1004. Select the best approach with justification1015. Outline implementation steps102103Always show your reasoning before giving a recommendation.104Output format: structured analysis with sections for Understanding, Options, Decision, and Next Steps."""105)106```107108## Reference Files109110| File | Content | When to Load |111|------|---------|--------------|112| `reference/chain-of-thought.md` | CoT, ToT, Self-Consistency patterns with LangGraph + ADK code | Complex reasoning, multi-step tasks |113| `reference/few-shot-learning.md` | Example selection, dynamic retrieval, edge cases — LangGraph + ADK | Inconsistent output format, classification tasks |114| `reference/prompt-optimization.md` | A/B testing, token reduction, versioning, metrics | Reducing cost, improving consistency |115| `reference/system-prompts.md` | Role definition, constraints, output format — LangGraph + ADK | Designing new agent system prompts |116| `reference/prompt-templates.md` | Reusable templates, variable interpolation, multi-turn — LangGraph + ADK | Building template systems |117| `reference/prompt-template-library.md` | 15+ battle-tested copy-paste templates for common tasks | Finding a starting template fast |118119## Post-Code Review120121After writing prompts or agent instructions, verify:122- `agentic-ai-reviewer` — graph correctness, system prompt quality in LangGraph agents123- `security-reviewer` — prompt injection defense, no sensitive data in prompts