Forward-deployed / Learning zone
Prompt engineeringa standalone module
Lesson 07

Prompting for tools and agents

TL;DR

The prompt changes shape the moment the model can act — call a function, run a search, read a file, hit an API. Instead of steering a single generation, you're steering a loop: the model reasons about what to do, picks a tool from a schema you supplied, receives the tool's output, reasons again, and stops when the task is done. That loop has a name — ReAct (Yao et al., 2022) — and every modern agent scaffold is a variant of it. The prompt engineering that runs it is a specialization of everything from lessons 1-6, plus three new concerns: how to describe available tools so the model picks the right one, how to constrain the loop so it terminates cleanly, and how to handle tools that fail without derailing the whole run. This lesson is the bridge from "prompting a model" to "prompting an agent."

🎯 For the AI PM (or coding-agent user)

Why it matters — Agent-shaped features fail in ways non-agent ones don't: tools misused, loops that don't stop, cascading errors after one bad step. The prompt is the primary steering surface for all of it.

What it changes in your decisions — Tool descriptions become spec-level artifacts, not one-line docstrings. The system prompt spells out when not to call tools, not just when to call them. Termination criteria are explicit.

Ask yourself — "If my agent has to decide between three plausible tools for a task, does the tool description tell it which one and when?"

Risk if ignored — An agent that calls the wrong tool, calls the right tool with wrong arguments, or loops until it hits the max-steps guardrail — all because the prompt described the tools instead of specifying them.

The mental model — the ReAct loop

The ReAct loop

Think → act → observe → repeat

Every modern agent scaffold is a variant of this loop.

System prompt + tool schemas + user goal
THINK
reason about next step
→
ACT
pick a tool + args
→
OBSERVE
tool output
↺ observe feeds back into think, or a stop condition is met
Done — final answer

Read the loop as think → act → observe → repeat. The prompt sets it up: role, goal, available tools, termination rules. The model executes it. Each turn produces either a tool call or a final answer. Each tool output becomes new context for the next turn. The whole run is one prompt, extended.

Three concerns unique to agent prompts

Concern 1 — describe tools like APIs, not features

A tool description is not marketing copy. It's an API contract the model reads to decide when and how to call the tool. Good tool descriptions name:

Compare a weak description:

search_documents: Search the document store.

To a strong one:

search_documents: Search the internal document store by keyword query.
Use for: finding company policies, product specs, meeting notes indexed
before today.
Do NOT use for: real-time information (use `web_search` instead), or
answers already in the current conversation.
Args:
  query (str): 2-8 word keyword phrase; not a natural-language question.
  top_k (int): 1-10, default 5.
Returns:
  List of {doc_id, title, excerpt}. Empty list if no matches.

The mechanics of writing these schemas — JSON Schema, OpenAPI-style descriptions, Anthropic's tool_use block, OpenAI's function calling — are covered in the tool calling module. This lesson is about the content that goes in the description.

Concern 2 — constrain the loop so it terminates

Left alone, an agent may loop until it hits a max-steps limit, especially on tasks without a clear success signal. The prompt has to name the stop conditions:

Termination is a prompt-engineering problem, not just a runtime guardrail. The runtime cap is the safety net; the prompt is the intent.

Concern 3 — handle tool failures on purpose

Tools fail. APIs time out. Search returns empty. A file doesn't exist. Without guidance, the model often invents a plausible answer instead of admitting the tool failed. The fix is explicit:

If a tool returns an error, do not invent the result. Report the error, then either retry once with a corrected argument, use a fallback tool if one exists, or stop and tell the user what failed.

The system prompt for an agent

Putting it together, a production agent system prompt tends to include:

The user turn provides the task. The rest of the loop is the model + tools + scaffold. But the ceiling on agent quality is set by that system prompt.

Tradeoffs

Failure modes

Practitioner checklist