Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mellea/backends/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def from_langchain(cls, tool: Any) -> "MelleaTool":

def parameter_remapper(*args, **kwargs):
"""Langchain tools expect their first argument to be 'tool_input'."""
if args is not None or len(args) != 0:
if args:
# This shouldn't happen. Our ModelToolCall.call_func actually passes in everything as kwargs.
FancyLogger.get_logger().warning(
f"ignoring unexpected args while calling langchain tool ({tool_name}): ({args})"
Expand Down
24 changes: 24 additions & 0 deletions test/backends/test_mellea_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@ def test_from_langchain():
assert t.run(input=2) == "2"


def test_from_langchain_args_handling(caplog):
"""Test that langchain tools handle args correctly.

Verifies that:
1. Tools work correctly when called with kwargs only (normal case)
2. A warning is logged if positional args are passed (shouldn't happen)
"""
t = MelleaTool.from_langchain(langchain_tool)

# Normal case: kwargs only (no warning expected)
caplog.clear()
result = t.run(input=5)
assert result == "5"
assert "ignoring unexpected args" not in caplog.text

# Edge case: positional args passed (warning expected)
# This shouldn't happen in practice since ModelToolCall.call_func uses **kwargs
caplog.clear()
result = t.run(42, input=5) # Pass both positional and keyword args
assert result == "5" # Should still work, using kwargs
assert "ignoring unexpected args" in caplog.text
assert "langchain_tool" in caplog.text


@pytest.mark.qualitative
@pytest.mark.ollama
@pytest.mark.llm
Expand Down
Loading