Prompting for Agents

Easy 20 min read

System Prompts for Agents

Why Prompting Matters

The Problem: An LLM without proper instructions is like a brilliant employee with no job description -- capable but directionless.

The Solution: Well-crafted system prompts transform a general-purpose LLM into a focused, reliable agent with clear behavior, tool awareness, and error handling strategies.

Real Impact: The difference between a mediocre agent and an excellent one is often just the quality of its system prompt.

Real-World Analogy

Think of a system prompt as an employee onboarding packet:

  • Role Definition = Job title and responsibilities
  • Tool Documentation = List of software and tools they can use
  • Guidelines = Company policies and best practices
  • Examples = Sample work from previous employees
  • Constraints = What they should never do

Anatomy of an Agent Prompt

Identity & Role

Define who the agent is, its expertise, and personality. This anchors all subsequent behavior.

Capabilities

List what tools the agent can use, what actions it can take, and the scope of its abilities.

Instructions

Step-by-step guidance on how to approach tasks, handle errors, and format responses.

Constraints

Boundaries the agent must respect -- safety guardrails, scope limits, and fallback behaviors.

Role & Persona Definition

Prompt Structure Breakdown
System Prompt Role Who you are Tools What you can use Instructions How to behave Constraints What to avoid Few-Shot Examples (Optional) Example interactions showing desired behavior

Tool Descriptions in Prompts

agent_system_prompt.txt
# System Prompt for a Research Agent

You are a research assistant with expertise in technology topics.

## Your Tools
- web_search(query): Search the internet for current info.
- read_url(url): Read the full content of a web page.
- save_note(content): Save important findings for later.

## Instructions
1. Always search before answering factual questions.
2. Cite your sources with URLs.
3. If sources disagree, present both viewpoints.
4. Think step-by-step for complex questions.

## Constraints
- Never fabricate information or URLs.
- If you cannot find reliable info, say so clearly.
- Limit searches to 3 per question to manage costs.

Few-Shot Examples

few_shot_prompt.py
messages = [
    {"role": "system", "content": system_prompt},
    # Few-shot example: demonstrate tool usage
    {"role": "user", "content": "What is the latest Python version?"},
    {"role": "assistant", "content": "Let me search for the latest Python release.",
     "tool_calls": [{"function": {"name": "web_search",
      "arguments": "latest python version 2026"}}]},
    {"role": "tool", "content": "Python 3.14 released..."},
    {"role": "assistant", "content": "Python 3.14 was released. [Source: python.org]"},
    # Now the actual user query
    {"role": "user", "content": actual_query}
]

Prompt Templates

TemplateWhen to UseExample
Role-Goal-ConstraintsGeneral-purpose agents"You are X. Your goal is Y. Never do Z."
Tool-FirstTool-heavy agentsLead with tool definitions and usage rules
Chain-of-ThoughtReasoning-intensive"Think step-by-step before acting"
Output-FormatStructured outputSpecify exact JSON schema in prompt

Quick Reference

PrincipleDoDon't
ClarityBe specific and explicitUse vague instructions
StructureUse headers and listsWrite a wall of text
ExamplesShow desired behaviorOnly describe abstractly
ConstraintsState boundaries explicitlyAssume model will infer limits
TestingIterate and refine promptsWrite once and deploy