Max Calls
Max Calls is a middleware that limits the number of calls to a node or model. This can be useful if you want tools to be called just once per workflow, or in general if you want to limit the number of calls to a tool.
import railtracks as rt
from railtracks.prebuilt.middleware import MaxCalls
def some_api_call():
return "API response"
# MaxCalls is slot-agnostic: use it as node middleware, model middleware, or both.
LimitedApiCall = rt.function_node(
some_api_call,
middleware=[MaxCalls(max_calls=3, custom_message="API call budget exhausted")],
)
Because it only controls the wrapped call, Max Calls works in both
middleware= and model_middleware=. The limit is enforced on the complete call in
the selected slot.