# Lab 5 — let it call a function

> Deepgram workshops › Deepgram Voice Agent workshop — easy mode › Lab 5 — let it call a function
> Web version: https://workshops.deepgram.com/voice-agent-in-browser/function-calling
> About 7 min.

### Ask for something the model can't know {#the-four-hops}

**Goal:** See how an agent uses a function to get information the model can't know on its own.

Ask your agent what time it is. It'll make something up with total confidence, because a language model has no clock. Function calling lets the agent hand a question to something outside the model. That could be your database, your API, the user's order history, or today's date.

The flow has four hops:

1. The configuration advertises a function: a **name**, a **description**, and a schema for its arguments. A schema describes the inputs the function accepts.
2. The model decides a turn needs the function, and Deepgram sends a **function call request** with the arguments the model chose.
3. Something runs the function and returns a result.
4. The model works the result into its reply, and the agent speaks it.

**You should see:** the agent answering with a time it can't have checked.

### Watch a function run {#see-it-happen}

Two example functions ship with the playground. Open the **Functions** section of the settings panel to find them:

- **Arithmetic (Example):** `do_arithmetic`, which takes an `operation` (add, subtract, multiply, divide) and a list of `numbers`.
- **End Conversation (Example):** `end_conversation`, which the agent calls when it hears a phrase that means the conversation is over.

Then follow these steps:

1. Toggle **Arithmetic (Example)** on, then expand it. You get the **Function name** and the **Function JSON**, the exact schema the model reads. Read the `description` fields. You're about to see why they matter.
2. Start a conversation and ask something arithmetic: *"what's four hundred and seventeen times nineteen?"*
3. Watch the message list. Expand the function events and compare their arguments to the schema you just read.
4. Toggle **End Conversation (Example)** on, start again, and say goodbye. It's a different function with the same four hops.

**You should see:** the function call request with the arguments the model picked, then the response, then the agent speaking the answer. If the Functions toggles are grayed out, click **End Conversation** first.

### Remember two things before you write your own {#the-two-things-worth-remembering}

**The description is a prompt.** It's the only thing the model reads when deciding whether to call your function. Write it to say *when* to use the function, not just what it does.

"Get the current time" is a weak description. "Get the current date and time in a given IANA timezone. Use this whenever the user asks what time it is or what today's date is" is one the model can act on. Nine times out of ten, a function that never fires has a description problem, not a wiring problem.

**Where the function runs is one field.** In the JSON, a function definition can carry an `endpoint`:

```json
{
  "name": "get_order_status",
  "description": "Look up the status of a customer order by order number. Use this whenever the caller asks where their order is.",
  "parameters": {
    "type": "object",
    "properties": {
      "order_number": { "type": "string", "description": "The order number the caller reads out." }
    },
    "required": ["order_number"]
  },
  "endpoint": { "url": "https://api.example.com/orders", "method": "post" }
}
```

With `endpoint` set, Deepgram calls that URL itself, server-side, with no application of yours involved. Leave `endpoint` out and Deepgram sends the call down the connection to your app and waits for you to answer.

Use that second option when the function touches local state, or credentials you'd rather not put on a public URL. That single omitted field is the whole distinction, and the code track's [Step 7](/voice-agent-py/function-calling) turns on it.

The playground's Functions section ships those two examples rather than an editor, so writing your own is where easy mode hands off. You now know what to write, and the [function calling documentation](https://developers.deepgram.com/docs/voice-agents-function-calling) has the rest.
