Skip to Content
AgentShield
Fundamentals

Tool Execution Lifecycle

How an authorized decision becomes exactly one adapter run. Claiming, argument binding, deadlines, completion, failure, and repeat calls.

Authorization records a decision. Execution turns an allow, or an approved require_approval, into one run of a registered adapter. The lifecycle is designed so a side effect happens at most once, even across crashes, timeouts, and retries.

The execute request

{
  "decision_id": "7f1c2a9e-…",
  "idempotency_key": "idem-5f0d2c8e9a1b4c7d",
  "approval_id": "3b9e…",
  "arguments": { "headers": { "Accept": "application/json" } }
}
FieldRequiredMeaning
decision_idyesThe decision returned by authorize
idempotency_keyyesMust equal the key used at authorize
approval_idonly for require_approvalThe approved approval request. Refused for an allow decision
argumentsfor adapters that use argumentsThe same arguments that were authorized. Omitted means {}

Execute is signed exactly like authorize, with a fresh nonce.

States

Step by step

Load and check the decision

The gateway authenticates the request, then loads the decision for the authenticated agent in its organization. A decision belonging to another agent is 404 not_found.

  • Idempotency key mismatch → 409 conflict.
  • deny → 403 forbidden ("decision is deny").
  • require_approval without approval_id → 409 approval_required.
  • allow with an approval_id → 409 conflict.

Find the adapter and bind the arguments

The tool must have a registered adapter that supports the operation, or the response is 501 not_implemented and nothing is claimed. For adapters that use arguments, such as http.request, the gateway canonicalizes the presented arguments, hashes them, and compares the hash with the one stored at authorize. A mismatch is 409 conflict ("arguments do not match the decision").

Raw arguments are never stored, because tool arguments often carry secrets. Binding by hash lets the gateway prove that what runs is what policy saw.

The adapter then validates the call without side effects, for example checking that the URL is canonical and the host is allowed. A rejection is 400 validation_failed.

Claim

In one transaction the gateway locks the execution row and:

  1. Returns the stored result if the execution already completed.
  2. Refuses with 409 conflict if a previous attempt was already dispatched without a recorded outcome.
  3. Consumes the approval if one was presented. See Human approvals.
  4. Checks the tool's circuit. An open circuit returns 503 circuit_open and rolls back, so the approval stays usable.
  5. Records dispatched_at and the adapter name, and commits.

Run

The adapter runs outside any transaction, with its deadline: two seconds by default, or the adapter's own (five seconds by default for http.request, up to 30). Keeping the run outside the transaction means a failed commit can never cause a second run.

Analyze (optional)

When the gateway has INTELLIGENCE_URL, the strings in the arguments and result are sent to the intelligence engine. The report is attached as analysis. It never changes the outcome. See Prompt injection analysis.

Complete or fail

A second transaction records the outcome:

  • Success. Status completed, the redacted result, and a tool.executed event. If analysis flagged the content, one alert per rule and a content.flagged event are written in the same transaction.
  • Failure. Status failed, the failure kind (timeout, rejected, or adapter_error), and a tool.failed event. Adapter failures other than validation rejections count toward the circuit.

The first execute returns the live result. A timeout surfaces as 500 internal_error with the message "tool adapter timed out".

Repeat calls

SituationResponseAdapter called?
Execution completed200 with the stored, redacted resultNo
Execution failed409 conflictNo
Dispatched but outcome unknown (crash)409 conflictNo
Circuit was open on the previous tryClaim was rolled back; retry is allowedYes, once

A retry after a timeout or crash requires a new authorize. This trades a little availability for a hard guarantee that a side effect is never repeated.

In the SDKs

call_tool / callTool performs authorize and, only on allow, execute with the same arguments. To execute an approved decision yourself:

executed = client.execute(
    decision.decision_id,
    decision.idempotency_key,
    approval_id=decision.approval_id,
    arguments=arguments,          # exactly what you authorized
)

Was this page helpful?

On this page