Lesson 3 of 5 Observability for Generative AI and Agents

Monitoring Agent Tool Failures, Coordination and Truncation

This lesson explains how to monitor the agent failure modes that the exam guide names: tool errors, coordination problems between agents and responses cut off mid-stream.

Learning outcomes

After completing this lesson, you will be able to:

  • Detect and handle tool failures.
  • Detect coordination failures in multi-agent systems.
  • Detect truncated streaming from stop reasons.

Tool failures

Tools are where agents meet other systems, and they fail in several ways: errors from the system behind the tool, timeouts, throttling, invalid parameters generated by the model, and permission problems. The tool error rate and tool latency for each tool are monitored from traces and Lambda metrics.

Failures are mitigated with retries and exponential backoff for transient errors, clear error messages that the model can act on, validation of inputs before the tool runs, fallback tools, and circuit breakers that stop calling a failing dependency so the agent does not waste tokens retrying it.

The following diagram shows the safeguards around a booking agent whose availability tool sometimes times out.

The booking agent's safeguards. The availability tool has a 5-second timeout, two retries with backoff and an error message telling the agent to offer other dates; custom metrics for tool timeouts and max_tokens stops alarm above 2%; maxTokens is raised for itineraries; and sessions are capped at 15 iterations, after which a human takes over.
The scenario is illustrative.
Troubleshooting scenario

An agent that fails

Exam skills 4.1.5

Diagnose agent failures one at a time.

Log in to try this activity Interactive activities are free with an account.

Coordination failures

In multi-agent systems, a supervisor may route a task to the wrong collaborator, agents may hand tasks back and forth in a loop, context may be lost in hand-offs, or an agent may stop without completing its part. Detect these with traces that show the sequence of agent invocations, counts of iterations per session, repeated identical tool calls and sessions that end without a final answer. Mitigate with maximum iteration and time limits, clear collaborator descriptions, structured hand-off messages and escalation to a human when limits are reached.

Truncated streaming

Streaming responses can end early. The stop reason returned by the Converse or ConverseStream API shows why: end_turn (normal), max_tokens (output limit reached, answer cut off), stop_sequence, tool_use, guardrail_intervened or content_filtered. Connection drops and client timeouts also truncate output without a stop reason. Monitor the share of max_tokens stops and incomplete streams, raise limits or ask for shorter answers, and implement reconnection or continuation. The following table summarises the failure modes.

FailureDetectMitigate
Tool error or timeoutTool error rate and latency in tracesRetries, backoff, fallback, validation
Agent loopIterations per session, repeated callsIteration limits, alarms, human escalation
Wrong routing between agentsTrace of agent invocationsBetter collaborator descriptions, routing tests
Truncated outputStop reason max_tokens, incomplete streamsRaise max tokens, shorten output, continuation
Guardrail stopsStop reason guardrail_intervenedReview policy and prompts
True or false

Truncated answers

Exam skills 4.1.5

Check how to detect and handle truncated responses.

Log in to try this activity Interactive activities are free with an account.
Worked example

Automating agent recovery

A booking agent occasionally hangs when a partner's availability API times out, and some itineraries are cut off mid-response.

  • Wrap the availability tool with a 5-second timeout, two retries with backoff and a clear error message telling the agent to offer alternative dates.
  • Publish custom metrics for tool timeouts and for responses with stop reason max_tokens; alarm when either exceeds 2%.
  • Raise maxTokens for the itinerary step and instruct the agent to summarise long itineraries.
  • Cap sessions at 15 iterations and route capped sessions to a human agent.

The agent now degrades gracefully, and alarms show the team when a partner API or prompt change causes new problems.

Check yourself

Answers are cut off. What should be checked?

Show answer

Whether the stop reason is max_tokens, and whether streams time out.

Exam Tips

Remember for the exam

  • Answers cut off: check for stop reason max_tokens and stream timeouts.
  • Agent loops: iteration limits and alarms on repeated tool calls.
  • Tool failures: retries with backoff, fallbacks and clear error messages.
  • Multi-agent routing problems: inspect traces of agent invocations.
  • Escalate to a human when limits are reached.