AWS Logo
Menu
Building AI Agents with Strands: Part 2 - Tool Integration

Building AI Agents with Strands: Part 2 - Tool Integration

Learn how to connect your AI agent to the real world using built-in and custom tools.

Dennis Traub
Amazon Employee
Published May 21, 2025
Last Modified May 28, 2025
Welcome to the second part of our series on building AI agents with Strands! In Part 1, we created a basic subject expert agent for our Integrated Learning Lab. Now, we'll take it to the next level by integrating tools to extend our agent's capabilities.
Tools are what transform a basic conversational agent into a truly useful assistant that can interact with the world. In this tutorial, we'll explore both built-in tools provided by the Strands SDK, and learn how to create our own custom tools.

What You'll Learn

  • How to integrate built-in tools from the strands-agents-tools package
  • How to create custom tools using the @tool decorator
  • How to implement file operations for learning resources
  • How to build a custom glossary tool for our agent

Prerequisites

Understanding Tools in Strands

Tools are functions that agents can use to perform actions beyond simply generating text. They allow agents to:
  • Access and manipulate external data (files, databases)
  • Perform calculations and specialized processing
  • Create, modify, and manage content
  • Connect to any external service via APIs
The Strands SDK makes tool integration straightforward while maintaining a security-focused approach.

Using Built-in Tools

Let's start by enhancing our subject expert with some built-in tools from the strands-agents-tools package:
When you run this code, you'll get a response similar to this:
This demonstrates a key strength of Strands: tools are selected and invoked automatically based on the context of the conversation. Without any explicit commands, the agent:
  1. Recognized the first question needed the current time and used the current_time tool
  2. Understood the second question required external information and used the http_request tool
  3. Integrated the tool results seamlessly into a comprehensive response

Creating a Custom Tool

While built-in tools are useful, the real power comes from creating custom tools tailored to your specific needs. For our Integrated Learning Lab, let's build a tool that manages a glossary of computer science terms:
A few important notes about this implementation:
  1. We use the @tool decorator to transform a regular Python function into a tool
  2. The function's docstring and type hints are used to generate a tool specification
  3. We include input validation as a precaution
  4. The tool maintains state between invocations by reading from and writing to a file
This approach follows secure tool design principles, which are essential when building AI systems that interact with external resources.

Creating a Subject Expert with Advanced Tools

Now, let's put it all together by creating a subject expert agent that uses both built-in and custom tools:

Interactive Testing Session

Let's create an interactive session to test our enhanced agent:
Save this to a file (e.g., subject_expert_with_tools.py) and run it. You'll have an interactive session with your tool-enhanced agent that looks similar to this:

Direct Tool Invocation

While the agent will automatically invoke tools based on user queries, sometimes you may want to call tools directly from your code:
This gives you programmatic control when needed, while still benefiting from the agent's context.

Security Considerations for Tool Design

When creating tools, always follow these security principles:
  1. Validate inputs: Check that inputs match expected types and formats
  2. Limit permissions: Tools should have minimal necessary access
  3. Sanitize outputs: Ensure tool outputs don't contain harmful content
  4. Error handling: Gracefully handle edge cases and errors
  5. Audit logging: Log sensitive operations for review
Our cs_glossary tool implements these principles by validating input types, using a specific file for storage, and providing clear error messages.

What We've Learned

In this tutorial, we've:
  • ✅ Added built-in tools to our subject expert agent
  • ✅ Created a custom glossary tool with the @tool decorator
  • ✅ Combined multiple tools for enhanced capabilities
  • ✅ Created an interactive testing environment
Our agent can now maintain a growing knowledge base of computer science terminology, perform calculations, and manage files - significantly expanding its capabilities beyond simple conversation.

Next Steps & Resources

In the the next lesson, we'll explore the Model Context Protocol (MCP) to connect our agent with external specialized capabilities. This will allow us to tap into tools developed by others without having to implement everything ourselves.
Ready? Let's continue with Part 3: MCP Integration

Want to learn more about the Strands Agents SDK?

Here are some resources to help you deepen your understanding:
What kind of tools would you like to build? Share your ideas in the comments below!

💡 Troubleshooting tip: If tools aren't working as expected, check that they have proper docstrings and type hints. The Strands SDK uses these to generate the tool specifications that the agent uses to understand when and how to invoke tools.
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

1 Comment