-
Notifications
You must be signed in to change notification settings - Fork 19.3k
feat(langchain_v1): Add ToolCallLimitMiddleware #33269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This defaults to __class__.__name__ as before, but can be overriden to support using multiple instances of same middleware in same agent
…either all tools, or a specific tool
class ToolCallLimitMiddleware(AgentMiddleware): | ||
"""Middleware that tracks tool call counts and enforces limits. | ||
|
||
This middleware monitors the number of tool calls made during agent execution |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
--
Thoughts on integration with SummarizationMiddleware which will be removing messages from chat history? Should the middleware extend the state to keep track of tool calls? Or do we just document?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just document
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious if you have any specific opposition to tracking in state? (or do you think it's too much complexity for this middleware?)
Looks good as an initial pass! I feel like if you have 10 tools and you want different limits for each of them it might be a bit annoying to have 10 middlewares (a map would be nicer), but that seems like a pretty out there use case. |
What do we do if the model decides to call |
which implements a tool call budget for either all tools, or a specific tool