Rana Maninder Singh
Lesson 10 of 12API & Integration Development

AI Agent and Copilot Integrations

Lesson opener

In one line: A model may propose a tool call. Your application decides whether that call is allowed, and a person approves writes that move goods or money.

Why it matters: A staff member pasted a customer list into a chat assistant and asked it to "clean the ERP." The assistant had no ERP tool, invented ten account ids, and the staff member typed them into a payment run. The defect was an unapproved write, not a clever prompt.

Before this lesson: Data engineering integrations.

What you will be able to do

Prerequisites

Lessons 4 to 7. This lesson does not require a particular model vendor. It does not claim a regulation that forces one product.

Function calling, tools, orchestration, approval

Function calling (also called tool use) is a pattern many model APIs offer: the application sends the model a list of tools, and the model returns a structured request to run one tool with arguments. The model does not execute your ERP. Your program does, after checks. Vendor field names differ. Follow that vendor's current docs for the message shape. This course specifies the checks, which stay yours.

Approved sources. The tool list is written down. A tool that is not on the list is not called, even if the model names it. Each tool maps to one API operation you already specified in earlier lessons, such as GET /items/{sku}.

Access control. The call uses the integration identity from lesson 4, not the staff member's personal token pasted into a prompt. The role is least privilege. A read tool cannot post a payment.

Validation. Arguments are validated like any other API body. A blank SKU is 422 and is not sent. The model does not get to skip validation by phrasing the request in a sentence.

Orchestration is the sequence your program runs: propose, validate, authorize, maybe ask a person, call the API, record the result, show that result to the person. The model does not choose a hidden extra step.

Human approval is required in this course before a tool writes master data, stock, or money. A read, such as "what is on-hand for FX-100," may run without a second click if the caller's role allows that read. Northline's illustrative rule: any POST, PUT, PATCH, or DELETE waits for an explicit yes from a named person. That rule is Northline's choice.

Escalation. If the tool returns 403 or 409, the program stops and shows the status to the person. It does not ask the model to "try another account."

Audit evidence. Store the time, the person's id, the tool name, the arguments with secrets removed, the HTTP status, and the resource id the API returned. Do not store the bearer token.

WRITE_METHODS = {"POST", "PUT", "PATCH", "DELETE"}


def gate(tool_on_list, method, approved, arguments_valid):
    if not tool_on_list:
        return "refuse"
    if not arguments_valid:
        return "reject_arguments"
    if method in WRITE_METHODS and not approved:
        return "hold"
    if method in WRITE_METHODS and approved:
        return "call"
    return "call"


assert gate(False, "GET", False, True) == "refuse"
assert gate(True, "POST", False, True) == "hold"
assert gate(True, "POST", True, True) == "call"
assert gate(True, "GET", False, True) == "call"
assert gate(True, "GET", False, False) == "reject_arguments"

Teacher walkthrough: on-hand, then a receipt

Illustrative. The approved list is read_on_hand (GET) and post_receipt (POST).

  1. A person asks the assistant for FX-100 on-hand. The model proposes read_on_hand with sku: FX-100.
  2. The tool is on the list, the argument is valid, the method is GET. The program calls the warehouse API with the webshop read identity and shows 80.
  3. The person asks to receive 10 units. The model proposes post_receipt. The program holds. It shows SKU, quantity, and the ERP path. It does not call yet.
  4. The warehouse supervisor clicks approve. The program POSTs with an idempotency key and the procurement identity, not the person's pasted password.
  5. The API returns 201 and receipt R-22. The audit row stores the supervisor's id, the tool, the arguments, 201, and R-22.
  6. Validation: without the click, no receipt exists. With the click, one receipt exists.

A second workplace case

A Copilot-style assistant inside a document can draft the text of a purchase request. Drafting text is not an API call. Posting the purchase order is an API call and waits for approval. The document draft may be wrong. The ERP does not change until the approved tool runs.

Failure example: the model returns an account id

Symptom: The assistant prints account C-9999 and the clerk pays it. The ERP has no C-9999. The payment run fails overnight.

Diagnosis: The model produced an identifier that did not come from a tool result. The clerk treated generated text as an API response. The root cause is a missing rule: identifiers used for writes must be copied from a tool result or typed from the system of record, not from the model's prose.

Correction: The program shows tool results in a separate block from the model's sentences. The payment screen accepts an account id only from that block or from an ERP search the person runs. A refused unknown tool does not get to "suggest ids instead."

Validation: A test prompt that asks for ten new account ids creates no payments and displays no pay button.

Guided practice: four proposals

Scenario: The approved list contains read_on_hand and post_receipt only.

  1. Tool read_on_hand, GET, sku FX-100, no extra approval.
  2. Tool post_receipt, POST, qty 10, no click yet.
  3. Tool pay_supplier, POST, the model insists.
  4. Tool read_on_hand, GET, sku blank.

Hints:

Complete solution:

  1. call. Show the API's on-hand. 2. hold until a person approves. 3. refuse. Paying is not on the list. Do not call and do not ask the model for a workaround. 4. reject_arguments. Do not send a blank SKU. Validation: the audit log has a call only for the first proposal, a hold for the second, and no HTTP call for the third or fourth.

Independent practice

Specify one assistant action that reads and one that writes.

Acceptance criteria:

Common mistakes

  • Letting the model call arbitrary URLs.
  • Using a person's pasted token as the integration identity.
  • Skipping approval because the model sounded confident.
  • Writing secrets or raw customer files into the prompt when a read tool can fetch the one field you need.

Quick check

  1. Who executes the ERP call?
  2. What happens to a tool that is not on the list?
  3. Which methods wait for approval in Northline's illustrative rule?
  4. What do you do when the API returns 403?
  5. Where must an account id come from before a payment?

Answers:

  1. Your program, after the checks. Not the model.
  2. The program refuses it. No HTTP call.
  3. POST, PUT, PATCH, and DELETE.
  4. Stop and show the status. Do not ask the model to try a different identity.
  5. From a tool result or from the system of record, not from the model's ungrounded sentence.

Lesson summary

Tools are a closed list. The program validates, authorizes, and calls. Writes wait for a person. The audit row is the evidence. Generated prose is not an API result.

Bridge to the next lesson

Calls now exist in several places: clients, webhooks, batches, and assistants. The next lesson is how you watch them, log them, trace one request across systems, and prove a repeat did not double-post.