AWS, Cloud Computing, Data Analytics

< 1 min

Tool-Calling LLM Agents with AWS Lambda and Amazon Bedrock

Voiced by Amazon Polly

Overview

AI systems are moving from simple chat-based tools to systems capable of performing tasks. This change is mainly due to tool-calling, where an AI model can use external tools such as APIs, databases, or services to fulfill a request.

In this blog post, we will explore the concept of tool-calling and demonstrate how to create agentic AI using two AWS services:

  • Amazon Bedrock for reasoning and decision-making
  • AWS Lambda for executing actions

Throughout this tutorial, we will discuss architecture, examples, and best practices to help you better understand how such systems are built.

Pioneers in Cloud Consulting & Migration Services

  • Reduced infrastructural costs
  • Accelerated application deployment
Get Started

Introduction

Previously, the AI models performed tasks such as question answering and text generation. The results depended on the training data, which could sometimes produce wrong or outdated responses.

However, with the tool-calling functionality, AI models can achieve much more now.

Rather than producing a response, they can:

  • fetch real-time data
  • interact with systems
  • execute tasks

For example, if a user asks for stock prices, the model does not guess. It calls a real API, gets the latest data, and then responds.

This makes AI systems more useful in real-world applications like data analysis, automation, and customer support.

AWS provides a strong setup for building such systems using Amazon Bedrock and AWS Lambda.

Tool-Calling

Tool-calling is the ability of an AI model to use external functions when needed.

A simple flow looks like this:

Step-by-Step:

  1. User sends a query
  2. The model understands the request
  3. The model decides which tool is needed
  4. The tool is executed using Lambda
  5. The result is returned to the model
  6. The model generates the final answer

This process can happen multiple times in complex tasks.

How Amazon Bedrock Fits In?

Amazon Bedrock is a fully managed AWS service that provides a wide range of capabilities for accessing advanced AI models without worrying about the underlying infrastructure, the required GPUs, or model deployment.

To put it simply, Bedrock is where the brain of your system lies.

This means you can instead leverage high-quality AI models from Anthropic, Meta, and AWS.

What Amazon Bedrock Actually Does?

When a user sends a request, Amazon Bedrock is responsible for:

  • Understanding the user query
  • Deciding what to do next
  • Selecting the right tool
  • Managing multi-step reasoning
  • Generating the final response

It also provides Agents, which automatically manage tool-calling workflows and reduce the need for custom logic.

How AWS Lambda Fits In?

AWS Lambda is a serverless compute service that runs your code only when it is needed. In this architecture, AWS Lambda acts as the execution layer.

Whenever Bedrock decides to call a tool, that tool is usually implemented as a Lambda function.

Lambda:

  • receives input from the model
  • executes logic (API call, DB query, etc.)
  • returns structured output

This makes the system scalable and cost-efficient since AWS Lambda runs only when needed.

Multi-Step Agent Workflow

Some tasks require multiple steps.

Example:
“Generate report and email it”

Flow:

  1. Fetch data
  2. Process data
  3. Generate report
  4. Store file
  5. Send email

This is handled by the agent using repeated tool calls.

End-to-End Tool Calling Example

This example shows how to connect:

  • Amazon Bedrock for reasoning
  • AWS Lambda for execution

We define two tools:

  • Weather tool
  • Web search tool

And implement a simple agent loop that handles tool-calling.

Step 1: Define Tool Schemas

Step 2: Create Tool Mapping

Step 3: AWS Lambda Invocation Helper

Step 4: Main Agent Loop

Real-World Use Cases

  • ML Automation

Agents can monitor models, retrain them, and automatically deploy updates.

  • Customer Support

Agents can fetch order details, process requests, and respond to users.

  • Business Automation

Agents can generate reports, update systems, and send notifications.

Best Practices

  • Keep tools small and focused
  • Write clear tool descriptions
  • Always return structured responses
  • Handle errors properly
  • Validate all inputs
  • Monitor logs and performance
  • Control costs by limiting unnecessary calls

Conclusion

Tool calling represents one of the largest advancements in the development of AI systems. The tool allows transitioning from passive systems to those that actively perform certain tasks.

This can be done using:

  • Amazon Bedrock for intelligence
  • AWS Lambda for execution

This represents one of the most common approaches in developing modern AI systems.

Drop a query if you have any questions regarding Tool calling, and we will get back to you quickly.

Empowering organizations to become ‘data driven’ enterprises with our Cloud experts.

  • Reduced infrastructure costs
  • Timely data-driven decisions
Get Started

About CloudThat

CloudThat is an award-winning company and the first in India to offer cloud training and consulting services worldwide. As an AWS Premier Tier Services Partner, AWS Advanced Training Partner, Microsoft Solutions Partner, and Google Cloud Platform Partner, CloudThat has empowered over 1.1 million professionals through 1000+ cloud certifications, winning global recognition for its training excellence, including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 14 awards in the last 9 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, Security, IoT, and advanced technologies like Gen AI & AI/ML. It has delivered over 750 consulting projects for 850+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.

FAQs

1. Do I need to use Amazon Bedrock Agents, or can I build this manually?

ANS: – You can build tool-calling manually using the Amazon Bedrock API, as shown in this blog. This gives you full control over how tools are selected and executed. However, Amazon Bedrock Agents simplify this process by automatically handling tool routing, session management, and multi-step reasoning. If you want faster development with less code, Agents are a good choice.

2. How does the model decide which tool to call?

ANS: – The model selects tools based on the tool name, description, and input schema you provide. These act like instructions. If the descriptions are clear and specific, the model can reliably choose the correct tool. Poorly written descriptions often lead to incorrect tool selection.

3. Why do we need a mapping layer between tools and AWS Lambda functions?

ANS: – The model only returns a structured tool request (e.g., tool name and inputs). It does not execute the tool itself. Your application must map that tool name to the correct AWS Lambda function and execute it. This mapping layer is essential for connecting model decisions with actual system actions.

WRITTEN BY Aniket Bembale

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!