-
Hi, Consider I have agents running on some service that contains the users jwt. 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. Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
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.
When invoking agents, any kwarg can be passed. These kwargs are then passed to tools when they are invoked. For example:
Now when tools are invoked they can access
my_value
withkwargs.get("my_value")
. For examplemy_package/my_custom_tool.py
: