AWS Builder Center
Building AI Agents with AWS: From LLMs to Tool Calling

Building AI Agents with AWS: From LLMs to Tool Calling

Explore how AI agents go beyond traditional LLM interactions by using tools, APIs, and external services. Learn how Amazon Bedrock, AWS Lambda, and API Gateway can help build practical, secure, and scalable AI-powered applications.

Building AI Agents with AWS: From LLMs to Tool Calling

Introduction

Large Language Models (LLMs) have changed how we interact with software. They can understand natural language, generate code, summarize information, and answer complex questions.
However, there is one important limitation: generating an answer is different from completing a task.
Imagine asking an AI assistant:
"Check my latest order, find its delivery status, and let me know if there is a delay."
A basic chatbot might explain how to track an order. But an AI agent could interact with an order-management API, retrieve the actual delivery information, analyze the result, and respond with relevant details.
This is where tool calling becomes important.
In this article, let's explore how AI agents work, how tool calling connects LLMs with external systems, and how we can use AWS services to build these applications.

1. What Is an AI Agent?

An AI agent is a system that uses a model to interpret a user's objective and determine which actions or information are needed to achieve it.
Unlike a basic chatbot that primarily generates responses, an agent can work with external tools and services.
A typical AI agent consists of:
  • LLM: Understands user requests and determines the next action.
  • Instructions: Define the agent's role, objectives, and boundaries.
  • Tools: Provide access to APIs, databases, and external services.
  • Memory or context: Helps maintain relevant information across interactions.
  • Orchestration: Coordinates model responses, tool execution, and subsequent decisions.
For example, an e-commerce agent might retrieve order information, check inventory, and provide delivery updates.
The model handles language understanding and action selection, while application code and external services perform the actual operations.

2. Understanding Tool Calling

Tool calling, also known as function calling, allows an LLM to request the execution of a specific function.
Suppose we provide the model with a tool called  get_order_status .
We also describe the tool's purpose and define the parameters it accepts.
For example:
{
"name": "get_order_status",
"description": "Retrieve the delivery status of an order",
"input_schema": {
"type": "object",
"properties": {
"order_id": {
"type": "string",
"description": "The customer's order ID"
}
},
"required": ["order_id"]
}
}
Now imagine the user asks:
"Where is my order ORD1024?"
The model can identify that it needs the  get_order_status  tool and generate a structured request containing the order ID.
An important distinction:
The LLM does not automatically execute the function.
It produces a structured tool-use request. The application or an authorized server-side execution environment validates and executes the requested operation.
The result is then returned to the model so it can formulate a meaningful response.

3. How Does the Tool Calling Workflow Work?

A typical tool-calling workflow follows these steps:
  1. The user submits a request through the application.
  1. The backend sends the conversation and available tool definitions to the LLM.
  1. The model determines whether a tool is required.
  1. If a tool is required, the model returns its name and structured arguments.
  1. The backend validates the request and executes the corresponding function.
  1. The tool returns its result to the backend.
  1. The backend sends the tool result back to the model.
  1. The model generates the final response.
This process can repeat when the agent needs additional information or another tool.
For example, checking an order might require retrieving the order record first and then checking a separate shipment service.

4. Building AI Agents with AWS

AWS provides several services that can help developers build AI-powered applications without managing every infrastructure component themselves.
Here are some important building blocks.

A. Amazon Bedrock

Amazon Bedrock provides access to foundation models through managed APIs.
Developers can use supported models for natural-language understanding, response generation, and tool calling.
One useful option is the Converse API, which provides a consistent interface for conversational interactions across supported models.
With tool use, developers can:
  • Define available functions.
  • Provide structured input schemas.
  • Receive tool-use requests from the model.
  • Execute functions through application code.
  • Return tool results for further model processing.
This makes it possible to build custom agent workflows without necessarily adopting a large agent framework.

B. AWS Lambda

AWS Lambda provides a serverless environment for executing application logic.
It can be used to implement tools that interact with databases, internal APIs, and third-party services.
For example, a Lambda function could:
  • Retrieve an order from DynamoDB.
  • Check payment information.
  • Query an external shipping API.
  • Return structured results.
The model decides which available tool may be useful, but Lambda performs the actual business operation.

C. Amazon API Gateway

Amazon API Gateway can provide an HTTP entry point for an AI-powered application.
A typical request flow might look like:
  • The frontend sends a user message to API Gateway.
  • API Gateway forwards the request to an AWS Lambda function.
  • Lambda communicates with Amazon Bedrock.
  • If the model requests a tool, Lambda executes the appropriate operation.
  • The final response is returned to the frontend.
This architecture separates the user interface, orchestration logic, and business operations.

D. Amazon Bedrock Knowledge Bases

Not every user request requires an external action.
Sometimes an agent needs information from internal documents, product manuals, FAQs, or company policies.
Amazon Bedrock Knowledge Bases can help retrieve relevant information from connected data sources and provide context to the model.
For example, a customer support agent could retrieve a company's return policy before answering a refund-related question.
This approach is commonly associated with Retrieval-Augmented Generation (RAG).

E. AWS IAM and CloudWatch

Building an agent is not just about connecting services.
Security and monitoring are equally important.
AWS Identity and Access Management (IAM) helps control which AWS resources and operations an application can access.
Amazon CloudWatch helps developers monitor logs, metrics, and application behavior.
Together, these services contribute to a more manageable and observable architecture.

5. A Practical Architecture: Order Tracking Agent

Let's put these concepts together with a simple example.
Imagine building an AI-powered order tracking assistant.
A customer enters:
"Can you check the status of my order ORD1024?"
The architecture could look like this:
CUSTOMER
|
v
React Frontend
|
v
Amazon API Gateway
|
v
AWS Lambda
(Agent Orchestrator)
|
v
Amazon Bedrock
(Foundation Model)
|
Tool-use request
|
v
Validate Tool Request
|
v
get_order_status()
|
v
AWS Lambda / Backend
|
v
Amazon DynamoDB
|
v
Structured Tool Result
|
v
Amazon Bedrock
|
v
Final AI Response
|
v
CUSTOMER
Here is how the interaction works:
Step 1: User request
The customer enters an order-tracking question in the React frontend.
Step 2: Model interaction
The backend sends the request and the available tool definition to Amazon Bedrock.
Step 3: Tool selection
The model determines that retrieving the order status is necessary and returns a structured tool-use request.
Step 4: Backend execution
The Lambda orchestrator validates the requested arguments and calls the order lookup function.
Step 5: Database interaction
The backend retrieves the relevant order information from DynamoDB.
Step 6: Final response
The tool result is sent back to the model, which generates a natural-language response for the customer.
For example:
"Your order ORD1024 has been shipped and is currently in transit. Please check the tracking details for the latest delivery update."
The important point is that the delivery status comes from the database, not from the model's imagination.

6. Tool Calling vs Traditional API Integration

You might wonder: why not simply call an API directly from the application?
Traditional API integration is useful when the application already knows exactly which operation needs to be performed.
For example, clicking a Track Order button can directly trigger an order-status API.
Tool calling becomes useful when a user expresses an objective in natural language and the application needs to determine which available operation is relevant.
Consider the difference:
Traditional API Integration
AI Tool Calling
Operation is predefined by application logic
Model selects from available tools
Usually follows a fixed workflow
Can support flexible workflows
Inputs are often provided through forms
Inputs can be extracted from natural language
Application controls the sequence
Model can help determine the next step
Predictable execution path
Requires validation of model-selected actions
These approaches are not competitors.
In fact, combining deterministic application logic with model-based reasoning is often a better architecture.

7. Important Challenges When Building AI Agents

AI agents introduce additional engineering challenges that developers should consider.
1. Incorrect tool selection
A model may select an inappropriate tool or misunderstand the user's request.
Solution: Provide clear tool descriptions, validate arguments, and restrict the available tools.
2. Security and permissions
An agent should never have unrestricted access to databases or sensitive operations.
Solution: Use least-privilege IAM permissions, backend authorization, and input validation.
3. Hallucinations
An LLM may generate information that is not supported by the actual tool result.
Solution: Ground responses in retrieved data and ensure important outputs are verified by application logic.
4. Latency and cost
Multiple model calls and tool executions can increase response time and operational cost.
Solution: Avoid unnecessary orchestration steps, limit repeated calls, and monitor token consumption.
5. Uncontrolled actions
Operations such as refunds, payments, cancellations, and account deletion should not be executed simply because a model requested them.
Solution: Introduce explicit authorization, confirmation steps, and deterministic business rules.

8. From AI Prototypes to Production Applications

A working AI agent demo is only the beginning.
Production applications need more than a capable model.
Some important engineering practices include:
  • Keep business-critical validation outside the LLM.
  • Use structured tool schemas.
  • Apply authentication and authorization before executing operations.
  • Add timeouts, retries, and error handling.
  • Monitor tool execution and model usage.
  • Maintain clear boundaries between reasoning and execution.
  • Require human confirmation for sensitive operations.
  • Test unexpected inputs and failure scenarios.
AWS also provides Amazon Bedrock Agents for managed agent orchestration, including action groups, Lambda integrations, and knowledge bases.
For more customized workflows, developers can use the Converse API and implement their own orchestration logic.
The right choice depends on the application's complexity, control requirements, and operational needs.

Conclusion

AI agents represent an interesting evolution in application development.
LLMs provide the ability to understand requests and determine possible actions, while tool calling connects that intelligence to real application functionality.
With services such as Amazon Bedrock, AWS Lambda, API Gateway, DynamoDB, and CloudWatch, developers can build applications that combine natural-language interaction with existing backend systems.
However, one lesson is particularly important:
An AI agent should decide what action may be useful, but the application should control whether that action is allowed and how it is executed.
That separation between reasoning and execution is essential when building reliable AI-powered applications.
As developers, we should focus not only on making agents smarter but also on making them secure, predictable, observable, and useful in real-world scenarios.

Further Reading

Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article