Annotates tool results with error recovery guidance for the LLM.
After each tool execution round, inspects the results and appends human-readable guidance: what went wrong, how to recover, and what to try instead. Uses JSON-aware error detection rather than naive string matching.
Usage
# As a post-tool-execution step in a graph:
annotations = LangEx.Tool.Annotation.annotate(state.messages)
# => %{messages: [...updated...]} or %{}Options
:empty_threshold— byte size below which a result is considered empty (default200):large_threshold— byte size above which a result triggers a "large result" note (default50_000):error_detector—fn(content) -> boolean()(default: JSON error key detection):guidance_builder—fn(content) -> String.t() | nilfor custom error guidance
Summary
Functions
Annotate the latest tool results in the message list.
Detect whether a tool result contains a JSON error payload.
Default error recovery guidance builder.
Extract the latest consecutive tool result messages from a message list.
Check whether the latest tool results contain substantive (non-empty, non-error) data.
Functions
@spec annotate( [LangEx.Message.t()], keyword() ) :: %{optional(:messages) => [LangEx.Message.t()]}
Annotate the latest tool results in the message list.
Returns %{messages: updated_messages} if annotations were added,
or %{} if no annotations are needed.
Detect whether a tool result contains a JSON error payload.
Returns true if the content parses as JSON with an "error" or
"errors" top-level key.
Default error recovery guidance builder.
Inspects the error message and returns context-specific recovery advice.
@spec latest_tool_results([LangEx.Message.t()]) :: [LangEx.Message.Tool.t()]
Extract the latest consecutive tool result messages from a message list.
@spec tool_results_substantive?( [LangEx.Message.t()], keyword() ) :: boolean()
Check whether the latest tool results contain substantive (non-empty, non-error) data.