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
- Separate a model's proposal from an API call your program actually makes.
- Allow only tools that are on an approved list.
- Hold a write for human approval when it changes master data, stock, or money.
- Keep an audit record of who approved the call and what the API returned.
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).
- A person asks the assistant for FX-100 on-hand. The model proposes
read_on_handwithsku: FX-100. - 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.
- 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. - The warehouse supervisor clicks approve. The program POSTs with an idempotency key and the procurement identity, not the person's pasted password.
- The API returns 201 and receipt R-22. The audit row stores the supervisor's id, the tool, the arguments, 201, and R-22.
- 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.
- Tool
read_on_hand, GET, sku FX-100, no extra approval. - Tool
post_receipt, POST, qty 10, no click yet. - Tool
pay_supplier, POST, the model insists. - Tool
read_on_hand, GET, sku blank.
Hints:
- Use
gate. - A tool absent from the list is refused even if the method is a read.
Complete solution:
call. Show the API's on-hand. 2.holduntil 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:
- The write is on a named tool mapped to one API operation.
- The identity and role match lesson 4.
- Arguments are validated before the call.
- The write waits for a named human approval.
- You list the audit fields and you exclude the token.
- You say what happens on 403.
- You do not present the model's prose as the API response.
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
- Who executes the ERP call?
- What happens to a tool that is not on the list?
- Which methods wait for approval in Northline's illustrative rule?
- What do you do when the API returns 403?
- Where must an account id come from before a payment?
Answers:
- Your program, after the checks. Not the model.
- The program refuses it. No HTTP call.
- POST, PUT, PATCH, and DELETE.
- Stop and show the status. Do not ask the model to try a different identity.
- 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.