Skip to content
Closed
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
3 changes: 3 additions & 0 deletions src/askui/models/shared/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ def _use_tools(
for content_block in message.content
if content_block.type == "tool_use"
]
if len(tool_use_content_blocks) == 0:
return None
Comment on lines +168 to +169
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about removing this? ThreadPoolExecutor.map() and, therefore, ToolCollection.run() can handle empty list.


content = tool_collection.run(tool_use_content_blocks)
if len(content) == 0:
return None
Expand Down
9 changes: 5 additions & 4 deletions src/askui/models/shared/tools.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import ABC, abstractmethod
from concurrent.futures import ThreadPoolExecutor
from typing import Any

from anthropic.types.beta import BetaToolParam, BetaToolUnionParam
Expand Down Expand Up @@ -132,10 +133,10 @@ def reset_tools(self, tools: list[Tool] | None = None) -> "Self":
def run(
self, tool_use_block_params: list[ToolUseBlockParam]
) -> list[ContentBlockParam]:
return [
self._run_tool(tool_use_block_param)
for tool_use_block_param in tool_use_block_params
]
if len(tool_use_block_params) == 1:
return [self._run_tool(tool_use_block_params[0])]
with ThreadPoolExecutor() as executor:
return list(executor.map(self._run_tool, tool_use_block_params))

def _run_tool(
self, tool_use_block_param: ToolUseBlockParam
Expand Down