Skip to main content
Recipe prompt
AI agent tool calling: an agent sends a lookup to the Forager REST APIAI agent tool calling: an agent sends a lookup to the Forager REST API

What you’ll build

A server-side loop that lets a model decide when to search for people and when to look up a phone number. The model sees two tool definitions. Your code runs the calls against the Forager REST API, so the key never reaches the model or a browser.

Steps

1

Define the tools

Each tool is a name, a description and a JSON Schema for its arguments. Most model providers accept this shape in their tool-calling API; rename the wrapper keys to match yours. The descriptions matter: they tell the model when a call is worth its credits.
2

Execute a tool call

Map each tool to one request. These are the two requests your executor sends.
3

Run the loop

call_model is a function you write (the code below has a placeholder) around your model provider’s tool-calling API. It sends the messages and the tool definitions, and returns the reply’s text and any tool calls, each with an id, a name and arguments as a dict.
The role and field names for tool results differ between providers. Adapt the two messages.append lines to yours.

Handle the edge cases

  • Not found. An empty people or phone_numbers list is a result, not an error. Return it so the model can tell the user.
  • 403. The key is missing or invalid. The code raises, so the failure reaches you and not the model.
  • 429. The code retries once, then returns rate_limited as data so the model can stop or wait. See errors and rate limits.
  • Credits. A role search costs 1 credit per request and a phone number lookup 15 credits per lookup, so a loop with no cap can spend fast. Keep a per-run call cap and log every call. See credit pricing.
  • Trimmed results. Return only the fields the model needs. Full person records are large and slow the model down.

Build with AI agents

Docs and the OpenAPI spec for agents.

Search people by role

Every role search filter.

Person role search

Request and response reference.
Last modified on October 28, 2026