5.7 Agent Safeguards, Tool Reliability & Cost Control
Key Takeaways
- Bound steps, time, tokens, tool calls, retries, and cost.
- Separate read and write tools and require approval for high-impact operations.
- Validate arguments server-side and make state-changing retries idempotent.
- Measure prompt-stage changes; post-processing is disabled by default and disabling orchestration changes behavior.
- Protect trace data and score tool trajectories, not only final prose.
5.7 Agent Safeguards, Tool Reliability & Cost Control
Agent optimization begins with a risk and completion contract, not with deleting prompt stages. Define what the agent may read, what it may change, which actions need confirmation, the maximum iterations and wall-clock time, the retry budget, and the evidence that proves the task succeeded.
Bound autonomous execution
Apply least privilege to the agent execution role and each downstream tool. Separate read-only discovery from state-changing operations. A refund, account change, deployment, or deletion should require a policy check and, when impact warrants it, a human approval or application-controlled confirmation outside the model's discretion.
Set limits on steps, time, tokens, tool calls, and cost. A tool failure should return a typed, bounded observation that distinguishes validation, authorization, conflict, transient dependency, and permanent business errors. Do not let the model retry an unbounded generic error.
State-changing tools need idempotency keys and explicit preconditions. If an agent times out after a successful payment call, retrying must return the existing result rather than charging again. Where possible, expose a dry-run or read-before-write operation and record an authoritative transaction identifier.
Prompt-step optimization
Current agent configuration lets teams alter promptState. Pre-processing, knowledge-base response generation, and post-processing can be skipped when disabled; post-processing is disabled by default. Disabling orchestration sends the input to the model without normal orchestration of actions and knowledge bases. Measure the exact configuration before claiming savings.
An upstream validator can reduce the need for some classification work, but authentication and schema checks do not automatically replace semantic safety review. Compare quality, unsafe-action rate, task completion, p95 latency, and tokens with and without a stage. A percentage saved on one demo prompt is not a production guarantee.
Trace-driven diagnosis
InvokeAgent with enableTrace can return trace events for applicable processing stages. Use the current trace schema to examine model invocation input, selected action, parameters, observation, collaborator or knowledge-base activity, and failure information. Field availability depends on the execution path and service version; do not promise an application stack trace when the service returns a typed orchestration failure instead.
Traces may contain sensitive prompt content, retrieved passages, tool arguments, and outputs. Restrict access, encrypt destinations, apply retention, and redact before support or analytics use. A reasoning trace is diagnostic evidence, not a security decision or a proof that the final action was authorized.
When the same action repeats, inspect whether the observation reached the next iteration, whether the parser accepted it, whether the tool returned the documented envelope, and whether the prompt has a stopping rule. Also check idempotency, timeouts, duplicate event delivery, and maximum-step enforcement. Missing scratchpad context is one possible cause, not the universal answer.
Measure agent outcomes
Track task completion, correct tool selection, argument validity, authorization denial, approval outcome, retry count, duplicate suppression, latency, tokens, cost, user correction, and rollback success. Evaluate adversarial prompts and poisoned tool or retrieval content. A fluent final message can conceal an unauthorized or failed action, so score the trajectory and external state.
The professional answer minimizes agency while retaining required capability: narrow tools, typed schemas, server-side validation, bounded loops, idempotency, approvals for high-impact changes, protected traces, and a tested fallback when the agent cannot complete safely.
Worked transaction boundary
Consider an address-change agent. A read tool retrieves the current address and allowed countries. A proposed-change tool validates format and returns a short-lived proposal ID without mutating state. The application then authenticates step-up confirmation and calls a narrowly scoped commit tool with the proposal ID and an idempotency key. The commit service rechecks ownership, expiry, and policy before writing. If the agent repeats the call, the same key returns the original result.
This design keeps identity and authorization outside the model, exposes a reversible review point, and makes retries safe. The trace can say which proposal and transaction were used without storing the full address in a general log. Test stale proposals, cross-user proposal IDs, duplicate commits, dependency timeouts, partial success, and rollback. A similar boundary applies to refunds, ticket closure, deployments, and data deletion.
Failure and fallback policy
Define which failures can be retried, which require new user input, which require human review, and which stop immediately. A schema validation error is not repaired by blind retries; a transient dependency timeout can use a bounded retry if the operation is idempotent. When the agent reaches its budget, return an explicit incomplete status and preserve enough controlled state to resume safely. Never describe an unexecuted plan as a completed business action.
Failure-policy table
| Failure class | Safe response |
|---|---|
| Invalid tool arguments | Return typed validation details; ask for missing data or stop |
| Authorization denial | Stop; never retry with broader credentials |
| Transient dependency timeout | Retry within the deadline only when the operation is idempotent |
| Ambiguous high-impact request | Require clarification and external approval |
| Step or cost budget exhausted | Return an explicit incomplete status and preserve controlled resume state |
| Partial state change | Reconcile by transaction ID and invoke the documented compensation path |
A Bedrock Agent can issue customer refunds. Which design most directly limits the impact of prompt injection?
An agent repeatedly calls the same action group. What is the best first diagnostic approach?