-
Notifications
You must be signed in to change notification settings - Fork 429
docs: replace deprecated strands_tools references in samples #296
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
base: main
Are you sure you want to change the base?
Changes from all commits
7fc7155
8adab09
e36566d
f8cc957
8fb605d
1870a16
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,8 +17,8 @@ | ||||||||||||||
| "| Agent structure | Single agent |\n", | |||||||||||||||
| "| Model provider | Amazon Bedrock |\n", | |||||||||||||||
| "| Model | Anthropic Claude Sonnet 4.5 |\n", | |||||||||||||||
| "| Native tools used | calculator |\n", | |||||||||||||||
| "| Custom tools created | weather, websearch |\n", | |||||||||||||||
| "| Native tools used | none |\n", | |||||||||||||||
| "| Custom tools created | calculator, weather, websearch |\n", | |||||||||||||||
| "| Strands features | Agent, @tool decorator, BedrockModel |" | |||||||||||||||
| ] | |||||||||||||||
| }, | |||||||||||||||
|
|
@@ -59,7 +59,7 @@ | ||||||||||||||
| "source": [ | |||||||||||||||
| "# Install Strands using pip\n", | |||||||||||||||
| "\n", | |||||||||||||||
| "!pip install strands-agents strands-agents-tools" | |||||||||||||||
| "!pip install strands-agents" | |||||||||||||||
| ] | |||||||||||||||
| }, | |||||||||||||||
| { | |||||||||||||||
|
|
@@ -113,7 +113,7 @@ | ||||||||||||||
| "source": [ | |||||||||||||||
| "### Add tools to the agent\n", | |||||||||||||||
| "\n", | |||||||||||||||
| "The [strands-agents-tools](https://github.com/strands-agents/tools) repository provides some built-in tools that you can import. You can also create custom tools using the `@tool` decorator. The function's typed arguments and docstring are not just documentation. Strands turns them into the tool's input schema, which is what the model reads to decide when and how to call the tool. We can create agents with built-in and custom tools. For instance, adding the built-in tool of a calculator and a custom tool for getting the weather, you get the following architecture:\n", | |||||||||||||||
| "You create custom tools using the `@tool` decorator. The [strands-agents-tools](https://github.com/strands-agents/tools) repository also provides pre-built tools that you can import. The function's typed arguments and docstring are not just documentation. Strands turns them into the tool's input schema, which is what the model reads to decide when and how to call the tool. We can create agents with built-in and custom tools. For instance, defining a small calculator tool and a custom tool for getting the weather, you get the following architecture:\n", | |||||||||||||||
| "<div style=\"text-align:center\">\n", | |||||||||||||||
| " <img src=\"images/agent_with_tools.png\" width=\"75%\" />\n", | |||||||||||||||
| "</div>\n", | |||||||||||||||
|
|
@@ -128,8 +128,29 @@ | ||||||||||||||
| "metadata": {}, | |||||||||||||||
| "outputs": [], | |||||||||||||||
| "source": [ | |||||||||||||||
| "import operator\n", | |||||||||||||||
| "\n", | |||||||||||||||
| "from strands import Agent, tool\n", | |||||||||||||||
| "from strands_tools import calculator # Import the calculator tool\n", | |||||||||||||||
| "\n", | |||||||||||||||
| "_OPS = {\n", | |||||||||||||||
| " \"+\": operator.add,\n", | |||||||||||||||
| " \"-\": operator.sub,\n", | |||||||||||||||
| " \"*\": operator.mul,\n", | |||||||||||||||
| " \"/\": operator.truediv,\n", | |||||||||||||||
| " \"**\": operator.pow,\n", | |||||||||||||||
| "}\n", | |||||||||||||||
| "\n", | |||||||||||||||
| "\n", | |||||||||||||||
| "@tool\n", | |||||||||||||||
| "def calculator(a: float, b: float, op: str) -> float:\n", | |||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Non-blocking, but this is the copy every newcomer reads first, so it's the one worth getting right. I generated both specs against 1.50.2. Same function, same docstring, only the annotation differs:
Both are recoverable errors — nothing crashes — so this is about whether the model is told the valid set up front instead of discovering it by failing a call. Three things make it more than taste here: the SDK solves this exact shape this way (
Suggested change
Needs (For what it's worth on the bigger question: I think the two-operand redesign is the right call and teaches better than the AST walker did — 30 lines about |
|||||||||||||||
| " \"\"\"Apply an arithmetic operator to two numbers.\n", | |||||||||||||||
| "\n", | |||||||||||||||
| " Args:\n", | |||||||||||||||
| " a: Left operand.\n", | |||||||||||||||
| " b: Right operand.\n", | |||||||||||||||
| " op: One of \"+\", \"-\", \"*\", \"/\", \"**\".\n", | |||||||||||||||
| " \"\"\"\n", | |||||||||||||||
| " return _OPS[op](a, b)\n", | |||||||||||||||
| "\n", | |||||||||||||||
| "# Create a custom tool\n", | |||||||||||||||
| "@tool\n", | |||||||||||||||
|
|
@@ -169,7 +190,7 @@ | ||||||||||||||
| "outputs": [], | |||||||||||||||
| "source": [ | |||||||||||||||
| "# Alternatively, you can invoke the tool directly like so:\n", | |||||||||||||||
| "agent.tool.calculator(expression=\"sin(x)\", mode=\"derive\", wrt=\"x\", order=2)" | |||||||||||||||
| "agent.tool.calculator(a=144, b=0.5, op=\"**\")" | |||||||||||||||
| ] | |||||||||||||||
| }, | |||||||||||||||
| { | |||||||||||||||
|
|
|||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,8 +21,8 @@ | |
| "| Agent structure | Single agent |\n", | ||
| "| Model provider | Amazon Bedrock |\n", | ||
| "| Model | Anthropic Claude Sonnet 4.5 |\n", | ||
| "| Native tools used | current_time, calculator |\n", | ||
| "| Custom tools created | create_appointment, list_appointments, update_appointment |\n", | ||
| "| Native tools used | none |\n", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Same as The heading fix landed well, by the way — "Define the tools our agent needs" reads correctly, and For context one level up: |
||
| "| Custom tools created | calculator, current_time, create_appointment, list_appointments, update_appointment |\n", | ||
| "| Strands features | @tool decorator, TOOL_SPEC, BedrockModel extended thinking |\n" | ||
| ] | ||
| }, | ||
|
|
@@ -541,7 +541,7 @@ | |
| "outputs": [], | ||
| "source": [ | ||
| "system_prompt = \"\"\"You are a helpful personal assistant that specializes in managing my appointments and calendar. \n", | ||
| "You have access to appointment management tools, a calculator, and can check the current time to help me organize my schedule effectively. \n", | ||
| "You have access to appointment management tools, a calculator, and a clock to help me organize my schedule effectively. \n", | ||
| "Always provide the appointment id so that I can update it if required\"\"\"" | ||
| ] | ||
| }, | ||
|
|
@@ -592,9 +592,9 @@ | |
| } | ||
| }, | ||
| "source": [ | ||
| "#### Import built-in tools\n", | ||
| "#### Define the tools our agent needs\n", | ||
| "\n", | ||
| "The next step to build our agent is to import our Strands Agents built-in tools. Strands Agents provides a set of commonly used built-in tools in the optional package `strands-agents-tools`, which you import as `strands_tools`. You have tools for RAG, memory, file operations, code interpretation and others available in this repo. For our example we will use the `current_time` tool to provide our agent with the information about the current time and the `calculator` tool to do some math" | ||
| "The next step is to define the remaining tools our agent needs. Strands Agents also offers an optional package of pre-built tools, `strands-agents-tools`, with tools for RAG, memory, file operations, code interpretation and more. For this example we keep everything self-contained and define two small tools of our own: a `calculator` to do some math and a `current_time` tool so the agent can resolve relative dates like \"tomorrow\"." | ||
| ] | ||
| }, | ||
| { | ||
|
|
@@ -608,7 +608,36 @@ | |
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from strands_tools import calculator, current_time" | ||
| "import operator\n", | ||
| "from datetime import datetime, timezone\n", | ||
| "\n", | ||
| "from strands import tool\n", | ||
| "\n", | ||
| "_OPS = {\n", | ||
| " \"+\": operator.add,\n", | ||
| " \"-\": operator.sub,\n", | ||
| " \"*\": operator.mul,\n", | ||
| " \"/\": operator.truediv,\n", | ||
| " \"**\": operator.pow,\n", | ||
| "}\n", | ||
| "\n", | ||
| "\n", | ||
| "@tool\n", | ||
| "def calculator(a: float, b: float, op: str) -> float:\n", | ||
| " \"\"\"Apply an arithmetic operator to two numbers.\n", | ||
| "\n", | ||
| " Args:\n", | ||
| " a: Left operand.\n", | ||
| " b: Right operand.\n", | ||
| " op: One of \"+\", \"-\", \"*\", \"/\", \"**\".\n", | ||
| " \"\"\"\n", | ||
| " return _OPS[op](a, b)\n", | ||
| "\n", | ||
| "\n", | ||
| "@tool\n", | ||
| "def current_time() -> str:\n", | ||
| " \"\"\"Get the current UTC date and time in ISO 8601 format.\"\"\"\n", | ||
| " return datetime.now(timezone.utc).isoformat()" | ||
| ] | ||
| }, | ||
| { | ||
|
|
@@ -640,8 +669,8 @@ | |
| " model=model,\n", | ||
| " system_prompt=system_prompt,\n", | ||
| " tools=[\n", | ||
| " current_time,\n", | ||
| " calculator,\n", | ||
| " current_time,\n", | ||
| " create_appointment,\n", | ||
| " list_appointments,\n", | ||
| " update_appointment,\n", | ||
|
|
@@ -949,18 +978,18 @@ | |
| }, | ||
| "outputs": [], | ||
| "source": [ | ||
| "current_time_result = agent.tool.current_time()\n", | ||
| "print(\"Current Time direct tool call result:\")\n", | ||
| "print(current_time_result)\n", | ||
| "current_time_direct_tool_messages = agent.messages[-4:]\n", | ||
| "print(\"Current Time direct tool call messages:\")\n", | ||
| "print(current_time_direct_tool_messages)\n", | ||
| "calculator_result = agent.tool.calculator(a=2, b=2, op=\"+\")\n", | ||
| "print(\"Calculator direct tool call result:\")\n", | ||
| "print(calculator_result)\n", | ||
| "calculator_direct_tool_messages = agent.messages[-4:]\n", | ||
| "print(\"Calculator direct tool call messages:\")\n", | ||
| "print(calculator_direct_tool_messages)\n", | ||
| "\n", | ||
| "agent.record_direct_tool_call = False # Set the record_direct_tool_call to False\n", | ||
| "agent.tool.list_appointments()\n", | ||
| "after_disable_record_messages = agent.messages[-4:]\n", | ||
| "print(\"After disabling record direct tool call messages, history should not have changed:\")\n", | ||
| "print(current_time_direct_tool_messages == after_disable_record_messages)" | ||
| "print(calculator_direct_tool_messages == after_disable_record_messages)" | ||
| ] | ||
| }, | ||
| { | ||
|
|
@@ -1061,16 +1090,16 @@ | |
| "outputs": [], | ||
| "source": [ | ||
| "thinking_system_prompt = \"\"\"You are a helpful personal assistant that specializes in managing my appointments and calendar. \n", | ||
| "You have access to appointment management tools, a calculator, and can check the current time to help me organize my schedule effectively. \n", | ||
| "You have access to appointment management tools, a calculator, and a clock to help me organize my schedule effectively. \n", | ||
| "You think through your problem, step by step, to come up with an answer.\n", | ||
| "Always provide the appointment id so that I can update it if required\"\"\"\n", | ||
| "\n", | ||
| "thinking_agent = Agent(\n", | ||
| " model=thinking_model,\n", | ||
| " system_prompt=thinking_system_prompt,\n", | ||
| " tools=[\n", | ||
| " current_time,\n", | ||
| " calculator,\n", | ||
| " current_time,\n", | ||
| " create_appointment,\n", | ||
| " list_appointments,\n", | ||
| " update_appointment,\n", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1 @@ | ||
| strands-agents | ||
| strands-agents-tools | ||
| strands-agents |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,6 @@ | ||
| fastapi | ||
| uv | ||
| strands-agents | ||
| strands-agents-tools | ||
| uvicorn | ||
| pydantic | ||
| httpx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 This row is now correct — and it makes the surrounding prose self-contradictory, since there genuinely is no built-in tool left in the notebook. Three spots in this file and two in its README still promise one:
:32— "* Add built-in and custom tools":442— "you built your first Strands agent, added built-in and custom tools…":11— "…from a simple agent to one that uses built-in and custom tools"README.md:49— "- Adding built-in and custom tools"README.md:3— same framing in the opening paragraphDropping "built-in and" in each covers it.
README.md:13and:44are already fixed, so this is the last of that thread.