Why contracts come first
The tools are the only way the platform can change a balance, a hold or a message. 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.
- Arguments are typed, bounded and validated by the tool gateway, never trusted from the model.
- Every tool declares whether it changes anything, whether it is safe to retry and what scope it needs.
- Miles are never taken from a model: the credit must equal the rule engine's result for the segment.
- A write states why it is allowed: a rule, a named approver or an approved goodwill gesture.
The tool catalogue
| Tool | Purpose | Changes data | Safe to retry | Scope | Needs approval |
|---|---|---|---|---|---|
| get_member_summary | Read tier, balance and status, with identity masked | No | Yes | member.read | No |
| get_flight_activity | Read a segment, class and prior credits | No | Yes | activity.read | No |
| search_program_terms | Retrieve program terms with citation, effective date and tier | No | Yes | knowledge.read | No |
| get_claim_evidence | Gather ticket, flight and prior-claim evidence | No | Yes | evidence.read | No |
| calculate_miles | Compute miles and qualifying miles by the rules | No | Yes | rules.read | No |
| price_award | Price an award with a plain-language reason | No | Yes | pricing.read | No |
| propose_credit | Record a proposed credit with evidence | Yes, a proposal only | Yes, by key | credit.propose | No |
| post_miles | Credit miles to an account | Yes | Yes, by key | ledger.post | Within 10,000 and equal to the rule result: no. Otherwise a person |
| reverse_entry | Reverse a ledger entry | Yes | Yes, by key | ledger.reverse | A person |
| redeem_award | Debit miles for an award | Yes | Yes, by key | redeem.write | Step-up result required |
| place_account_hold | Place a time-limited hold | Yes | Yes, by key | account.hold | Fraud analyst for high-risk, rule for step-up |
| check_consent | Read channel and purpose permission | No | Yes | consent.read | No |
| send_member_message | Send an approved message | Yes | Yes, by key | message.send | Approved template and a consent check |
An operation, in OpenAPI
Posting miles is the most sensitive write. The operation requires an idempotency key and a stated basis, the miles must equal the rule result, and its responses say exactly what happens on a replay or a conflict.
openapi: 3.1.0
info: { title: Loyalty tools, version: 1.6.0 }
paths:
/ledger/entries:
post:
operationId: post_miles
summary: Credit miles to an account. Append-only; corrections are reversals.
parameters:
- { name: Idempotency-Key, in: header, required: true, schema: { type: string, minLength: 16 } }
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [member_id, miles, source, basis]
properties:
member_id: { type: string }
miles: { type: integer, minimum: 1, maximum: 250000 }
qualifying: { type: integer, minimum: 0 }
source: { type: string, enum: [flight, partner, claim, goodwill] }
source_ref: { type: string }
basis: { type: string, enum: [rule, approved_by_person, goodwill_approved],
description: Why this credit is allowed; the last two need approver_id }
approver_id: { type: string }
responses:
"201": { description: Posted }
"200": { description: Same Idempotency-Key replayed; returns the original entry }
"409": { description: Segment already credited to this or another member }
"422": { description: Basis not permitted for this amount, or miles not equal to the rule result }
"403": { description: Caller scope failed }A read tool, as an MCP definition
The platform sees tools through the Model Context Protocol. The definition repeats the constraints that matter: a pattern for flight numbers, required fields and read-only hints.
{
"name": "get_flight_activity",
"description": "Read the segment a member claims: whether it was flown by this member, in which booking class, and whether miles were already credited. Read only.",
"inputSchema": {
"type": "object",
"required": ["member_id", "flight_number", "flight_date"],
"properties": {
"member_id": { "type": "string" },
"flight_number": { "type": "string", "pattern": "^[A-Z0-9]{2}[0-9]{1,4}$" },
"flight_date": { "type": "string", "format": "date" }
}
},
"annotations": { "readOnlyHint": true, "idempotentHint": true }
}Error model
| Code | Meaning | What the platform does |
|---|---|---|
| invalid_argument | A field failed validation | Route to a person with the reason; never retry unchanged |
| not_found | Segment, member or claim unknown | Check the identifier; do not guess |
| conflict | Segment already credited, or an entry already reversed | Re-read state and reconsider; never force |
| forbidden | Scope or approval check failed | Do not retry; route to a person; raise a security event |
| rate_limited | Too many calls | Back off, then queue |
| unavailable | Backend down or timed out | Retry once with the same key, then queue for a person |
Rules every tool follows
Idempotency
Every write takes an idempotency key. A replay returns the original result and never creates a second one.
Basis and approval
A write states why it is allowed. The tool gateway checks the basis against the amount and the caller's authority.
Rules decide amounts
Credits must equal the rule engine's result for the source. A model-supplied number that differs is refused.
Versioning
Contracts are versioned. A breaking change is a new major version, run side by side until the evaluation set passes on it.
Audit
Each call writes an audit record with the arguments hash, the caller, the basis, the outcome and the trace identifier.
Contract tests
- Every tool definition validates against the schema and has an owner, a scope and a retry rule.
- Property tests send out-of-range, oversized and malformed arguments and expect invalid_argument, never a partial write.
- A replay test sends each write twice with the same key and expects one result.
- A rule-result test posts amounts that differ from the rule engine and expects a refusal.
- The Foundry build and the LangGraph build run the same contract suite against a mock backend.
Build this for your business
This example is a loyalty platform for an airline, but the same pattern, deterministic financial rules, a governed gateway, runtime security, consent-aware personalisation and measured quality, fits any program that holds a customer balance and makes offers. We can scope a pilot on your own systems.
Book a discovery call