Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

[FEATURE] Add tool filtering to use_llm and think meta-tools to prevent infinite recursion #73

Closed

Description

@cagataycali

Problem

Currently, the use_llm and think meta-tools can cause infinite recursion when they call themselves. For example:

  • use_llm calling use_llm within its execution creates an endless loop
  • think calling think during its thinking cycles causes stack overflow
  • Parent agents have no control over which tools child agents can access

This leads to:

  • 🔥 System crashes due to infinite loops
  • 💾 Memory exhaustion from uncontrolled recursion
  • 🎯 Lack of precision in tool access control
  • 🏗️ Poor architecture for nested agent scenarios

Proposed Solution

Add a tools parameter to both use_llm and think functions that allows parent agents to specify exactly which tools child agents can access.

Pull request: #72

Key Features:

  1. 🛡️ Infinite Recursion Prevention - Parent can exclude meta-tools from child agents
  2. 🎯 Fine-grained Control - Specify exact tool subsets for specialized tasks
  3. 🔄 Backward Compatibility - Existing code continues to work unchanged
  4. 📋 Tool Validation - Graceful handling of non-existent tools

Usage Examples:

# Prevent infinite recursion by excluding meta-tools
result = agent.tool.use_llm(
    prompt="Calculate something and read a file",
    system_prompt="You are a helper",
    tools=["calculator", "file_read"]  # Excludes use_llm itself
)

# Create focused thinking agent
result = agent.tool.think(
    thought="Analyze quantum computing implications",
    cycle_count=3,
    system_prompt="You are a quantum expert",
    tools=["journal", "file_read"]  # Only specific tools
)

Implementation Details

  • Add optional tools: list = None parameter to both functions
  • Implement tool registry filtering logic
  • Maintain backward compatibility (None = inherit all tools)
  • Add comprehensive test coverage
  • Include warning logs for invalid tool names

Benefits

For Developers

  • Safe Meta-Programming: No more infinite recursion concerns
  • Precise Control: Exact tool specification for specialized tasks
  • Better Architecture: Clean separation of concerns

For Production

  • Reliability: Eliminates infinite loop crashes
  • Resource Efficiency: Reduced memory and computation overhead
  • Predictable Behavior: Controlled tool access prevents unexpected behaviors

Acceptance Criteria

  • tools parameter added to use_llm function
  • tools parameter added to think function
  • Tool filtering logic implemented for both functions
  • Infinite recursion prevention working
  • Backward compatibility maintained (no breaking changes)
  • Comprehensive test coverage (>95%)
  • Documentation updated with examples
  • Manual testing with real agent scenarios
  • Warning system for invalid tool requests
  • Performance impact minimized

Priority

High - This addresses a critical system stability issue that can cause crashes and affects the core functionality of meta-tools.

Labels

enhancement, bug, meta-tools, high-priority, tools-filtering

Activity

  1. added
    bug
    enhancement
    on Jun 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugenhancementhigh-prioritymeta-tools

Type

No type

Fields

Language

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions