Lesson 19: Prompting for Agentic Workflows
System prompts for agents, tool-use instructions, prompt chaining, and evaluation — production prompting for AI tools.
The Agent Prompt Is a Job Description
When you prompt an agent, you're writing the rules for a worker that decides its own steps. Structure beats cleverness here.
The Agent System Prompt Template
You are [ROLE] with access to [TOOLS].
GOAL: [what success looks like]
AVAILABLE TOOLS (name: description):
- tool_a(...): [when to use]
- tool_b(...): [when to use]
RULES:
1. Think before acting; call one tool at a time.
2. Stop and answer when you have enough information.
3. If a tool fails, try once more, then report the error.
4. Never invent tool results.
EXAMPLE:
[one full turn: Thought / Action / Observation / Answer]
Writing Tool Instructions (The Highest-Leverage Part)
Each tool description is a mini-prompt the model reads when deciding:
| Weak description | Strong description |
|---|---|
| "get_weather(city)" | "Get current weather for a city. Use when the user asks about weather or temperature." |
| "search(q)" | "Search the knowledge base for internal policies. Use for HR/IT questions. Returns up to 5 snippets." |
The model chooses tools by these descriptions — vague descriptions cause wrong tool picks.
Prompt Chaining: One Task, Many Prompts
Break big jobs into chained prompts where each output feeds the next:
1. "List 10 trending AI topics for 2026."
2. "For each, write a one-line hook."
3. "Expand #3 into a 500-word outline."
Chaining beats one giant prompt: each stage gets a focused context, and you can review/redirect between stages.
The Reflect–Revise Pattern
For high-stakes output, add a self-review pass:
- Draft: generate the answer.
- Critique: "List the weaknesses of the draft against the rubric."
- Revise: "Rewrite fixing the weaknesses."
This 'generate → critique → revise' loop measurably improves drafts — at the cost of extra tokens.
Evaluating Prompts (Bring Back Lesson 15)
| Change | How to Verify |
|---|---|
| New system prompt | Same 20-test golden set, compare scores |
| New tool description | Does the agent now call the right tool? |
| New chain order | End-to-end output quality + cost |
| Temperature change | Consistency across 5 runs |
Key Takeaways
- An agent prompt = role + goal + tool catalog + rules + an example turn.
- Tool descriptions are prompts — write them for the model, not for humans.
- Chain complex tasks into focused prompts; add a critique–revise pass for quality.
- Evaluate every change against a fixed test set.
Course complete: you now have the full toolkit — from how LLMs work to building and prompting agents. Keep learning, keep iterating.
# A production-style agent system prompt, built in code
tools_section = """AVAILABLE TOOLS:
- get_weather(city: str) -> str
Use when the user asks about weather or temperature.
- search_web(query: str) -> list[str]
Use when the user asks for current information or research.
- calculate(expression: str) -> float
Use for arithmetic or math questions."""
rules = """RULES:
1. Think step by step before acting.
2. Call at most one tool per turn.
3. When you have enough information, stop and answer.
4. Never invent tool results - report errors honestly."""
example = """EXAMPLE:
User: "What's the weather in Delhi?"
Assistant: I'll check the weather for Delhi.
Action: get_weather("Delhi")
Observation: "32C, sunny"
Answer: The weather in Delhi is 32C and sunny."""
system_prompt = f"""You are a helpful AI agent.
GOAL: Answer user questions accurately using tools when needed.
{tools_section}
{rules}
{example}"""
print(system_prompt)Lesson Code (Python)
# A production-style agent system prompt, built in code
tools_section = """AVAILABLE TOOLS:
- get_weather(city: str) -> str
Use when the user asks about weather or temperature.
- search_web(query: str) -> list[str]
Use when the user asks for current information or research.
- calculate(expression: str) -> float
Use for arithmetic or math questions."""
rules = """RULES:
1. Think step by step before acting.
2. Call at most one tool per turn.
3. When you have enough information, stop and answer.
4. Never invent tool results - report errors honestly."""
example = """EXAMPLE:
User: "What's the weather in Delhi?"
Assistant: I'll check the weather for Delhi.
Action: get_weather("Delhi")
Observation: "32C, sunny"
Answer: The weather in Delhi is 32C and sunny."""
system_prompt = f"""You are a helpful AI agent.
GOAL: Answer user questions accurately using tools when needed.
{tools_section}
{rules}
{example}"""
print(system_prompt)Console Output
You are a helpful AI agent.
GOAL: Answer user questions accurately using tools when needed.
AVAILABLE TOOLS:
- get_weather(city: str) -> str
Use when the user asks about weather or temperature.
- search_web(query: str) -> list[str]
Use when the user asks for current information or research.
- calculate(expression: str) -> float
Use for arithmetic or math questions.
RULES:
1. Think step by step before acting.
2. Call at most one tool per turn.
3. When you have enough information, stop and answer.
4. Never invent tool results - report errors honestly.
EXAMPLE:
User: "What's the weather in Delhi?"
Assistant: I'll check the weather for Delhi.
Action: get_weather("Delhi")
Observation: "32C, sunny"
Answer: The weather in Delhi is 32C and sunny.Code Visualization Tips
- Draw the agent system prompt as an org chart: GOAL at top, TOOLS and RULES below, EXAMPLE as the footer.
- Diagram a prompt chain as boxes with arrows — output of one feeds the next.
- Sketch the critique–revise loop: Draft → Critique → Revise → Ship.
Professional Tips & Tricks
- Include one full worked example turn in agent prompts — it teaches the format better than 10 rules.
- After changing any prompt, re-run your golden set — 'small' prompt edits move scores a lot.
- Log prompts + outputs per run; agent debugging lives or dies on traces.
Python Code Judge & Practice Arena
LeetCode StyleRun real Python 3.12 WebAssembly code directly in your browser against automated test suites.
Write an Agent System Prompt
Up next · Continue learning
Self-Consistency — Sample & Vote
Run the same prompt several times and take the majority answer to lift accuracy on hard reasoning tasks, with examples.