feat: Add specialized handler for tool calling improvements by Cristhianzl · Pull Request #10857 · langflow-ai/langflow (original) (raw)

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This change introduces IBM WatsonX/Granite-specific tool calling support with model detection, enhanced system prompts for multi-tool scenarios, placeholder detection in tool arguments, and a dynamic agent creator that alternates tool-choice binding based on iteration depth. The feature integrates into the existing tool-calling pipeline and is covered by comprehensive unit tests.

Changes

Cohort / File(s) Summary
IBM Granite Handler – New Module src/lfx/src/lfx/components/langchain_utilities/ibm_granite_handler.py New module providing WatsonX/Granite model detection (is_watsonx_model, is_granite_model), enhanced system prompt construction (get_enhanced_system_prompt), placeholder detection in tool arguments (detect_placeholder_in_args), and dynamic agent creation with tool-choice switching (create_granite_agent / create_watsonx_agent alias).
Tool Calling Integration src/lfx/src/lfx/components/langchain_utilities/tool_calling.py Integrated Granite handler imports and conditional logic: detects Granite models and enhances system prompts before building messages; routes to Granite-specific agent creator when applicable, else falls back to default tool-calling agent.
Agent Base Refactoring src/lfx/src/lfx/base/agents/agent.py Removed explicit empty input_dict initialization and replaced with a comment; existing population logic unchanged.
Granite Handler Unit Tests src/backend/tests/unit/components/models_and_agents/test_ibm_granite_handler.py Comprehensive test module validating model detection strategies, prompt augmentation logic, placeholder pattern matching, Granite agent creation, dynamic iteration behavior, tool-choice binding, and edge cases across multiple test classes and parameterized scenarios.

Sequence Diagram(s)

sequenceDiagram participant Client participant ToolCalling participant GraniteHandler participant LLM participant Agent participant Tools

Client->>ToolCalling: create_agent_runnable(llm, tools, prompt)

rect rgb(200, 220, 240)
Note over ToolCalling,GraniteHandler: Granite Model Detection & Prompt Enhancement
ToolCalling->>GraniteHandler: is_granite_model(llm)
GraniteHandler-->>ToolCalling: bool result

alt Granite Model Detected
    ToolCalling->>GraniteHandler: get_enhanced_system_prompt(base_prompt, tools)
    GraniteHandler-->>ToolCalling: enhanced_prompt with tool instructions
end
end

rect rgb(240, 220, 200)
Note over ToolCalling,Agent: Agent Creation
alt Granite Model with Tools
    ToolCalling->>GraniteHandler: create_granite_agent(llm, tools, prompt)
    
    loop For Each Iteration
        rect rgb(220, 240, 220)
        Note over GraniteHandler,LLM: Dynamic Tool Choice Binding
        GraniteHandler->>LLM: Select tool_choice (required/auto based on iteration)
        LLM->>LLM: Bind tools with selected tool_choice
        end
        
        GraniteHandler->>LLM: Invoke with input & agent_scratchpad
        LLM-->>GraniteHandler: tool_call or response
        
        GraniteHandler->>GraniteHandler: detect_placeholder_in_args(tool_calls)
        
        alt Placeholder Detected
            GraniteHandler->>GraniteHandler: Inject corrective SystemMessage
        end
        
        GraniteHandler->>Tools: Execute tool_calls
        Tools-->>GraniteHandler: tool results
    end
    
    GraniteHandler-->>ToolCalling: RunnableLambda agent
else Default Model
    ToolCalling->>Agent: create_tool_calling_agent(llm, tools, prompt)
    Agent-->>ToolCalling: default agent
end
end

ToolCalling-->>Client: agent_runnable

Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30–45 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Excessive Mock Usage Warning ❓ Inconclusive Test file cannot be accessed to assess mock usage patterns and determine if mocking is excessive or appropriately targeted at external dependencies versus core business logic. Examine actual test file to quantify mocks, verify core business logic uses real objects, and ensure mocks target external dependencies rather than internal control flow.

✅ Passed checks (6 passed)

Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: Add specialized handler for tool calling improvements' accurately reflects the main change: introduction of a new IBM Granite handler module with specialized tool-calling logic.
Docstring Coverage ✅ Passed Docstring coverage is 96.55% which is sufficient. The required threshold is 80.00%.
Test Coverage For New Implementations ✅ Passed Comprehensive test coverage verified with new test file (test_ibm_granite_handler.py) containing 9 test classes covering all 6 new functions, including unit tests, integration tests, parameterized tests, and edge-case coverage.
Test Quality And Coverage ✅ Passed Test suite demonstrates comprehensive coverage with 200+ lines testing all 5 public functions across 9 well-structured test classes, featuring parametrized testing (16+ scenarios), explicit error handling validation, extensive edge case coverage, 80+ assertions, and integration tests with ToolCallingAgentComponent.
Test File Naming And Structure ✅ Passed The test file test_ibm_granite_handler.py fully adheres to all specified naming, structure, and content requirements with 50+ descriptive test methods covering positive/negative scenarios and edge cases.

✨ Finishing touches 🧪 Generate unit tests (beta)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.