Skip to content

Passing context outside the LLM to tools #173

Answered by awsarron
liorheber asked this question in Q&A
Discussion options

You must be logged in to vote

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 my_value with kwargs.get("my_value"). For example my_package/my_custom_tool.py:

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": {},
}

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@isacandrei
Comment options

@dbschmigelski
Comment options

@isacandrei
Comment options

@dbschmigelski
Comment options

Answer selected by dbschmigelski
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants