agrag.agents.middleware.ResearchAttemptLimiter
ResearchAttemptLimiter(max_attempts:int) -> None
Bases: AgentMiddleware
Cap how many times the planner may re-delegate after verification.
Intercepts the generated task tool call and counts only
delegations to the researcher that follow at least one prior
delegation to the verifier. Once the cap is reached, short-circuits
with a message telling the planner to synthesize from evidence
already gathered, instead of letting the graph run until
recursion_limit aborts it with an opaque GraphRecursionError.
Holds per-run state, so construct one per ainvoke call, never
shared across runs.
Functions:
- awrap_tool_call – Count or short-circuit one task tool call.
Parameters:
- max_attempts (
int) – How many researcher re-delegations after the first verifier consultation the planner may make.
Raises:
ValueError– max_attempts is negative.
awrap_tool_call
awrap_tool_call(request:ToolCallRequest, handler:Callable[[ToolCallRequest], Awaitable[ToolMessage | Command[Any]]]) -> ToolMessage | Command[Any]
Count or short-circuit one task tool call.
Parameters:
- request (
ToolCallRequest) – The intercepted tool call request. - handler (
Callable\[[ToolCallRequest], Awaitable[ToolMessage | Command[Any]]]) – The rest of the tool-call pipeline.
Returns:
ToolMessage | Command[Any]– The handler's result, or the limit-reached ToolMessage whenToolMessage | Command[Any]– the planner has spent its retry budget.