Recommended resources
The freely available resources this lesson will direct you to.
Introduction
Welcome to the first lesson of Module 4. In our previous lesson, we mastered how to structure the dynamic information an agent receives—user inputs, retrieved documents, and tool outputs—using formats like XML and Markdown to ensure clarity and reliability. We established that how you "serialize" data for an LLM is a critical design choice.
Now, we shift our focus from the dynamic data to the static foundation of an agent's identity: its system instructions. This is where you, as the architect, define the agent's core purpose, personality, and operational rules. Our goal for this lesson is to learn how to write system instructions that define an agent's role, tone, boundaries, and decision-making rules.
Think of this as moving from designing the data packets an agent processes to drafting the agent's constitution or its detailed job description. This is a foundational skill in shifting from being a task executer to a designer of agentic systems.
1. From Conversation to Instruction: Structured Prompts for Agents
When interacting with a chatbot like Claude or ChatGPT, you engage in conversational prompting—a back-and-forth dialogue where you clarify and refine requests. Agentic systems, which must operate autonomously and reliably at scale, require a different approach: structured prompting.
Prompt Engineering for AI Agents (FULL GUIDE)
To begin, let's clarify why agents need a more rigorous prompting style. This video from Brennan Wells provides a concise explanation of the shift from conversational to structured prompting.
Watch the segment from 01:18 to 02:48. Focus on the core argument: with agents, you often have 'one shot to get it right,' which necessitates clear, consistent, and structured instructions to ensure reliability and manage costs.
The key takeaway is that agent prompts aren't just starting points for a conversation; they are durable, executable instructions. The higher stakes—wasted compute, broken workflows, unreliable outputs—demand a more disciplined approach to their construction.
2. The Anatomy of a System Prompt
A robust system prompt acts as a comprehensive charter for the agent. It's not a single command but a multi-faceted document that sets the stage for every action the agent takes. A well-structured prompt typically contains several key sections that work together to guide the agent's behavior.
Prompt Engineering for AI Agents (FULL GUIDE)
The same video provides an excellent breakdown of the components of a long structured prompt, which is the standard for any non-trivial agent.
Please watch the following segments carefully: 06:42 - 08:08: This introduces the core components of a long structured prompt: Role/Persona, Objective/Task, Context, Instructions/Rules, Examples, and Variables. 08:08 - 10:09: Here, the video details each component. Pay attention to the 'useful phrases' like 'You are a world-class...' and 'think step-by-step,' which are pragmatic techniques for improving output quality. 10:09 - 11:48: This section extends the framework for multi-agent systems by adding components like SOP (Standard Operating Procedure) and Tools/Sub-agents. This is highly relevant to your goal of designing complex workflows.
This structured approach, using clear headings (often in Markdown), allows the model to easily parse its instructions. The core components are:
- Role/Persona: Defines who the agent is ("You are a world-class financial analyst..."). This primes the model to adopt a specific style, tone, and knowledge base.
- Objective/Task: A clear, high-level statement of the agent's goal.
- Context: Provides background information on why the task is important.
- SOP (Standard Operating Procedure): A step-by-step process the agent must follow. This is crucial for creating predictable behavior and is analogous to an algorithm definition.
- Instructions/Rules: Specific constraints, formats, and "don'ts" that the agent must adhere to.
- Tools/Sub-agents: A manifest of the capabilities available to the agent, with clear descriptions of when and how to use them.
- Examples: Few-shot examples of desired input/output behavior, especially for edge cases.
- Variables: Placeholders for dynamic data.
3. Principles of Effective Instruction Design
Knowing the components is the first step. The art of system instruction lies in the principles you apply when writing them. Given your background in system design, you'll recognize that this is less about finding "magic words" and more about sound conceptual engineering.
Effective context engineering for AI agents
Anthropic's engineering blog offers high-level guidance on this topic. This article on 'Effective context engineering' frames the problem in a way that should resonate with your design-oriented approach.
Read the section titled 'System prompts'. Focus on the concept of writing instructions at the 'right altitude'—the balance between overly prescriptive logic and vague guidance. Note the recommendation to start minimal and add instructions based on observed failure modes.
Building on this, let's explore more advanced principles for guiding an agent's reasoning process.
Prompting for Agents | Code w/ Claude
The 'Prompting for Agents' talk from Anthropic provides deeper insights into the mindset required to design agent behavior.
Watch these two key segments: 06:39 - 10:34: This section introduces crucial principles like 'thinking like your agents' and providing 'reasonable heuristics.' Pay close attention to the idea that prompting is 'conceptual engineering'—defining the concepts and behaviors the model should follow, such as 'irreversibility' or 'search budgets'. 10:25 - 12:50: This part explains how to 'guide the thinking process.' Instead of just letting an agent 'think,' you can instruct it how to think—for example, by telling it to create a plan in its first step or to reflect on the quality of search results before acting on them.
These principles elevate prompt writing from simple instruction to true system design. You are not just telling the agent what to do, but shaping how it decides what to do. Providing explicit heuristics (e.g., "for simple queries, use under 5 tool calls") is a powerful way to define decision-making rules.
4. A Formal Framework: The Agent Contract
To give these concepts a more rigorous structure, we can borrow from computer science and economics to introduce the idea of an Agent Contract. This framework formalizes the agent's operational parameters and is particularly useful for designing production-grade systems where predictability and cost control are paramount.
Agent Contracts: A Formal Framework for Resource-Bounded ... - arXiv
The paper 'Agent Contracts: A Formal Framework for Resource-Bounded...' provides a robust, academic perspective on defining agent boundaries. This will provide a formal structure for the concepts we've discussed.
Your focus should be on Sections 4.1 and 4.2: Section 4.1 'Contract Definition': Review the formal definition of an Agent Contract as a seven-tuple. See how this formalizes the components we saw earlier (e.g., 'Input/Output Specifications', 'Skill Set'). Section 4.2 'Contract Components': Read the breakdown of each component. Pay special attention to 'Resource Constraints' (token limits, API calls, cost) and 'Temporal Constraints' (duration). These are the explicit boundaries of the agent's operation. Also, note the distinction between 'Success Criteria' and 'Termination Conditions,' which are the heart of the agent's decision-making rules for completion and failure.
The Agent Contract provides a powerful mental model. When you write a system prompt, you are essentially defining the terms of this contract:
- Role & Objective map to the contract's overall goal.
- Skills & Tools define the
Skill Set. - Instructions & Rules translate into
Resource Constraints,Temporal Constraints,Success Criteria, andTermination Conditions.
For example, a rule in your prompt like "You must not exceed 50,000 tokens or run for more than 5 minutes" is a direct implementation of the contract's resource and temporal constraints. A rule like "The task is complete when the final report is generated and has been approved by the review tool" defines the Success Criteria. This framework turns abstract instructions into measurable, enforceable boundaries.
5. From Theory to Practice: A Complete Example
Let's synthesize these concepts by analyzing a complete, well-structured system prompt for a multi-agent orchestrator.
Prompt Engineering for AI Agents (FULL GUIDE)
Let's return to the 'Prompt Engineering for AI Agents' video for a comprehensive example that puts all these pieces together.
Watch the detailed walkthrough from 12:48 to 16:15. As you watch, try to map the sections of the prompt to the frameworks we've discussed: Anatomy: Identify the Role, Objective, Context, SOP, Instructions, and Sub-agents sections. Principles: Notice the use of 'world-class', 'think step-by-step', and the emotional framing ('it is vital to the user's career'). Agent Contract: How does the SOP define success criteria? How do the Instructions act as termination/failure conditions (e.g., 'never assume missing details, ask for clarification')? How does the Sub-agents section define the available Skill Set?
This example demonstrates how a system prompt serves as the complete operational specification for an agent, defining its identity, its process logic, its boundaries, and its relationships with other agents in the system.
6. The Iterative Nature of Prompt Design
Finally, it's crucial to understand that a system prompt is not a static artifact. It is a living document that evolves as you discover edge cases and failure modes. The most effective strategy is not to write a perfect, exhaustive prompt from the start, but to begin simply and add rules reactively.
Prompt Engineering for AI Agents (FULL GUIDE)
This final clip explains the strategic choice between 'proactive' and 'reactive' prompting.
Watch from 02:48 to 05:01. The core idea is to 'fix one problem at a time and iterate based on real failures.' This approach is more debuggable, cost-effective, and ultimately leads to a more robust and tailored set of instructions than trying to anticipate every possible failure upfront.
This iterative process of testing, observing failures, and refining the system instructions is the fundamental loop of agent engineering.
Conclusion
In this lesson, we have established a comprehensive framework for designing and writing system instructions for AI agents. We've moved beyond simple commands to architecting an agent's core operational logic.
Key Takeaways:
- System instructions are the "constitution" of an agent, defining its role, allowable actions, and decision-making logic.
- Adopt a structured approach with clear sections for Role, Objective, SOPs, Rules, and Tools to ensure clarity and reliability.
- Write at the "right altitude" by providing guiding heuristics and shaping the agent's thinking process, rather than hardcoding brittle logic.
- Use the Agent Contract as a formal model to define explicit boundaries for resources, time, and success, turning your instructions into enforceable constraints.
- Embrace iterative refinement. Start with a minimal set of instructions and add rules and examples reactively as you identify specific failure modes through testing.
Preview of the Next Lesson
We've now learned how to define an agent's role and rules. The next logical step is to explore the specific techniques used to enforce those rules, especially the negative constraints ("what not to do"). In the next lesson, we will dive deeper into how to use constraint-based prompting to prevent an agent from acting outside its scope, a critical skill for building safe and reliable systems.