Introduction
In our previous lesson, we established the fundamental mechanism for giving our agent a memory: the role-based message history. We saw that by managing a list of system, user, and assistant messages, we can create the illusion of a continuous, stateful conversation. The system message, in particular, was introduced as the place to "set the stage" for the entire interaction.
This lesson dives deep into that very concept. We will move from simply acknowledging the system role to mastering it. Your goal is to learn and implement system prompt design patterns for defining an agent's identity, its operational constraints, and its core objectives. Think of the system prompt not just as an instruction, but as the agent's constitution, its operational blueprint, or its core programming. For a Systems Architect, this is akin to defining the service contract and operational parameters for a critical component in a distributed system.
The System Prompt: An Agent's Constitution
The system prompt is the most influential piece of context you can provide to an LLM. It's the first thing the model "reads" and it anchors its behavior for the entire duration of a task. Crafting this prompt is a discipline that sits at the intersection of programming, technical writing, and instruction design.
Anthropic refers to this broader discipline as "context engineering," which they view as the natural evolution of prompt engineering.
Effective context engineering for AI agents
This article from Anthropic's engineering blog frames the importance of the system prompt within the larger task of managing an LLM's context.
Read the introduction and the section Context engineering vs. prompt engineering. Focus on the distinction they draw: prompt engineering is about writing instructions, while context engineering is about curating the entire set of information the model receives, of which the system prompt is a foundational part.
A key concept from this article is finding the "right altitude" for your instructions—specific enough to guide behavior, but not so rigid that the prompt becomes brittle and complex. This balance is central to engineering a robust agent.
Core Patterns for System Prompt Design
By analyzing the system prompts of production-grade AI agents like Vercel's v0, OpenAI's ChatGPT, and Anthropic's own coding assistants, we can distill a set of recurring, effective design patterns. The "awesome-ai-system-prompts" repository provides an excellent survey of these real-world examples. We will use its analysis as our guide.
dontriskit/awesome-ai-system-prompts: Curated collection ... - GitHub
This guide analyzes a diverse collection of real-world system prompts to identify recurring best practices for creating powerful and predictable AI agents.
First, read the introduction to grasp the "blueprint" analogy. Then, carefully review the main section, Core Principles. As you read, focus on how each of the eight principles contributes to defining the agent's identity, objectives, or constraints.
Let's dissect these principles and see how to implement them.
1. Defining Identity and Persona (The "Who")
The first step is to give the agent a clear identity and role. This anchors its behavior and sets the tone for the interaction. Is it a formal expert, a creative assistant, or a direct, no-nonsense programmer?
The examples from the reading show this can be as simple as:
You are v0, Vercel's AI-powered assistant.You are a powerful agentic AI coding assistant.
This explicit role-setting is the most basic form of the "Role Prompting" technique.

For a more dynamic approach, you can use a classic software design pattern: the Strategy Pattern. Instead of a single, hardcoded identity, you can define multiple "personality" functions, each returning an agent configured with a different system prompt. This is a clean, extensible way to manage agent personas, which will be familiar from your software engineering background.
Avoid Messy Code: Design Patterns for AI Agents in Python
In this video, ArjanCodes demonstrates how to apply the Strategy Pattern to dynamically switch an AI agent's personality.
Watch the segment from the final pattern. Notice how the professional_agent, fun_agent, and budget_agent functions are essentially factories that produce an agent with a specialized system prompt. This pattern decouples the agent's core logic from its specific persona, allowing you to swap behaviors cleanly.
2. Defining Objectives and Constraints (The "What" and "How")
This is where you lay down the law for your agent. These instructions define the agent's goals and the rules it must follow to achieve them. This involves several of the principles from our reading:
- Domain-Specific Expertise: Provide rules for the agent's area of operation. For a code-generation agent, this could include preferred libraries, coding style, or forbidden patterns.
- Example (from Vercel's v0):
v0 tries to use the shadcn/ui library unless the user specifies otherwise...
- Example (from Vercel's v0):
- Environment and Context Awareness: Tell the agent about its environment. This helps it generate compatible commands and understand its limitations.
- Example (from Cline):
SYSTEM INFORMATION Operating System: ${osName()} Default Shell: ${getShell()} ...
- Example (from Cline):
- Safety and Refusal Protocols: Define what the agent should not do. This includes handling harmful requests and specifying how to refuse them.
- Example (from Claude):
If Claude cannot or will not help the human with something, it does not say why... keeps its response to 1-2 sentences.
- Example (from Claude):
The leaks of the Claude Code system prompt, discussed in the video below, show how specific "nudges" can be used to refine an agent's behavior.
How Claude Code Works - Jared Zoneraich, PromptLayer
This segment discusses specific instructions, or "nudges," found in the leaked system prompt for the Claude Code agent.
Watch the section from we could go back to the system prompt. The speaker lists several key constraints and objectives: be concise, prefer using tools over text explanations, match existing code style, and avoid adding comments. These are all perfect examples of rules you would place in your system prompt.
3. Structuring for Clarity and Maintainability
As your agent's capabilities grow, its system prompt can become long and complex. Just as with source code, structure is essential for maintainability. Use formatting to create clear, parsable sections.
- Markdown Headings: Use
#,##, etc., to create a hierarchy of instructions (e.g.,## Tool Rules,## Safety Protocols). - XML Tags: Wrap distinct rule sets in XML-like tags (e.g.,
<instructions>,</instructions>). This is a common pattern that makes prompts easier for both humans and models to parse. - Logical Grouping: Keep related rules together. All tool-related instructions should be in one section, all output formatting rules in another.
The Anthropic article on context engineering also strongly advocates for this structured approach to avoid creating brittle, hard-to-maintain prompts.
Advanced Patterns: Modular and Dynamic Prompts
For complex, production-grade agents, a single, monolithic system prompt is often insufficient. We need more dynamic and modular approaches, much like breaking down a monolithic application into microservices.
Modular Constitutions and Extendable "Skills"
Instead of one giant prompt, you can split the agent's "constitution" into multiple files. For instance, one file for personality, another for tool usage rules, and a third for safety policies. This separation of concerns makes the system much easier to manage and update.
An even more advanced version of this is the concept of "Skills," which function as extendable, on-demand system prompts.
How Claude Code Works - Jared Zoneraich, PromptLayer
This video introduces two powerful, modular approaches to system prompting used by the Claude Code agent.
First, watch from the first is the constitution. This describes the claude.md file, which acts as a simple, user-editable set of instructions—a modular system prompt. Next, watch the segment on "Skills" from all right skills. A "skill" is a piece of context (another prompt) that can be dynamically loaded when the agent needs to perform a specific task, like deep research or a documentation update. This avoids cluttering the main context window with information that is not always relevant.
This "Skills" pattern is powerful. It allows you to build a library of specialized expertise that the agent can tap into as needed, without exceeding the context window. It's a form of dynamic context injection that you, as the system architect, would design and manage.
Task Decomposition via Prompting
One of the most critical objectives you can define for an agent is how it should plan and execute complex tasks. Instead of just giving it a final goal, you can instruct it to first break the problem down into a to-do list and then execute that list step-by-step. Remarkably, this entire workflow can be managed through system prompt instructions, without requiring a complex, hardcoded state machine.
How Claude Code Works - Jared Zoneraich, PromptLayer
This segment explains how the Claude Code agent uses a to-do list, managed entirely through prompt instructions, to handle multi-step tasks.
Watch from let's talk about to-do lists. The key insight here is that the to-do list is "structured but not structurally enforced." It works because the model is good at following instructions. The system prompt tells the model to generate a list, mark items as complete, and work through them sequentially. This is a first-principles approach to agentic planning.
Conclusion
In this lesson, we have elevated the system prompt from a simple instruction to a sophisticated engineering tool. By designing it with clear patterns, you can steer an agent's behavior with a high degree of precision, creating a reliable and predictable system component.
Here are your key takeaways:
- The System Prompt is the Blueprint: It defines the agent's identity, objectives, and constraints, acting as its operational "constitution."
- Design Patterns Provide Structure: Effective prompts follow clear patterns, including defining a role (identity), establishing rules (constraints), providing context (environment), and specifying goals (objectives).
- Structure is Key to Maintainability: Use Markdown headings or XML tags to organize complex prompts, treating them like maintainable code.
- The Strategy Pattern Enables Dynamic Personas: You can use this software design pattern to cleanly swap out system prompts and change an agent's behavior and personality on the fly.
- Modular Prompts are Scalable: For complex agents, move beyond monolithic prompts to modular "constitutions" and dynamic, on-demand "skills" to manage context effectively.
- Workflow Can Be Prompted: You can instruct an agent to follow complex workflows, like creating and executing a to-do list, purely through instruction-following.
We now have the tools to give our agent a clear purpose and set of rules. However, it is still largely static. In our next lesson, we will begin building the engine that brings this agent to life. We will distinguish between static chains and truly autonomous agents, and then implement the core observe-think-act loop—the asynchronous heart that will power our agent's actions.