Scale customer reach and grow sales with AskHandle chatbot

How Can You Use Function Calling with AWS Bedrock?

If you are exploring ways to incorporate machine learning models into your applications, AWS Bedrock offers a flexible platform to do so. One of its powerful features is function calling, which allows seamless integration of custom functions with pre-built AI models. This article explains how to call functions with AWS Bedrock in an easy-to-follow way, providing clear steps and examples.

image-1
Written by
Published onAugust 1, 2025
RSS Feed for BlogRSS Blog

How Can You Use Function Calling with AWS Bedrock?

If you are exploring ways to incorporate machine learning models into your applications, AWS Bedrock offers a flexible platform to do so. One of its powerful features is function calling, which allows seamless integration of custom functions with pre-built AI models. This article explains how to call functions with AWS Bedrock in an easy-to-follow way, providing clear steps and examples.

What is AWS Bedrock?

AWS Bedrock is a managed service that helps developers build and scale AI applications. It provides access to various foundation models (FMs) from multiple providers. These models are capable of performing a range of tasks, including text generation, image creation, and more. Bedrock makes it easier to connect these models to your applications without managing complex infrastructure.

What is Function Calling?

Function calling is a feature that lets you extend the capabilities of foundation models. When a model responds to a prompt, it can also invoke specific functions you define. For example, if a user asks for the weather forecast, the model can trigger a weather API call to provide real-time data. This process improves the usefulness of AI responses and allows integration with other services in your architecture.

Setting Up Your Environment

Before you start, make sure you have an AWS account with appropriate permissions. You also need to install the AWS CLI and SDKs in your development environment. Once set up:

  1. Create an IAM role with permissions for Bedrock.
  2. Establish a connection to your AWS account.
  3. Choose a foundation model from the available options in Bedrock.

Defining Your Function

The first step in function calling is to define your custom function. A function can be a simple script that interacts with other APIs or performs calculations. This example creates a function that retrieves current weather data.

Here's a sample Python function:

Python

You need to expose this function so that it can be called by the model. The process involves registering the function's schema and making it accessible to Bedrock.

Integrating Function Calling into Bedrock

AWS Bedrock uses a feature called "function schema" to understand what functions are available. You define a JSON schema describing your function's parameters and output.

An example schema for the weather function:

Json

Register this schema with AWS Bedrock, linking it to your code. Once registered, the model can invoke this function during interactions.

Performing Function Calls with the Model

To make the model call your function, you will send a prompt along with instructions that specify when to trigger the function. When using the AWS SDK in Python, this involves calling a specific API method with necessary parameters.

Example of calling the model:

Python

The response from the model may include a function call request, which your code needs to interpret. Once the function call is identified, your application executes the function and feeds the output back to the model, completing the conversation.

Handling the Function Output

After calling your custom function, you should return its result to the model to generate a final reply. This process often involves:

  1. Detecting that a function has been invoked.
  2. Running the corresponding code to get the necessary data.
  3. Sending the result back into the model as context for generating a reply.

For example, if the weather data is retrieved successfully, you pass this information back:

Python

Your application can then display this information to the user or use it further.

Knowing how to use function calling with AWS Bedrock allows you to extend AI models with your custom logic efficiently. First, define your functions and register their schemas with Bedrock. Then, instruct the model when to invoke these functions during interactions. Finally, handle the responses by executing your functions and feeding results back into the conversation.

This approach simplifies building intelligent applications that can interact with external services, perform calculations, or retrieve live data. With practice, you can create more complex workflows that combine multiple functions and models to serve a wide range of needs.

Create your AI Agent

Automate customer interactions in just minutes with your own AI Agent.

Featured posts

Subscribe to our newsletter

Achieve more with AI

Enhance your customer experience with an AI Agent today. Easy to set up, it seamlessly integrates into your everyday processes, delivering immediate results.

Latest posts

AskHandle Blog

Ideas, tips, guides, interviews, industry best practices, and news.

View all posts