-
-
Notifications
You must be signed in to change notification settings - Fork 104
86: Add default limit for tools completions #87
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
base: main
Are you sure you want to change the base?
Conversation
lib/ruby_llm/chat.rb
Outdated
@@ -105,6 +107,10 @@ def handle_tool_calls(response, &) | |||
end | |||
|
|||
def execute_tool(tool_call) | |||
raise ToolCallsLimitReachedError, "Tool calls limit reached: #{@max_tool_calls}" if max_tool_calls_reached? |
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.
It might be worth discussing if this should be handled via the chat instead of raising an unhandled error.
- Otherwise the chat object could not have 'ask' executed on again due to malformed messages
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.
changing the whole interface to chat
is a bit heavy handed. this should be a simple config change.
lib/ruby_llm.rb
Outdated
def chat(model: nil, provider: nil) | ||
Chat.new(model: model, provider: provider) | ||
def chat(model: nil, provider: nil, max_tool_completions: config.max_tool_completions) | ||
Chat.new(model: model, provider: provider, max_tool_completions: max_tool_completions) |
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.
changing the whole interface to chat
is a bit heavy handed. this should be a simple config change.
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.
Thanks for the feedback @crmne. I've adjusted things so the chat interface isn't modified, and instead, a single instance can use an override from the config using with_max_tool_completions
.
Please let me know what you think?
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.
@crmne would love an update here ... I'm getting looping tool calls as well, and would like to avoid implementing my own solution.
Resolves #86
Purpose
Introduces a configurable limit on tool completions to prevent infinite loops and excessive API usage. This feature adds protection against scenarios where AI responses might trigger continuous tool calls.
Implementation Details
max_tool_completions
configuration option (default: 25 calls)RubyLLM.chat.with_max_tool_completions(N)
ToolCallCompletionsReachedError
when limit is exceedednumber_of_tool_completions
counternil
Usage Example
Testing
Documentation
TODO