Skip to content
Open
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
13 changes: 12 additions & 1 deletion src/rai_core/rai/agents/langchain/core/tool_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,20 @@ def run_one(call: ToolCall):
self.logger.info(f"Running tool: {call['name']}, args: {call['args']}")
artifact = None

tool = self.tools_by_name.get(call["name"])
if tool is None:
error_message = f'Unknown tool: "{call["name"]}"'
self.logger.info(error_message)
return ToolMessage(
content=error_message,
name=call["name"],
tool_call_id=call["id"],
status="error",
)

try:
ts = time.perf_counter()
output = self.tools_by_name[call["name"]].invoke(call, config) # type: ignore
output = tool.invoke(call, config) # type: ignore
te = time.perf_counter() - ts
self.logger.info(
f"Tool {call['name']} completed in {te:.2f} seconds. Tool output: {str(output.content)[:100]}{'...' if len(str(output.content)) > 100 else ''}"
Expand Down
20 changes: 20 additions & 0 deletions tests/agents/langchain/test_tool_runner_unknown.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (C) 2026 Robotec.AI
from langchain_core.messages import AIMessage, ToolMessage

from rai.agents.langchain.core.tool_runner import ToolRunner


def test_tool_runner_unknown_tool_returns_error_message():
runner = ToolRunner(tools=[])
ai = AIMessage(
content="",
tool_calls=[{"name": "missing_tool", "args": {}, "id": "call_1", "type": "tool_call"}],
)
out = runner.invoke({"messages": [ai]})
msgs = out["messages"]
assert len(msgs) == 2
err = msgs[-1]
assert isinstance(err, ToolMessage)
assert err.status == "error"
assert "Unknown tool" in err.content
assert err.tool_call_id == "call_1"
Loading