bikkamora
0 / 2 done (0%)
Lesson 02•25 min read•Interactive Invariant

Bounding Execution Loops & Tool Calling Schemas

What Happened in Production?

Your payment agent invokes an external banking API with a refund amount formatted as "$50.00" (string) instead of 5000 (cents integer). The API fails with an unhelpful 400 error. The agent re-invokes with "50.00 USD", escalating the failure. How do strict JSON Schema contracts prevent argument hallucination before packets ever hit the network?

Target Architectural Invariant

Author unambiguous tool definitions using strict schema constraints and implement pre-flight argument validation.

System Prediction
Predict before reading

Why is it critical to set "additionalProperties: false" on all tool argument schemas passed to language models?

Tool Contracts as Security Boundaries

In an agentic architecture, tools are the boundary where non-deterministic text generation interacts with deterministic production systems.

Every tool definition must treat the model as an untrusted client. The application must validate every argument against an exact schema before executing the handler.

Idempotency and Side-Effect Isolation

Network calls drop. Connections timeout. If an agent calls a payment tool, the network drops before receiving the response, and the agent retries, will it charge the user twice?

Every mutating tool must accept a deterministic idempotency key derived from the conversation ID and step index.

Production Incident Analysis
POSTMORTEM

Incident Analysis: Duplicate Order Fulfillment via Unbounded Retry

Context

A fulfillment warehouse agent was processing physical shipment labels.

Assumption

Developers assumed the model would know whether a label had been created based on the assistant message history.

Observed Failure

A transient socket timeout caused the label creation call to return an error observation. The model retried with slightly altered dimensions. Two physical shipping labels were generated and printed for a single customer order.

Root Cause

The tool lacked an idempotency key tied to the order ID.

System / Cost Impact

Duplicate inventory dispatched and unnecessary carrier freight charges.

Remediation

Added mandatory idempotency keys (`idempotency_key = order_id + "_" + item_sku`) to the tool contract.

Engineering Rule

All mutating agent tools must be idempotent. Never rely on the language model to manage transaction safety.

Architectural Checkpoint
Single Choice

What is the most reliable way to generate an idempotency key for an agent tool call?

System Implementation Challenge
EXERCISE

Exercise: Writing a Zero-Tolerance Tool Contract

Author a tool definition for an automated database query analyzer that prevents destructive SQL execution.

System Invariants & Hard Constraints:
  • •Must reject non-SELECT statements at the schema parser level
  • •Enforce mandatory execution timeout parameter
  • •Set additionalProperties to false
Revealed 0 of 4 tiers

Key Engineering Invariants

  • 01Treat the model as an untrusted caller at all tool boundaries.
  • 02Enforce strict JSON schemas with additionalProperties: false.
  • 03Every state-mutating tool must implement idempotency keys.