Advanced Prompt Engineering Techniques

Chain-of-thought, tool use, and agentic prompt patterns from production AI tools

SystemPrompts Archive
12 min read

Beyond the basics of clarity and structure, advanced prompt engineering involves techniques that unlock significantly more powerful AI behavior. These techniques are found throughout the system prompts of production AI coding tools — and understanding them helps you build better AI-powered applications.

Chain-of-Thought Prompting

Chain-of-thought (CoT) prompting instructs the model to reason through a problem step-by-step before producing the final answer. Many production system prompts include phrases like 'Think through this carefully before responding' or 'First analyze the requirements, then plan the implementation, then write the code.' This significantly improves accuracy on complex tasks by forcing the model to decompose the problem before solving it.

  • Instruct the model to 'think step by step' or 'reason through this'
  • For coding tasks: 'Analyze requirements → Plan approach → Write code → Review'
  • Use <thinking> or similar tags to separate reasoning from the final output
  • CoT is especially effective for debugging, architecture decisions, and complex refactoring

Designing Prompts for Tool Use

Agentic AI tools like Cursor, Claude Code, and Devin have complex system prompts that define not just what the AI should say, but what tools it can call and how. These prompts include detailed descriptions of each available tool, when to use it, and the expected format for tool calls. The structure matters enormously — vague tool descriptions lead to incorrect tool selection.

  • Define each tool with: name, description, when to use it, parameters, and expected output
  • Include examples of correct tool call format
  • Define priority rules: when multiple tools could work, which takes precedence
  • Specify error handling: what to do if a tool returns an error or unexpected result
  • Include 'tool not needed' cases to prevent over-calling

Agentic System Prompts

Agentic prompts are designed for AI systems that operate autonomously over multiple steps to complete complex tasks. Devin's and Claude Code's system prompts are examples of sophisticated agentic prompts. They include: task decomposition instructions, state management guidance, fallback behaviors, safety constraints, and instructions for when to ask for human input vs. proceed autonomously.

  • Define the planning phase: how to break down a task before starting
  • Include explicit 'pause and verify' instructions for high-risk operations
  • Define what constitutes task completion vs. partial completion
  • Specify how to handle ambiguous or contradictory requirements
  • Include recovery instructions for when steps fail
  • Define human escalation triggers — when to ask for input rather than guess

Context Window Management in System Prompts

Advanced system prompts account for context window limitations. They include instructions for how to prioritize information when the context gets long, what to summarize vs. retain in full, and how to communicate to users when context limits are approaching. Cursor's system prompt, for example, includes specific instructions for managing long codebases within context constraints.

Advanced Persona Design

The persona section of a system prompt does more than define a name. Production AI tools use persona design to establish: expertise level (which affects how the AI explains things), communication style (verbose vs. concise), attitude toward uncertainty (confidence level, hedging), and role clarity (what the AI is vs. what it is not). Cursor's prompt explicitly defines that it is an 'AI coding assistant' not a 'general assistant' — a subtle but important distinction that shapes all responses.

No. CoT adds tokens and latency. For simple, factual queries or short code completions, it's unnecessary overhead. Use CoT for complex reasoning tasks: architecture decisions, debugging tricky issues, algorithm design. Many production tools conditionally invoke CoT based on task complexity.
Production system prompts typically use a structured format: tool name, one-line description, when to use it (not just what it does), parameter descriptions with types, and a usage example. JSON schema or XML-tagged descriptions are common. The 'when to use' section is critical — without it, models often call tools when simpler approaches would suffice.
Real agentic system prompts (like Devin's and Claude Code's) include explicit safety layers: operations the agent can never perform without confirmation, operations that require summarizing what will happen before proceeding, and hard stops for potentially irreversible actions. The safety instructions are typically the most detailed section of the prompt.