Skip to content

Conversation

@tian44200
Copy link

@tian44200 tian44200 commented Oct 30, 2025

Summary

Feature: Add tool-specific call limits
(Currently, we only have tool_call_limit that applies to the total count across all tools, not for individual tools.)

Why this feature: The query "search for Sherlock Holmes in the knowledge base" might trigger the search_knowledge tool up to 8 times in a single run. But we might only want it once in some cases. See more details in link to discord discussion.

Changes:
This PR only covers the following for now:

  • Custom tools → added call_limit for Function type
  • search knowledge (default tool) → added search_knowledge_call_limit for Agent(..)

This PR does not cover:

  • Toolkit and functions inside Toolkit (can be extended easily with the current implementation, but not sure about DX: add call limit for each tool inside or the whole toolkit? or later?)
  • Dict
  • Other default tools (read_chat_history, update_knowledge ...)

To be discussed:
As mentioned in Discord, the DX need to be discussed. The current implementation is just a suggestion and can be changed:

# with decorator
@tool(call_limit=3)
    def limited_func() -> str:
        return "test"

# as argument
func = Function(name="test_func", call_limit=5)

# for search knowledge (default tool)
agent = Agent(
    model=OpenAIChat(id="gpt-4o-mini"),
    knowledge=loaded_knowledge_base,
    search_knowledge=True,
    search_knowledge_call_limit=1,
    ...
)

Small Note: I noticed that continue_run/acontinue_run actually resets tool_call_limit. Not sure if this is intended. This PR also followed the same implementation logic, but if not, the issue can be handled in a later PR or this if needed.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Improvement
  • Model update
  • Other:

Checklist

  • Code complies with style guidelines
  • Ran format/validation scripts (./scripts/format.sh and ./scripts/validate.sh)
  • Self-review completed
  • Documentation updated (comments, docstrings)
  • Examples and guides: Relevant cookbook examples have been included or updated (if applicable)
  • Tested in clean environment
  • Tests added/updated (if applicable)

Additional Notes

The actual implementation follows the logic of the existing tool_call_limit logic so it should be safe.
I also tested on my personal project.
For search_knowledge_call_limit=1 and query="search for reinforcement learning and tabular reinforcement learning":

 [
{'id': 'd3e1857c1f6c4cf0bc7e9a4cb3c7fb1b', 'type': 'function', 'function': {'name': 'search_knowledge_base', 'arguments': '{"query": "reinforcement learning"}'}}, 
{'id': 'ad3a3b6703ac4022ba4f1ad5cd766c75', 'type': 'function', 'function': {'name': 'search_knowledge_base', 'arguments': '{"query": "tabular reinforcement learning}'}}]}, 
{'role': 'tool', 'content': "Call limit reached for search_knowledge_base. Don't try to execute this tool again.", 'tool_call_id': 'ad3a3b6703ac4022ba4f1ad5cd766c75'}, 
{'role': 'tool', 'content':'[\n  {\n    "content" ...', 'tool_call_id': 'd3e1857c1f6c4cf0bc7e9a4cb3c7fb1b' }, ...
]

@tian44200 tian44200 changed the title feat: add call limit for individual tools feat: support tool-specific call limits Nov 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant