ExAgent. Tool. RepeatGuard
(ExAgent v2.3.0)
View Source
Capability that tells the model when it keeps repeating an identical tool call.
Models sometimes loop: they call the same tool with the same arguments, get
the same result and call it again until the step budget runs out. Before each
model request this capability counts the calls made since the latest user
message. When the model's latest response repeats a call (same tool name and
equal decoded arguments) for the :warn_at-th time or more, the request gets
a short runtime note asking it to use the earlier result, change the
arguments or explain what is blocking it.
ExAgent.new(
model: model,
tools: tools,
capabilities: [compaction, ExAgent.Tool.RepeatGuard.new(warn_at: 3)]
)The note exists only in the projection sent to the model, like the final-step
instruction: the canonical history and events never contain it (a persisted
continuation's request record captures the projection actually sent). It is rebuilt from the history at the same position in every later
request of the task, so the request prefix stays stable for provider prompt
caches and for providers that check signed reasoning against it. It never
blocks a call; use ExAgent.Permissions, :max_steps or usage limits
to bound execution. List it after capabilities that rewrite the projection,
such as compaction, so they do not treat the note as the user's request.
Options (struct fields):
:warn_at— repetition count that triggers the note (default3, minimum2).:tools—:all(default) or the tool names to watch. Exclude tools that are expected to repeat, such as polling a job status.
Summary
Functions
Callback implementation for ExAgent.Capability.after_model_request/2.
Callback implementation for ExAgent.Capability.after_tool_execute/4.
Callback implementation for ExAgent.Capability.before_tool_execute/3.
Build a validated guard. Raises ArgumentError for invalid options.
Types
@type t() :: %ExAgent.Tool.RepeatGuard{ tools: :all | [String.t()], warn_at: pos_integer() }
Functions
Callback implementation for ExAgent.Capability.after_model_request/2.
Callback implementation for ExAgent.Capability.after_tool_execute/4.
Callback implementation for ExAgent.Capability.before_tool_execute/3.
Build a validated guard. Raises ArgumentError for invalid options.