Tool Invocation

12 patterns for this goal

Tool invocation fails when agents pass wrong arguments, use wrong ID or key formats, misunderstand tool semantics, fail to page results, or retry non-idempotent operations without side-effect awareness. The 12 invocation patterns documented here cover the challenge of calling tools correctly β€” from parameter validation through pagination, query scoping, timezone handling, and understanding when operations are idempotent. Invocation failures are particularly common because agents must understand and respect tool contracts (what parameters it accepts, what they mean, what side effects occur), and misunderstanding any part of that contract leads to failed or incorrect tool calls.

Key Takeaways

  • 12 patterns documented: parameter validation, ID/key usage, query scoping, pagination, timezone, idempotency, side effects, rate-limiting, result handling, and format errors.
  • Missing Required Parameter and Wrong Argument Format are most severe: missing required parameters cause tool failures, wrong format (string vs integer) causes parsing errors.
  • Over Broad Query and Over Narrow Query are second-order: agents don’t scope queries correctly, returning too much (inefficient, expensive) or too little (missing relevant results) data.
  • Idempotency Failure and Side Effect Misunderstanding are architectural failures: agents don’t know whether operations are idempotent or what side effects they cause, leading to unwanted retries or cascading effects.

Scope

When Tool Invocation Matters

  • Agents invoke tools with complex parameters where correct formatting and scope matter.
  • Tools have side effects or state changes; retrying without idempotency awareness causes duplicate writes.
  • Tools return paginated results; agents must navigate pagination to get complete data.

Cross-Pattern Insight

The 12 invocation patterns describe systems where tool semantics are implicit: agents guess what parameters mean, whether operations are idempotent, whether queries are scoped correctly, without explicit validation or documentation. Tool documentation exists but is incomplete, and agents must infer semantics from example usage or error messages. Most teams discover invocation failures only after agents start calling tools incorrectly and cascading failures reveal the misunderstandings. The mitigation that recurs across nearly every pattern is explicit contract validation: use API contracts to specify required parameters and their formats, document idempotency and side effects explicitly, test tool invocation with correct and incorrect parameters, and add agent-level validation before calling tools.

Frequently Asked Questions

How do you prevent wrong-argument-format errors?

Per Wrong Argument Format, validate argument types and formats before calling tools: check that IDs are strings not integers, dates are ISO 8601 not user-locale format, amounts are in correct currency. Use API contracts (OpenAPI, schema) to specify expected formats and validate against them.

What should an agent do if pagination is required?

Per Pagination Failure, agents should check for pagination metadata (e.g., has_next, next_token), and iterate through all pages rather than assuming first page is complete. Test pagination by requesting large result sets and verifying all results are retrieved.

How do you understand tool idempotency?

Per Idempotency Failure, ask the tool documentation: is calling this operation twice with same parameters safe? If yes, idempotent; if no, non-idempotent. Never retry non-idempotent operations automatically β€” log the failure and require manual intervention or explicit retry logic that accounts for side effects.

Can over-broad queries be optimized after the fact?

Partially β€” per Over Broad Query, agents should scope queries before calling (filter by date range, category, etc.) rather than retrieving everything and filtering client-side. Over-broad queries waste resources and cost; filter server-side first.

Patterns

PatternMechanism
Idempotency FailureNon-idempotent operation is retried; retries cause duplicate writes or state corruption
Missing Required ParameterTool requires a parameter; agent doesn’t provide it; call fails
Over Broad QueryQuery is not scoped; returns expensive results; agent wastes resources and cost
Over Narrow QueryQuery is over-scoped; misses relevant results; agent gets incomplete data
Pagination FailureResults are paginated; agent doesn’t iterate through pages; misses data
Partial Result MisuseFirst page of paginated results is used as if it’s complete; missing data treated as not-found
Rate Limit/Timeout MishandlingTool returns rate-limit or timeout error; agent doesn’t backoff appropriately
Side Effect MisunderstandingAgent doesn’t understand or underestimates operation side effects; cascading failures result
Wrong Argument FormatArgument format is wrong (string vs integer, ISO date vs locale date); tool parsing fails
Wrong Date Range/TimezoneDate range is wrong timezone; agent retrieves data from wrong time period
Wrong ID/Key UsageAgent uses wrong ID format or references wrong ID; retrieves wrong record
Wrong Units/CurrencyUnits or currency are mismatched; calculations are incorrect

Total: 12 patterns

Pagination Failure

Frequency: Common
Category: Operations

Agent Reads Only the First Page of a Paginated or Length-Capped Tool Response and Proceeds as if That Page Were the Complete Result Set