Skip to Content

Prompts for tools and agents

A tool's name, description and parameter descriptions are prompt text that the model reads. Watch vague tool text send a clinic assistant to the wrong tool, then see clear text fix it, and see an agent's system prompt decide when to ask and when to stop.

11 minFree

Prompts for tools and agents
  1. What the model reads
  2. Choose a tool
  3. Run the tool
  4. Reply
FIG. PE-TOOLS-AND-AGENTS / 06 PARTSPatientclinic chatSystem promptgoal, limits, stopTool listnames, descriptionsModelany LLMYour coderuns the toolAppointmentsclinic database

Press Play to watch it run, or step through with ← →. Then switch to Practice and run it yourself.

00/08
[
  {
    "name": "get_data",
    "description": "Gets data.",
    "parameters": {
      "type": "object",
      "properties": {
        "id": { "type": "string" },
        "date": { "type": "string" }
      }
    }
  },
  {
    "name": "get_info",
    "description": "Gets info.",
    "parameters": {
      "type": "object",
      "properties": {
        "id": { "type": "string" }
      }
    }
  },
  {
    "name": "update",
    "description": "Updates an appointment.",
    "parameters": {
      "type": "object",
      "properties": {
        "id": { "type": "string" }
      }
    }
  }
]

Tool calls and results

No tool calls yet. Press Play.

Background: the idea in plain words2 min read

A model can only write text. It cannot look at a timetable or cancel a booking. To let it do real work, your app gives it tools. A tool is a function in your code that the model may ask you to run. The model writes a tool call (the name of a tool and the values to pass to it), your code runs it, and the result goes back to the model.

How does the model know which tools exist? Your app sends a list. For each tool the list has a name, a description and the parameters (the values the tool needs), each with its own short description.

Here is the part many people miss. The model cannot open your code. It reads the tool list as text, in the same way it reads your prompt. The name and the descriptions are the only things it knows about a tool. So they are prompts, and they need the same care as any other prompt.

When the text is vague, the model guesses. It may pick the wrong tool. It may pick the right tool and fill it with the wrong values, such as "tomorrow evening" where your database wants a date. Neither is a model fault. A new human helper with the same labels would make the same mistakes.

An agent is a model that calls tools in a loop until a job is done. An agent decides its own next step, so its system prompt has more work to do. It must state the goal, the limits, when to stop, and when to ask the user before acting.

The running example is the front desk of a clinic in Chennai. A patient asks: "Is Dr. Rao free tomorrow evening?" The assistant has three tools: one finds free slots, one lists a patient's appointments, and one cancels an appointment.

Press Play to watch vague tool text fail. Then switch Try it to After: clear names, descriptions and parameters, and last to Agent prompt: when to ask, when to stop.

What to notice

  1. Tool text is prompt text. Anthropic's docs say the API builds a system prompt from your tool definitions. OpenAI's docs say functions are injected into the system message. The model reads every word, and you pay for those words as input tokens.
  2. Vague names cause the wrong tool. "Gets data" and "Gets info" gave the model nothing to choose by. clinic_find_slots and clinic_list_appointments cannot be confused.
  3. Vague parameters cause the wrong values. A field called id could be anything. A field called doctor_name with "surname without the title, for example Rao" can be filled in only one way.
  4. Say when to use a tool, and when not to. The cancel tool's description says "Use it only after the patient has confirmed". That one sentence is a safety rule the model sees at the exact moment it considers the tool.
  5. An agent's prompt sorts actions by risk. Looking things up is safe, so the agent does it without asking. Cancelling cannot be undone, so the agent asks first. Then it stops when the job is done.
Go deeper

A vague description and a clear one

1 min read

Vague

get_data: "Gets data." A parameter called id and one called date, with no description. The model must guess what data, whose id, and which date format.

Clear

clinic_find_slots: what it does, when to use it, and that it only reads. doctor_name with an example, date with a format, period with three allowed values.

Anthropic's docs call detailed descriptions "by far the most important factor in tool performance". They list what a description should explain:

  • What the tool does.
  • When it should be used, and when it should not.
  • What each parameter means and how it affects the tool.
  • Important limits, such as what the tool does not return.

They suggest at least 3 to 4 sentences per tool, and more for a complex one. OpenAI's docs give a quick check, the intern test: could an intern use the function correctly, given only what you gave the model? If the intern would have questions, put the answers in the description.

Go deeper

A checklist for tool definitions

1 min read
Do thisWhyWho says so
Use a clear name with a prefix for the service, such as clinic_find_slotsThe model can tell similar tools apart as the list growsAnthropic (namespacing), Google (descriptive names)
Describe each parameter with its format and an example"YYYY-MM-DD" removes a whole class of wrong valuesAll three
Use an enum for a fixed set of choicesThe model cannot invent a value outside the listOpenAI, Google
Do not ask the model for values your code already hasThe patient's identity comes from the chat session, so the list tool takes no argumentsOpenAI
Keep the active tool list smallMore tools means more ways to pick the wrong one. OpenAI suggests fewer than 20 at the start of a turn as a soft guide. Google suggests an active set of 10 to 20 at mostOpenAI, Google
Return short, useful resultsThe result is read by the model as input. Extra fields waste tokens and hide what mattersAnthropic
Check a call before you run itA model can still send a bad value. Validate, and return a clear errorGoogle

The JSON shape of a tool differs a little by vendor. The example files use name, description and parameters, which are the field names in the OpenAI and Google docs. Anthropic's docs name the third field input_schema. The advice about the words inside is the same for all three.

Longer descriptions cost tokens Every tool definition is sent on every call and billed as input. Three clear tools are cheap. Sixty tools with long descriptions are not. Keep the list short, keep the fixed tool list at the start of the prompt so it can be cached, and see Tokens, cost and prompt caching.

Go deeper

The system prompt of an agent

1 min read

A prompt for one answer needs a role, rules and a format. An agent runs for many steps without you, so its prompt must also say how far it may go. The clinic prompt has four parts:

PartWhat it answersIn the clinic prompt
GoalWhat is the job, and for whom?Help this patient check timings and manage their own appointments
LimitsWhat must it never do? What is safe to do freely?Only the given tools. No medical advice. Lookups are safe. Cancelling needs a yes
When to askWhen should it stop and ask the user?A detail is missing, or two answers are possible
When to stopWhen is the job finished? What if it cannot finish?Done and reported. Or a tool failed twice: offer the clinic staff

Google's prompting guide describes the same ideas for agents. Its example separates low-risk actions that only read from high-risk actions that change state. It covers when the agent must pause and ask the user for clarification or permission. It also tells the agent to change its plan after an error, not to repeat the same failed call.

There is a trade-off, and Google's guide names it: an agent that keeps trying succeeds more often, but it can cost more tokens or get stuck in a loop. An agent that asks about everything is safe and tiresome. Decide per action. Ask where a wrong step would hurt, and let the agent work freely where a step is easy to undo.

Tool definitions and the system prompt work together. OpenAI's docs suggest using the system prompt to say when to use each function and when not to. Put rules about one tool in that tool's description. Put rules about the whole job in the system prompt.

Go deeper

Words to know

1 min read
WordMeaning in simple words
ToolA function in your code that the model can ask you to run
Tool callThe model's request: a tool name and the values to pass to it
Tool descriptionThe text that tells the model what a tool does and when to use it
ParameterOne value a tool needs, such as a date or a doctor's name
EnumA fixed list of allowed values for a parameter
AgentA model that calls tools in a loop, choosing its own next step, until the job is done

Check your understanding

1. An assistant keeps calling the wrong one of two tools: get_data and get_info. What is the best first fix?
2. A tool has a parameter named date with no description. The user says “tomorrow evening”. What is likely to go wrong?
3. A patient with two appointments says “cancel my appointment”. Which part of the agent's system prompt makes it ask which one?
Sources: the official documentation4 links

Something wrong or unclear in this lesson? Tell us, it gets fixed.