Skip to content

Article

Agent Next-Action Routing: The Pattern That Uses the Decisions API Well

Agent loops fail in predictable ways: free-text tool names, hallucinated arguments, parser errors. Routing the next action through the Decisions API makes the loop deterministic.

The failure mode

A general agent picks its next tool in prose. The tool name must then be extracted, parsed, and validated. Every step is a place where the loop can break — and retries are where latency and cost quietly multiply.

The pattern

Declare the action space as choices and let the Decisions API do the selection:

  • choices: ['call_weather_api', 'ask_user', 'escalate', 'end_conversation']
  • context: the conversation and any tool results so far
  • response: exactly one action, ready to dispatch

Why it holds up

The invariant is the point: the returned action is always one of the declared set, by construction. The agent no longer needs an extraction step, and the routing loop can be tested against a fixed contract instead of against model whims.

Back to all guides