fix tool limiting#1198
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR changes the tool limiting strategy from raising exceptions to returning a message when the tool usage limit is exceeded. It removes the custom ToolUseLimitExceeded exception and associated error handling, replacing it with a return value that instructs the agent to continue with gathered information.
- Removes
ToolUseLimitExceededexception class and related error handling - Changes tool limit enforcement to return a message instead of raising an exception
- Reduces default max tool calls from 50 to 5
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| examples/slackbot/src/slackbot/wrap.py | Removes exception class and changes limit enforcement to return a message |
| examples/slackbot/src/slackbot/settings.py | Reduces default max tool calls from 50 to 5 |
| examples/slackbot/src/slackbot/api.py | Removes import and exception handling for ToolUseLimitExceeded |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if total_calls > max_tool_calls: | ||
| # Return a message that tells the agent to stop using tools and continue | ||
| # This will be returned as the tool result, which the agent will see | ||
| return "Tool use limit reached. Please continue with the information you've gathered so far to answer the user's question." |
There was a problem hiding this comment.
Returning a string when the function is expected to return type T breaks the function's type contract. This could cause type errors or unexpected behavior for callers expecting the original return type.
| return "Tool use limit reached. Please continue with the information you've gathered so far to answer the user's question." | |
| return None |
| if len(args) > 1: | ||
| tool_name = args[1] | ||
|
|
||
| # Always track and enforce tool usage limits |
There was a problem hiding this comment.
The comment says 'Always track and enforce' but the tracking logic only runs when _progress_message.get() returns a truthy value (line 112). This creates inconsistency between the comment and actual behavior.
| # Always track and enforce tool usage limits | |
| # Always enforce tool usage limits; progress tracking occurs only if a progress message context is present |
No description provided.