Skip to content

Give the library assistant one tool and run its first call

Define the assistant's first tool, a catalogue lookup, as the model sees it: a name, a description that says when to use it, and a schema. Dispatch the model's first call through validation, return a result shaped for the next decision, and see why a tool call is a proposal until the harness runs it.

15 MIN

By AIAgentInterviews · Updated

TL;DR: The model never sees your function. It sees a name, a description and a schema, and it returns a request to call them. The harness validates the arguments, runs the function, shapes the result for the next decision and appends it under the call's id. Until the harness runs it, a tool call has done nothing in the world, which is the fact every later control rests on.

Where you are. Module two, lesson one. You have a valid message list. Now the model gets something to ask for, and you run the first request it makes.

What the model actually sees

Linden's catalogue service has a function that looks up a title and returns copies by branch. The model cannot call it. The model can only produce text, and with tool calling that text is a structured request: a tool name and a JSON object of arguments. What the model knows about the tool is exactly what the harness sends in the tool definition: a name, a description and a schema for the arguments. Write those three well and most tool-calling bugs never happen.

In plain language. A tool definition is the advertisement the model reads. A tool call is the model's structured request to run it. The dispatcher is the harness code that validates the request, runs the function and returns a result the model reads next turn. A tool call is a proposal; the dispatcher decides whether and how it runs.

Three choices in the definition carry most of the value. The name says what decision the tool serves (catalogue_lookup, not get). The description says when to use it and when not, because the model chooses among tools by reading descriptions. And the schema constrains the arguments with types and, where possible, enumerations, so the model cannot send a branch name that does not exist.

The first call, end to end

import json

CATALOGUE = {
    "the lighthouse": {"central": 2, "northfield": 0, "riverside": 1},
    "small island": {"central": 0, "northfield": 1, "riverside": 0},
}

TOOL = {
    "name": "catalogue_lookup",
    "description": ("Find how many copies of a title each Linden branch holds. "
                    "Use it when a reader asks whether a book is available. "
                    "Not for placing holds or renewing loans."),
    "schema": {"type": "object", "required": ["title"],
               "properties": {"title": {"type": "string",
                                        "description": "The book's title"},
                              "branch": {"type": "string",
                                         "enum": ["central", "northfield",
                                                  "riverside"]}}},
}

def catalogue_lookup(title, branch=None):
    copies = CATALOGUE.get(title.lower())
    if copies is None:
        return {"found": False, "title": title}
    if branch:
        return {"found": True, "title": title, "branch": branch,
                "copies": copies[branch]}
    held = {b: n for b, n in copies.items() if n > 0}
    return {"found": True, "title": title, "available_at": held,
            "total": sum(copies.values())}

def validate(args, schema):
    problems = [f"missing required '{r}'" for r in schema["required"] if r not in args]
    for k, v in args.items():
        spec = schema["properties"].get(k)
        if spec is None:
            problems.append(f"unknown argument '{k}'")
        elif "enum" in spec and v not in spec["enum"]:
            problems.append(f"'{k}' must be one of {spec['enum']}")
    return problems

def dispatch(call):
    """Validate, run, and return a result the model can read."""
    try:
        args = json.loads(call["arguments"])
    except json.JSONDecodeError:
        return {"error": "arguments were not valid JSON"}
    problems = validate(args, TOOL["schema"])
    if problems:
        return {"error": "; ".join(problems)}
    return catalogue_lookup(**args)

# The model's first request, as a scripted provider would return it.
call = {"id": "c1", "name": "catalogue_lookup",
        "arguments": "{\"title\": \"The Lighthouse\"}"}
result = dispatch(call)
print(result["found"], result["total"])  # => True 3
print(result["available_at"])  # => {'central': 2, 'riverside': 1}
bad = {"id": "c2", "name": "catalogue_lookup",
       "arguments": "{\"title\": \"The Lighthouse\", \"branch\": \"airport\"}"}
print(dispatch(bad))
# => {'error': "'branch' must be one of ['central', 'northfield', 'riverside']"}

message = {"role": "tool", "tool_call_id": call["id"], "content": json.dumps(result)}
print(message["tool_call_id"], len(message["content"]) < 120)  # => c1 True

Read the three parts. The definition is what the model read: a name that states the decision, a description with a when and a not-for, a schema whose branch is an enumeration. The dispatcher validated before running: the second call named a branch that does not exist, and instead of a crash or a lookup of nothing the model gets a message that says which values are allowed. And the result is shaped for the next decision: the branches that hold copies and the total, not the raw table, under the call's id so the pairing rule from the last lesson holds.

A worked case: the proposal that was mistaken for an action

Here is the mistake the Linden team made before this design. Their first assistant logged "placed a hold" when the model produced a hold request, before anything had run, and a bug in the hold service meant a third of those holds never existed. Readers arrived at branches expecting books. Walk the reasoning: the observation was a log line that did not match reality; the question was what the log line recorded; the answer was the model's proposal, not the harness's effect. The decision was to record and report only what the dispatcher did, after it did it, and to treat every tool call as nothing until then. That principle (the model proposes, the harness disposes) is the authority line, and it is the reason the dispatcher exists rather than the model calling functions directly.

DiagramFrom the model's request to a result it can read
Modelreturns a tool callValidateJSON, required, enumRun the functioncatalogue_lookupShape the resultbranches with copies, totalAppend under the call idrole: tool, c1proposalvalidproblems, as a result
1/3

Nothing has happened yet

A tool call is text describing an action. The dispatcher decides whether it runs.

Results are read on every later turn

The result you return is appended to the list and resent on every later turn, so its size is paid many times. The lookup returns the branches that hold copies and a total, not the full table with zeros and metadata, and says found: False plainly when the title is unknown rather than returning an empty object the model might read as "no copies anywhere". The habit is to return what the next decision needs and to make a negative result say so.

What if · interview follow-ups

Change one condition

Linden's assistant has one tool and a dispatcher. The team starts adding the next two tools and asks what carries over.

  1. Start here

    The hold tool will change the world. Does it get the same dispatcher path as the lookup?

Do this before moving on

Add a second tool, loans_renew, with a schema that requires a loan id and an enumerated reason. Route it through the same dispatch by looking the tool up by name, and make dispatch return a result for an unknown tool name that lists the tools that exist. Then send three calls: a valid renewal, a renewal with a reason outside the enumeration, and a call to a tool that does not exist.

Review your result. For each call, write down what the model would read next turn. Every one should be something the model can act on, and none should be a stack trace or an empty object.

Go deeper

Key takeaways

  • The model sees a name, a description and a schema; it returns a request, not an action.
  • The dispatcher validates before running and returns problems as results the model can act on.
  • Results are shaped for the next decision and say plainly when nothing was found.
  • Every call goes through the dispatcher, because that is where authority checks and idempotency will live.

Check yourself

Answer aloud or on paper before revealing. Producing the explanation unaided is exactly what a panel listens for.

  1. 1The model returns a catalogue_lookup call with branch set to 'airport'. What should the reader of the result be able to do?

  2. 2Why does the lesson insist that a tool call has done nothing until the dispatcher runs it?

  3. 3What does shaping a result buy, concretely, for the catalogue lookup?

Sign in to track which lessons you have finished.