
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.
- 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
- Completed Part 1: Creating Your First Agent
- The Strands Agents SDK installed (
pip install strands-agents strands-agents-tools
) - Basic Python knowledge
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.
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:
- Recognized the first question needed the current time and used the current_time tool
- Understood the second question required external information and used the http_request tool
- Integrated the tool results seamlessly into a comprehensive response
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:
- We use the
@tool
decorator to transform a regular Python function into a tool - The function's docstring and type hints are used to generate a tool specification
- We include input validation as a precaution
- 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.
Now, let's put it all together by creating a subject expert agent that uses both built-in and custom tools:
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: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.
When creating tools, always follow these security principles:
- Validate inputs: Check that inputs match expected types and formats
- Limit permissions: Tools should have minimal necessary access
- Sanitize outputs: Ensure tool outputs don't contain harmful content
- Error handling: Gracefully handle edge cases and errors
- 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.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.
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
Here are some resources to help you deepen your understanding:
- 📚 Strands Agents Documentation - Comprehensive guides and API references
- 💻 GitHub Repository - Source code and examples - and if you like it, consider giving it a ⭐
- 🧩 Example Gallery - Explore sample implementations for various use cases
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.