diff --git a/llm/models.py b/llm/models.py index 892a4f2ba..9c32d8b70 100644 --- a/llm/models.py +++ b/llm/models.py @@ -938,7 +938,8 @@ def log_to_db(self, db): { "tool_id": tool_id, "response_id": response_id, - } + }, + ignore=True, ) for tool_call in self.tool_calls(): # TODO Should be _or_raise() db["tool_calls"].insert( diff --git a/tests/test_tools.py b/tests/test_tools.py index b849779cc..5aa0f68db 100644 --- a/tests/test_tools.py +++ b/tests/test_tools.py @@ -369,6 +369,24 @@ def test_default_tool_llm_time(): } +def test_duplicate_tool_name_does_not_crash(logs_db): + """Passing the same tool twice (same name) should not cause a sqlite UNIQUE constraint error.""" + runner = CliRunner() + result = runner.invoke( + cli.cli, + [ + "-m", + "echo", + "-T", + "llm_time", + "-T", + "llm_time", + json.dumps({"tool_calls": [{"name": "llm_time"}]}), + ], + ) + assert result.exit_code == 0 + + def test_incorrect_tool_usage(): model = llm.get_model("echo")