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
4 changes: 2 additions & 2 deletions src/aviary/tools/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ def from_tool(cls, tool: "Tool", *args, id: str | None = None, **kwargs) -> Self
)

@classmethod
def from_name(cls, function_name: str, **kwargs) -> Self:
def from_name(cls, function_name: str, id: str | None = None, **kwargs) -> Self: # noqa: A002
return cls(
id=cls.generate_id(),
id=id or cls.generate_id(),
function=ToolCallFunction(name=function_name, arguments=kwargs),
)

Expand Down
11 changes: 10 additions & 1 deletion tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ async def test_arg_types(self) -> None:
tool._tool_fn(**call.function.arguments)

@pytest.mark.asyncio
async def test_tool_serialization(
async def test_tool_serialization( # noqa: PLR0915
self, dummy_env: DummyEnv, subtests: SubTests
) -> None:
def get_todo_list(n: int):
Expand Down Expand Up @@ -662,6 +662,15 @@ def get_todo_list(n: int):
new_messages = await dummy_env.exec_tool_calls(action)
assert new_messages[0].content == "Go for a walk\nRead a book"

with subtests.test("tool call from name with custom id"):
custom_id = "custom123"
tool_call = ToolCall.from_name("get_todo_list", id=custom_id, n=2)
assert tool_call.id == custom_id
action = ToolRequestMessage(tool_calls=[tool_call])
new_messages = await dummy_env.exec_tool_calls(action)
assert new_messages[0].content == "Go for a walk\nRead a book"
assert new_messages[0].tool_call_id == custom_id

with subtests.test("tool call from tool"):
tool_call = ToolCall.from_tool(tool, n=2)
action = ToolRequestMessage(tool_calls=[tool_call])
Expand Down
Loading