Skip to main content

Agent + Functions integration

This integration uses an Agent to reason and one or more Functions to execute. It is the cleanest way to keep a model from doing fragile manual work while still letting it choose the next step.

Use it when

  • the task needs decision-making plus deterministic work,
  • you want the model to call into code you can test separately,
  • you want to reuse the same worker from many agents.

The pieces

  • Agent — chooses the tool and frames the request.
  • Function — performs the work.
  • Tool chain — the contract between the two.

Step 1: Build the function first

Write a function that does one thing well and returns a small, typed result.

def handle(event):
# Normalize input and compute a result.
return {"ok": True, "normalized": event}

Test the function directly first. If it is not correct by itself, an agent will not fix it.

Step 2: Give the agent a narrow tool

The agent should see only the tool signature and the result shape. Keep the payload simple and the outcome predictable.

Step 3: Deploy and verify

Deploy the agent and ask a question that forces the tool chain. Watch for two receipts:

  1. the agent selected the function, and
  2. the function returned the expected structured result.

Common mistakes

  • Letting the model do the work the function should do. The model decides; the function executes.
  • Passing huge payloads into the tool. Keep the function interface small.
  • Skipping direct function tests. Build confidence in the worker before combining it with the agent.

Next steps