CopilotForgeDraft

Catalogue › AI Engineering › ai-api-and-tooling

AI API and tooling

Designs the APIs and shared tooling that custom AI solutions call or expose - contract-first interfaces, narrow tool surfaces a model can use correctly, input validation, user-scoped authorisation, idempotent writes, rate limits, versioning and errors a model can act on. Use when building a service an agent will call as a tool, when exposing an AI capability as an API, or when shared tool libraries are needed across solutions.

Department
AI Engineering
Lifecycle
Deliver, Assure, Improve
Maturity
builder, scaler, ai-enterprise
Risk tiers
1, 2, 3, 4
Platforms
ai-foundry, azure, copilot-studio, m365-agents, github
Editions
starter, scale, enterprise
Reviewers
security-privacy, design-authority
Status
draft
Copilot Cowork
AI Engineering plugin for Copilot Cowork, or this skill on its own: Download SKILL.md
Licence
CC BY 4.0, by Simon Foote

Purpose

Agents and AI services are only as safe and reliable as the APIs they call and the APIs that expose them. A model chooses which tool to call and with what arguments based on names, descriptions and schemas, so an API that is fine for a careful developer can be misused by a model in ways nobody intended. This skill sets the engineering of those interfaces: narrow, well-described tools, validated inputs, authorisation in the user's context, idempotent writes, limits, versioning and errors the model can recover from. It goes wrong when an existing broad API is handed to a model as is, and when tools run with a service identity that can do far more than the user.

When to use

When not to use

Questions to ask first

  1. Who or what will call the API - a model choosing tools, application code, or both - and on whose behalf?
  2. What is the narrowest set of operations the AI solution actually needs, and which of them change data or send anything?
  3. Whose permissions should apply to each call: the signed-in user's, or a service identity's, and why?
  4. What happens if the same call arrives twice, or arrives with plausible but wrong arguments?
  5. Who will own the API, its versions and its consumers over time?

Required inputs

If the identity model is undecided, design for user-delegated access and mark service identity use as "to confirm" with a named decision owner. Never default a write tool to a broad service identity.

Decision framework

Apply each rule to every tool or API operation. From tier 2, a failed rule needs a recorded justification.

RuleWhat good looks like
Narrow surfaceOne operation per tool, doing one thing, rather than a general query or "execute" endpoint
Descriptive contractClear name, plain description of when to use and when not to, typed parameters with allowed values and examples
Contract firstInterface defined in a machine-readable specification before implementation, and versioned
Input validationServer-side checks on every argument; never trust that the model passed valid values
Authorisation in contextCalls run with the user's permissions where data is user-scoped; service identities only with narrow, documented scope
Read and write separatedWrite, send and delete operations are distinct tools, return a preview where effect is material, and require confirmation upstream
IdempotencyWrites accept an idempotency key so retries do not repeat effects
Useful errorsErrors say what was wrong and what the caller can do, without leaking internals or data
LimitsRate limits, payload limits and timeouts declared and enforced
VersioningBreaking changes get a new version; old versions have a retirement date
LoggingEach call logged with caller, user context, operation, outcome and correlation id

Practitioner approach

Start from the task, not the existing API. List what the agent or AI service genuinely needs to do, then design the smallest set of operations that achieves it. An existing API with fifty endpoints and a free-form query parameter is a poor tool: the model will find uses nobody tested. Wrap it with a narrow facade that exposes only the needed operations.

Write the contract before the code. Define each operation in a machine-readable specification with names, descriptions, parameters, allowed values and examples. For tools a model will call, the description is part of the prompt: say when to use the tool, when not to, and what each parameter means in business terms. Test descriptions by asking the model to choose tools for realistic requests, including near misses, and refine the wording until selection is reliable.

Validate everything on the server. Models produce plausible arguments that may be wrong, out of range or crafted by injected content. Check types, ranges, allowed values and that referenced records exist and are visible to the user. Reject with a clear, safe error rather than guessing.

Authorise in the user's context wherever the data is user-scoped. A tool that searches documents or records should return only what the signed-in user could see. Where a service identity is unavoidable, scope it to the operations the tool performs, document why and name an owner. Follow ai-engineering:secrets-and-identity.

Separate reads from writes, and make writes safe. Give write, send and delete operations their own tools. Where the effect is material, return a preview the calling solution can show the user for confirmation, then commit with an idempotency key. Make errors actionable: a model can recover from "the date must be in the future" but not from a stack trace.

Plan for load and change. Declare and enforce rate limits and timeouts, because agents can call tools in loops. Version the contract, publish changes to consumers and keep old versions running until a set retirement date. Log every call with a correlation id so a user's request can be traced through orchestration, model and tool.

Where several solutions need the same tools, package them as a shared library or service with an owner, tests, versions and documentation, and register them so teams find and reuse them instead of rebuilding.

Outputs

Microsoft platform considerations

Foundry agents, Copilot Studio agents and Microsoft 365 agents consume tools through different mechanisms, including OpenAPI-described actions, connectors, functions and Model Context Protocol servers; Azure API Management can front and govern APIs. Supported formats, authentication options and limits change. Check current behaviour in references/sources.md before choosing an interface style, and record what was checked.

Adoption considerations

Makers and engineers reuse tools they can find and trust. Publish shared tools with clear documentation, examples and an owner to contact, and make the shared route easier than building a private copy.

Knowledge considerations

Not applicable to most API design, because tools act on systems rather than ground on content. Where a tool performs retrieval, its results must respect the knowledge owner's access rules; see ai-foundry:retrieval-design.

Security and privacy considerations

Tools are the main route by which prompt injection turns into action. Validate inputs, authorise per user, keep writes narrow and confirmed, avoid returning more data than the task needs, and log calls. Tools that reach personal data or external services go to security-privacy:connector-review.

Responsible AI considerations

Tools that change records about people, send messages or make decisions need human confirmation upstream and an audit trail. Design previews so the person confirming can see what will actually happen, in plain language.

Evaluation requirements

Include tool selection and argument accuracy in the evaluation harness, with near-miss requests and injected content. Contract tests check every tool against its specification on each change; see ai-engineering:ai-solution-testing.

Value measures

Track reuse of shared tools across solutions, tool call error rates, rejected invalid arguments and incidents caused by tool misuse. The AI engineering lead owns these measures at portfolio level.

Scale notes

Starter

Expose a few narrow read tools with user-delegated access and clear descriptions. Avoid write tools until confirmation and idempotency are in place.

Scale

Introduce contract-first design for all tools, a shared tool library for common systems, an API gateway for limits and logging, and tool selection tests in the pipeline.

Enterprise

Run a governed internal catalogue of AI tools and APIs with owners, versions, consumers and retirement dates, and review new write-capable tools centrally.

Hand-offs

Reviewer gates

From risk tier 2, security-privacy reviews authorisation, validation and write controls, and a write tool running on a broad service identity beyond user rights is blocking. design-authority checks contracts, versioning and reuse of shared tools.

Failure modes

Sources

references/sources.md in this skill lists the source records behind this skill, what each is authoritative for, how volatile it is and what you may do with it. Product availability, licensing, limits and preview status change often, so check the current source before stating them, and cite what you used.

Never

Source records for this skill

Ways to extend Microsoft 365 Copilot

Compare declarative and custom engine agents

Microsoft Foundry Models overview

Copilot Studio security and governance

Credit

This skill was created by Simon Foote as part of CopilotForge, licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Credit the author when you share or adapt it.