Replies: 1 comment
-
When invoking agents, any kwarg can be passed. These kwargs are then passed to tools when they are invoked. For example: from strands import Agent
from my_package import my_custom_tool
agent = Agent(tools=[my_custom_tool])
my_value = {"key1": "value1", "key2": 1234} # can be any variable, object, anything
agent("Do the thing", my_value=my_value) Now when tools are invoked they can access from typing import Any
from strands.types.tools import ToolResult, ToolUse
TOOL_SPEC = {
"name": "my_custom_tool",
"description": "Demonstration tool that must be called for all requests.",
"inputSchema": {},
}
def my_custom_tool(tool: ToolUse, **kwargs: Any) -> ToolResult:
# tool has access to my_value in kwargs
my_value = kwargs.get("my_value")
print(f"my_value: {my_value}")
return {
"toolUseId": tool["toolUseId"],
"status": "success",
"content": [{"text": f"my_value: {my_value}"}],
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
Consider I have agents running on some service that contains the users jwt.
When my agents use tools or MCP servers, I want the agent to act on behalf of the user, meaning that the tools will get the jwt as part of their arguments.
What I don't wan't to do is pass the jwt to the LLM and have it pass it as an argument to the tools.
Is there any way this could be done?
This is very similar to the Context in OpenAI agents where you can add external context to tools without going through the LLM.
An alternative is to create some initialization to the tools before passing them to the agent, but that will require implementation for all tools.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions