Conversational AI (artificial intelligence) · 06 / 22

Tool and API (Application Programming Interface) Contracts

The tool catalogue and contracts of the booking assistant: OpenAPI and MCP (Model Context Protocol) definitions, error model, idempotency and contract tests.

Why contracts come first

The tools are the only way the assistant can change the world. Their contracts are the stable layer: the Microsoft Foundry build and the LangGraph build both call the same operations, and the evaluation set checks the same arguments. A strict contract makes the system testable, lets the tool gateway enforce policy and limits what a manipulated model can do.

The tool catalogue

ToolPurposeChanges dataSafe to retryScopeNeeds confirmation
search_rulesRetrieve airport rules and terms as cited clausesNoYesknowledge.readNo
get_airportHours, services, capacity and local restrictionsNoYesairport.readNo
quote_servicesPrice a set of servicesNoYespricing.readNo
check_availabilityHangar, ramp and fuel availability for a windowNoYesinventory.readNo
hold_resourcesHold resources for a fixed windowYesYes, by keybooking.holdNo, but shows terms
commit_bookingTurn a hold into a bookingYesYes, by keybooking.commitYes, token
change_bookingChange the time or services of a bookingYesYes, by keybooking.changeYes, token
cancel_bookingCancel and apply the cancellation termsYesYes, by keybooking.cancelYes, token
request_serviceRequest a crew car, catering or de-icingYesYes, by keyservice.requestNo for standard, desk for custom
get_bookingRead a booking on the caller's own accountNoYesbooking.readNo
handoffOpen a ticket for the line desk with the threadYesYes, by keydesk.writeNo

An operation, in OpenAPI

The commit operation is the most sensitive. It needs an idempotency key and a single-use confirmation token, and its responses say exactly what happens on a replay or a stale hold.

booking-tools.openapi.yaml · excerpt
openapi: 3.1.0
info: { title: Booking tools, version: 2.3.0 }
paths:
  /bookings:
    post:
      operationId: commit_booking
      summary: Commit a held booking. Requires a confirmation token.
      parameters:
        - { name: Idempotency-Key, in: header, required: true, schema: { type: string, minLength: 16 } }
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [hold_id, confirmation_token]
              properties:
                hold_id:            { type: string }
                confirmation_token: { type: string, description: Single use, issued after the guest's explicit CONFIRM }
      responses:
        "201": { description: Committed, content: { application/json: { schema: { $ref: "#/components/schemas/Booking" } } } }
        "200": { description: Same Idempotency-Key replayed; returns the original booking }
        "409": { description: Hold expired or already committed }
        "422": { description: Token invalid, expired or already used }
        "403": { description: Caller scope or account ownership check failed }

The same tool, as an MCP definition

The assistant sees tools through the Model Context Protocol. The definition repeats the constraints that matter: patterns, bounds, an enumerated list of services and read-only hints.

quote_services · MCP tool definition
{
  "name": "quote_services",
  "description": "Price a set of ground services at one airport for one aircraft. Read only. Prices come from the pricing service.",
  "inputSchema": {
    "type": "object",
    "required": ["airport", "arrival_from", "arrival_to", "aircraft_id", "services"],
    "properties": {
      "airport":      { "type": "string", "pattern": "^[A-Z]{4}$" },
      "arrival_from": { "type": "string", "format": "date-time" },
      "arrival_to":   { "type": "string", "format": "date-time" },
      "aircraft_id":  { "type": "string" },
      "services": {
        "type": "array", "maxItems": 12,
        "items": { "type": "object", "required": ["type"],
                   "properties": { "type": { "enum": ["fuel", "hangar", "handling", "crew_car", "catering", "deice"] },
                                   "quantity": { "type": "number", "minimum": 0 },
                                   "notes": { "type": "string", "maxLength": 200 } } }
      }
    }
  },
  "annotations": { "readOnlyHint": true, "idempotentHint": true }
}

Error model

CodeMeaningWhat the assistant does
invalid_argumentA field failed validationAsk the guest for the missing or corrected detail; never retry unchanged
not_foundAirport, aircraft or booking unknownCheck the identifier with the guest; do not guess
conflictHold expired or resources takenExplain, re-check availability and offer alternatives
forbiddenScope or ownership check failedDo not retry; offer a person; raise a security event
rate_limitedToo many callsBack off, then degrade
unavailableBackend down or timed outRetry once with the same key, then hand off

Sequence: a lost response and a safe retry

Idempotent commit with a retry and a cross-account rejection A commit succeeds in the booking system but the response is lost. The service retries once with the same idempotency key and receives the original booking. A separate attempt to cancel another account's booking is rejected and audited. Conversation service Tool gateway Booking system Audit log commit_booking, key K1 validate token, scope, owner create reservation, key K1 BK-20417 created response lost: timeout unavailable retry once, same key K1 commit_booking, key K1 create reservation, key K1 key seen: return original BK-20417, 200 BK-20417 cancel_booking BK-9, other account owner is not the verified account audit: denied call forbidden
Idempotent commit with a retry and a cross-account rejection

The retry cannot double-book because the key identifies the request. The rejection happens in the gateway, before any backend sees the call.

Rules every tool follows

  1. Idempotency

    Every write takes an idempotency key. A replay returns the original result and never creates a second one.

  2. Ownership

    The tool gateway binds each call to the verified account. An identifier from another account is rejected, whatever the model asked for.

  3. Bounded output

    Responses are structured and size-limited. Customer-entered notes are stripped before the model sees them.

  4. Versioning

    Contracts are versioned. A breaking change is a new major version, run side by side until the evaluation set passes on it.

  5. Audit

    Each call writes an audit record with the arguments hash, the caller, the outcome and the trace identifier.

Contract tests

Build this for your business

This example is a booking assistant for a ground-handling network, but the same pattern, a governed gateway, runtime security, grounded knowledge, deterministic commits and measured quality, fits any customer-facing assistant that takes actions. We can scope a pilot on your own systems.

Book a discovery call