Velamuvi AIAcademy

Lesson 4 of 9 · Components

Prompts for Agents

Write system prompts for AI agents: role, goal, tool guidance, rules, dynamic context, output format and stopping conditions, with a runnable prompt builder.

  • 5 min read
  • Intermediate
  • Reviewed
In this lesson you will learn
  • Structure an agent's system prompt into clear sections
  • Give guidance on when to use each tool
  • Add dynamic context such as the date and the user's details
  • Keep prompts testable and easy to maintain

Agents need different prompts

A chat prompt shapes one answer. An agent prompt shapes many decisions in a row: which tool to use, when to ask the user, when to stop. Gaps that don't matter for one answer become loops, wasted steps and wrong actions in an agent.

The sections of an agent prompt

SectionPurpose
RoleWho the agent is and who it serves
GoalWhat success looks like
ToolsWhen to use each tool (beyond the tool descriptions), and in what order
RulesConstraints and when to ask the user, including stopping conditions
ContextDynamic facts: today's date, the user's name, location, permissions
OutputLength, format and tone of replies

Building the prompt from labelled sections in code keeps it readable and lets you fill in dynamic parts:

Try it yourselfPython
from datetime import date

def build_system_prompt(user, tools, today):
    sections = {
        "Role": "You are the travel assistant for Acme's employees.",
        "Goal": "Help the user plan and book work trips that follow the travel policy.",
        "Tools": "\n".join(f"- {name}: {use}" for name, use in tools.items()),
        "Rules": ("- Always check the policy before suggesting flights or hotels.\n"
                  "- Never book anything without the user saying yes to the exact option.\n"
                  "- If a tool fails twice, explain the problem and stop."),
        "Context": f"Today is {today.isoformat()}. The user is {user['name']} ({user['office']} office, {user['grade']}).",
        "Output": "Keep replies under 120 words. Show prices in EUR. End with one clear next step.",
    }
    return "\n\n".join(f"## {title}\n{text}" for title, text in sections.items())

tools = {
    "search_flights": "find flights; use for any trip question",
    "check_policy": "look up limits for the user's grade; use before suggesting options",
    "book": "book an option; only after explicit confirmation",
}
prompt = build_system_prompt({"name": "Priya", "office": "Lisbon", "grade": "G5"}, tools, date(2026, 11, 18))
print(prompt)
print(f"\n({len(prompt.split())} words)")

The context section changes per user and per day; the rest stays fixed. Without today's date, an agent asked to book “next Friday” has to guess what today is.

Tips that matter most for agents

  • Say when to ask instead of act. “If the destination or dates are unclear, ask one question before searching.”
  • Say when to stop. “When the booking is confirmed, summarise it and stop.” “If a tool fails twice, explain and stop.”
  • Give the tool order when it matters: “Check the policy before suggesting options.”
  • Show one good example of a complete interaction if the task is unusual. Examples often teach more than rules.
  • Keep rules short and specific. Ten clear rules beat two pages of guidance.

Common mistakes

Practice exercise

Assemble an agent's system prompt from clearly labelled sections.

Your solutionPython
sections = {
    "Role": "You are a research assistant.",
    "Rules": "Cite a source for every fact.",
    "Stop": "Finish when you have three good sources.",
}

# Join the sections into one system prompt: a "## <title>" line, then the text,
# with a blank line between sections. Print the result.
Knowledge check

Why include today's date in an agent's system prompt?

Summary

  • Agent prompts guide many decisions in a row, so gaps cause loops and wrong actions.
  • Use sections: role, goal, tools, rules, context, output.
  • Say when to ask, when to stop and in what order to use tools.
  • Prompts guide behaviour; code enforces rules. Version and test prompts like code.

Next: the ReAct pattern.

Finished reading? Tick it off to track your progress.