agentleFS
kumaran-iskumaran-is/claude-code-onboarding/.claude/skills/prompt-engineering-patterns/SKILL.md

prompt-engineering-patterns

Skill36 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.

9 other projects use a version of this.

Adopted by

Most recently taken up by

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 9 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
  1. Distinctive:

    Always structure prompts in this order:

    line 65
  2. Distinctive:

    After writing prompts or agent instructions, verify:

    line 130

“Common” is measured: kept by at least 6 in 10 of the 9 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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

PatternWhenLangGraphGoogle ADKReference
Few-ShotOutput format needs demonstrationHumanMessage with examples in node promptinstruction= block with examplesreference/few-shot-learning.md
Chain-of-ThoughtMulti-step reasoning, math, debuggingSystemMessage with "think step by step"instruction= with numbered stepsreference/chain-of-thought.md
Tree-of-ThoughtComplex exploration / planningParallel branch nodes + aggregatorParallelAgent + synthesizerreference/chain-of-thought.md
Self-ConsistencyHigh-accuracy critical tasksMultiple llm.invoke() + majority voteMultiple ADK runs + votereference/chain-of-thought.md
System Prompt DesignDefine agent role, behavior, constraintsSystemMessage as first messageLlmAgent(instruction=...)reference/system-prompts.md
Prompt TemplatesReusable structured promptsf-string + SystemMessageinstruction= with {variable}reference/prompt-templates.md
Prompt OptimizationReduce tokens, improve consistencyOffline A/B test frameworkOffline A/B test frameworkreference/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

FileContentWhen to Load
reference/chain-of-thought.mdCoT, ToT, Self-Consistency patterns with LangGraph + ADK codeComplex reasoning, multi-step tasks
reference/few-shot-learning.mdExample selection, dynamic retrieval, edge cases — LangGraph + ADKInconsistent output format, classification tasks
reference/prompt-optimization.mdA/B testing, token reduction, versioning, metricsReducing cost, improving consistency
reference/system-prompts.mdRole definition, constraints, output format — LangGraph + ADKDesigning new agent system prompts
reference/prompt-templates.mdReusable templates, variable interpolation, multi-turn — LangGraph + ADKBuilding template systems
reference/prompt-template-library.md15+ battle-tested copy-paste templates for common tasksFinding 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

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.