nodestep.middleware.tool_limit ¶
ToolLimitMiddleware, which denies tool calls over a budget per run.
See Built-in middleware.
ToolLimitMiddleware¶
ToolLimitMiddleware(*, max_calls=50, per_tool=None)
Deny tool calls over a budget per run and its resumes; the model is told.
Subclass of Middleware.
Put it in the graph's middleware: tool calls of a run it did not see
start raise GraphConfigError. Budgets live in this instance's memory;
see Built-in middleware.
max_calls | int |
Total calls allowed per run. |
per_tool | dict[str, int] | None |
Limits for individual tools. |
Methods
before_graph(ctx)¶
Start a fresh budget, or keep the budget of a resumed run.
before_graph(ctx)¶before_graph(ctx) -> None
after_graph(ctx)¶
Drop the budget of the finished run.
after_graph(ctx)¶after_graph(ctx) -> None
before_tool(ctx)¶
Count the call once per tool call id and deny it over the limit.
before_tool(ctx)¶before_tool(ctx) -> Replacement | None
ToolDeniedError |
If the call is over a limit. |
GraphConfigError |
If the call belongs to no graph run this instance saw start. |