-
Notifications
You must be signed in to change notification settings - Fork 330
tool executors #658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
tool executors #658
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
97a062e
tool executors
pgrayy 8a86a29
tool executors - override type decorator
pgrayy 45198c3
executor - skip tracing member variable
pgrayy c95154f
executors - pass tool results separately
pgrayy 01327c2
Merge branch 'main' of https://github.com/strands-agents/sdk-python i…
pgrayy 7cc16e6
address feedback
pgrayy 4398086
make tools validator private
pgrayy b3249cc
python agent tool - custom thread pool
pgrayy 72e4238
python agent tool - pass thread pool
pgrayy 946035c
executor - init - thread_pool - literal asyncio
pgrayy 5740118
remove sa prefix
pgrayy 56b51de
remove thread pool customization
pgrayy 43af1ae
Merge branch 'main' of https://github.com/strands-agents/sdk-python i…
pgrayy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Tool validation utilities.""" | ||
|
||
from ..tools.tools import InvalidToolUseNameException, validate_tool_use | ||
from ..types.content import Message | ||
from ..types.tools import ToolResult, ToolUse | ||
|
||
|
||
def validate_and_prepare_tools( | ||
message: Message, | ||
tool_uses: list[ToolUse], | ||
tool_results: list[ToolResult], | ||
invalid_tool_use_ids: list[str], | ||
) -> None: | ||
"""Validate tool uses and prepare them for execution. | ||
|
||
Args: | ||
message: Current message. | ||
tool_uses: List to populate with tool uses. | ||
tool_results: List to populate with tool results for invalid tools. | ||
invalid_tool_use_ids: List to populate with invalid tool use IDs. | ||
""" | ||
# Extract tool uses from message | ||
for content in message["content"]: | ||
if isinstance(content, dict) and "toolUse" in content: | ||
tool_uses.append(content["toolUse"]) | ||
|
||
# Validate tool uses | ||
# Avoid modifying original `tool_uses` variable during iteration | ||
tool_uses_copy = tool_uses.copy() | ||
for tool in tool_uses_copy: | ||
try: | ||
validate_tool_use(tool) | ||
except InvalidToolUseNameException as e: | ||
# Replace the invalid toolUse name and return invalid name error as ToolResult to the LLM as context | ||
tool_uses.remove(tool) | ||
tool["name"] = "INVALID_TOOL_NAME" | ||
invalid_tool_use_ids.append(tool["toolUseId"]) | ||
tool_uses.append(tool) | ||
tool_results.append( | ||
{ | ||
"toolUseId": tool["toolUseId"], | ||
"status": "error", | ||
"content": [{"text": f"Error: {str(e)}"}], | ||
} | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.