AI Finance Agent with Amazon Bedrock
Build an AI finance agent with Amazon Bedrock and Code Interpreter
Introduction
⚡️ 30 Second Summary
Managing your finances usually means staring at spreadsheets and manually categorizing every transaction, but an AI agent can do all of that for you in seconds.
In this project, you will build an AI agent using Amazon Bedrock Agents that reads your spending data, categorizes expenses, calculates budgets, and generates visual charts, all through natural language conversation with zero coding required.
What You'll Build
A personal finance advisor AI agent powered by Amazon Bedrock that uses Code Interpreter to autonomously write and execute Python code, analyzing a CSV of transactions and producing spending breakdowns and charts on demand.
By the end of this project, you'll have:
- 🤖 An Amazon Bedrock Agent configured as a personal finance advisor with custom natural language instructions.
- 🧠 Code Interpreter enabled on your agent, giving it the ability to write and run Python code in a secure sandbox.
- 📊 A spending analysis where the agent reads your transactions CSV, categorizes expenses, and generates visual charts.
- 💎 Secret Mission: Enable agent memory so your finance agent remembers conversations across sessions.
Want a complete demo of how to do this project, from start to finish? Check out our 🎬 walkthrough with Kahu:
Do I need to pay to do this project?
Amazon Bedrock charges per API call, but costs for this project are minimal (less than $0.01). You will need an AWS account with model access enabled. If you do not have one yet, check the prerequisites to set one up for free.
Not sure if this project is right for you? Check if it matches your goals
If you're up for a bit of a challenge, quiz yourself on the key concepts up ahead in this project.
Set Up Amazon Bedrock
Time to find the AI service that will power your finance agent.
Amazon Bedrock is a fully managed AWS service that gives you access to foundation models from Amazon, Anthropic, Meta, and others through a single API. You don't need to manage any servers or infrastructure.
In this step, get ready to:
- Sign into your AWS account and set your region.
- Navigate to Amazon Bedrock and find Amazon Nova 2 Lite in the model catalog.
- Preview the Bedrock Agents feature.
Sign In and Set Your Region
- Navigate to the AWS Management Console in your browser.
What do you see?
✔️ I see the AWS Console dashboard
You're already signed in. Continue on to the next instruction.
✋ I see a sign-in page
That's great! Let's enter your account details.
- Enter your Account ID (or alias), IAM username, and password, then click Sign in.
Need help finding your credentials?
If you completed the Set Up An AWS Account for Free project, your credentials are in the .csv file you downloaded when you created your IAM user. If you set up AWS on your own, sign in with whichever credentials you normally use. If you're unsure, try signing in as a Root user with the email address you used to create your AWS account.
ⓧ I don't have an account
This project requires an AWS account. Complete the Set Up An AWS Account for Free project first, then come back here. It takes about 10 minutes.
- Look at the region selector in the top-right corner of the console.
- Select US East (N. Virginia) (us-east-1).
Why us-east-1?
Code Interpreter for Bedrock Agents is only available in specific regions: us-east-1, us-west-2, and eu-central-1. We use us-east-1 because it has the widest model and feature availability.
Explore the Model Catalog
- Type Bedrock in the search bar at the top of the console.
- Select Amazon Bedrock from the search results.
- In the left sidebar, click Model catalog (under Discover).
What is a foundation model?
A foundation model is a large AI model pre-trained on massive amounts of data. Instead of training your own model (which costs millions of dollars), you access one through an API. Think of it like renting a brain instead of building one.
- Search for Nova 2 Lite in the model catalog.
- Confirm that Amazon Nova 2 Lite appears in the results.
Why Amazon Nova 2 Lite?
Amazon Nova 2 Lite is Amazon's own lightweight, fast, and cost-effective model. Amazon-owned models are automatically available in your account with no manual enablement needed.
✔️ I can see Nova 2 Lite
You're all set. Amazon Nova 2 Lite is ready for you to use.
ⓧ I can't find Nova 2 Lite
Let's troubleshoot:
- Check that your region is set to US East (N. Virginia) (us-east-1) in the top-right corner.
- Check that your IAM user has appropriate Bedrock permissions, or that you are using an admin-level IAM user.
- Try refreshing the page.
Still stuck?
Get help with your error or share your error with the NextWork community!
Preview Bedrock Agents
- In the left sidebar, click Agents (under Build).
You should now see the Bedrock Agents page.
What is a Bedrock Agent?
A Bedrock Agent is an AI that can reason through multi-step tasks autonomously. Unlike a simple chatbot that just answers questions, an agent can decide what actions to take, execute code, call APIs, and iterate on results. You give it instructions in plain English, and it figures out the steps on its own. This is what agentic AI means.
You've confirmed that Amazon Bedrock is available, Nova 2 Lite is ready, and you've seen where Agents live. Next up, you'll create your very own Bedrock Agent and give it the power to write and run code.
Build Your AI Agent
Now it is time to create the core of this project: your very own AI agent. Instead of simply answering questions about your finances, your agent will write and run Python code to crunch the numbers for you. To make that happen, we need to set up the agent and give it clear instructions on how to behave.
In this step, get ready to:
- Create an Amazon Bedrock Agent as a personal finance advisor.
- Write the agent's natural language instructions.
- Enable Code Interpreter so the agent can write and execute Python code.
Create Your Agent
- On the Agents page, click Create Agent.
- For Agent name, enter nextwork-finance-advisor.
- Optionally, add a description like A personal finance AI that analyzes spending data.
- Click Create.
Seeing a popup about an existing service role?
If you see a popup asking about a service role, select Create and use a new service role and click Create. AWS creates a role that gives your agent permission to call Bedrock models.
If you don't see a popup, that's fine too. AWS may auto-create the role for you, or you can select Create and use a new service role on the next page.
You are now in the Agent Builder. This is your agent's control center, where you configure everything about how it works.
What about Multi-agent collaboration?
You might notice a Multi-agent collaboration option when creating your agent. This lets multiple agents work together on complex tasks, where a supervisor agent delegates subtasks to specialized agents. We are skipping this because our finance agent handles everything on its own. Multi-agent setups are useful when you need separate agents for distinct responsibilities, like one for data analysis and another for report generation.
Configure the Model and Instructions
The most important part of your agent is its instructions. These are natural language directions that tell the agent who it is and how it should behave. This is prompt engineering in action.
- Under Select model, click the pencil icon next to the default model name to change it.
- Select Amazon on the left, then choose Nova Lite (1.0). Click Apply.
Need a reminder on why Amazon Nova Lite?
Amazon Nova Lite is one of Amazon's own foundation models. It is automatically available with no approval forms needed, it is the most affordable option, and it handles data analysis and code generation well for this use case.
- In the Instructions text box, paste the following:
You are a personal finance advisor. Analyze spending data, categorize expenses, and suggest budgets.
Why do instructions matter so much?
Instructions are your agent's personality and operating manual. The more specific and clear your instructions are, the better the agent performs. You will see the impact of this later when you iterate on these instructions to improve the agent's output.
Want to learn more about prompt engineering? You can also check out our Prompt Engineering project for a deeper dive.
Enable Code Interpreter
Now let's give your agent a superpower: the ability to write and run its own code.
- Scroll down to the Additional settings section and expand it.
- For Code Interpreter, select Enable.
What is Code Interpreter?
Code Interpreter gives the agent the ability to autonomously write, execute, and debug Python code in a secure, sandboxed environment. When you ask the agent to analyze your spending, it writes Python code using libraries like pandas, runs it, and returns the results.
- Click Save and Exit to save your agent configuration and return to the agent overview page.
- Click Prepare to prepare the agent for testing.
Can't find the Prepare button?
Depending on your console version, the Prepare button may appear at the top of the page or inside the test chat panel. Both work the same way.
💡 What does Prepare do?
Preparing the agent compiles your configuration (instructions, model selection, enabled tools) into a deployable version. You must prepare after every change before you can test it.
- Wait for the agent status to show Prepared (this takes a few seconds).
✔️ My agent is Prepared
You're all set. Your agent is ready to test.
ⓧ My agent is not showing as Prepared
Let's troubleshoot:
- Make sure you clicked both Save and Prepare. Saving alone does not make the agent testable.
- If you only see a Save confirmation but not a Prepared status, click Prepare again.
- Check that you selected a valid model (Amazon Nova Lite) and that your instructions field is not empty.
- Try refreshing the page and clicking Prepare one more time.
Still stuck?
Get help with your error or share your error with the NextWork community!
Your agent is configured, instructed, and ready to go. Next up, you will put it to the test with real transaction data and watch it analyze your spending in real time.
Analyze Your Finances
Your AI agent is built, instructions are set, and Code Interpreter is ready to go. Now it is time to put it to work on real data. In this step, you will upload a mock transactions file, ask the agent to analyze your spending, and watch it write and execute its own Python code to produce insights.
Along the way, you will explore agent traces to see exactly how your agent thinks and then iterate on its instructions to improve the quality of its output.
In this step, get ready to:
- Upload a transactions CSV and get a spending summary from your agent.
- Get budget recommendations from your agent.
- Iterate on your agent's instructions for better output.
Upload Your Transactions Data
Before you can ask your agent to analyze anything, it needs data. You will upload a mock CSV file containing realistic personal transactions.
- Download the sample transactions file: transactions.csv.
What is in this CSV?
The file contains around 30-50 rows of realistic personal transactions with columns for Date, Description, Category, and Amount. Categories include Food & Dining, Entertainment, Transportation, Utilities, Shopping, Health, and Subscriptions. Amounts range from $3.50 to $250, spanning about 1-2 months of spending.
- In the Amazon Bedrock console, open your agent's detail page.
- Click Test to open the test panel.
- Click the three dots in the chat input area.
- Select Attach file.
- Under Choose function, select Attach files to Code Interpreter.
- Under Choose upload method, select Your computer.
- Select the transactions.csv file you downloaded.
- Click Attach.
Why Code Interpreter and not Chat?
Attach files to Chat lets the agent read your file, but Attach files to Code Interpreter lets the agent write and run Python code to analyze it. Since we want the agent to write Python code to analyze our data, we need Code Interpreter.
- Type the following prompt and press Enter:
Use code interpreter to read the uploaded file and calculate total spending by category
You should see a spending breakdown by category. The agent wrote a Python script using the pandas library, executed it against your CSV file, and formatted the results into the summary below. You did not write any code. The agent did it all on its own.
How do I know code was actually executed?
You will see the exact Python code the agent wrote in the next section when you explore agent traces. For now, just know that every time Code Interpreter is involved, the agent is autonomously writing and running real Python code.
✔️ I see a spending breakdown
Your agent analyzed the data successfully. Keep going.
ⓧ I see an error or unexpected response
Let's troubleshoot:
- Network error? Click the broom/clear icon to refresh the chat, re-upload your CSV, and try again. This is common on the first attempt.
- Had to run it multiple times? That's normal. Bedrock Agents can occasionally time out or fail on the first try. Just re-send the same prompt.
- Check that you uploaded a .csv file (not a .xlsx or other format).
- Make sure Code Interpreter is enabled in your agent's configuration. Go to Additional settings and confirm it shows Enabled.
- If the agent responds but does not analyze the data, try rephrasing: Use code interpreter to read the uploaded file and summarize total spending by category.
Still stuck?
Get help with your error or share your error with the NextWork community!
Ask for Budget Recommendations
Now that the agent understands your data, ask it to go deeper with a budget analysis.
- Type the following prompt:
Use code interpreter to suggest a monthly budget for each category based on my spending. Highlight any categories where I might be overspending.
You should see the agent generate a budget breakdown for each spending category, with flags on any categories where you might be overspending.
Explore Agent Traces and Iterate
One of the most powerful features of Amazon Bedrock Agents is the ability to see exactly how your agent thinks through a problem. These are called agent traces.
- Click Show trace (or the trace icon) next to any of the agent's responses.
You should see a detailed breakdown of the agent's reasoning process, including the tools it used and the code it ran.
- Examine the trace to see step-by-step reasoning. You should see the agent's rationale for how it decided what to do:
What is inside an agent trace?
Each trace shows four key parts:
- Rationale: The agent's thought process for deciding what to do.
- Action: What tool the agent chose to use (Code Interpreter).
- Code: The actual Python code the agent wrote and executed.
- Observation: The output or result of running that code.
Agent traces give you full transparency into the agent's decision-making process. This is how you debug and understand AI agent behavior.
Look at the Code section in the trace. You should see import pandas as pd, code that reads your CSV, and calculations that produced the spending breakdown. This is the actual Python code your agent wrote and ran entirely on its own. You did not write a single line.
Now try improving your agent's output by updating its instructions.
- Go back to the agent configuration by clicking Edit in Agent Builder.
- Replace the Instructions with the following improved version:
You are a personal finance advisor. Analyze spending data, categorize expenses, and suggest budgets. Always show dollar amounts with two decimal places. Include percentage breakdowns showing what fraction of total spending each category represents.
- Click Save to save the updated configuration.
- Click Prepare to recompile the agent with the new instructions.
- Return to the Test panel.
- Click the three dots in the chat input area.
- Select Attach file.
- Select Attach files to Code Interpreter, then Your computer, and re-upload your transactions.csv file.
- Re-send the same spending summary prompt:
Use code interpreter to read the uploaded file and calculate total spending by category
You should now see dollar amounts with two decimal places and percentage breakdowns for each category. Compare this with your earlier output to see the improvement.
I don't see any difference
If the output looks the same as before, click Prepare again to make sure the agent picked up your new instructions, then re-upload the CSV and re-send the prompt. AI responses can vary, so you may need to try a couple of times.
Why does iterating on instructions matter?
Iterating on an agent's instructions is the agent equivalent of prompt engineering. Small changes to the instructions can dramatically improve the quality, accuracy, and formatting of the agent's output. This is how you tune an AI agent in production.
You've uploaded data, explored agent traces, and iterated on your instructions to improve output quality. Next up, a secret mission to take your agent even further.
Secret mission
Your finance agent works great in a single conversation, but what happens when a user comes back the next day? Right now, the agent starts from scratch every time.
In this secret mission, you'll enable agent memory so your Bedrock Agent retains context across separate sessions, then test that it can recall spending patterns and budget goals from a prior conversation.
In this secret mission, get ready to:
- Enable agent memory with session summarization.
- Establish spending preferences in a test session.
- Verify the agent recalls your goals in a new session.
Teach Your Agent to Remember
Clean Up Your Resources
Clean Up Your Resources
Decide whether to keep your resources running, pause them to come back later, or delete them entirely. Bedrock Agents do not incur charges when idle, so there is no per-agent fee. All costs in this project came from foundation model token usage during agent interactions, typically under $0.01 total.
Cost warning
All costs in this project came from Amazon Bedrock model token usage during agent interactions. Typical total cost is under $0.01. There are no ongoing charges for idle agents.
Resources you used:
- Finance advisor Bedrock Agent (including its auto-created service role).
- Agent memory data (auto-deleted when the agent is deleted).
✔️ Keep everything running
No action needed. Choose this if you're still actively building or want to keep testing right away.
Your agent sits idle at no cost. You can return to the Amazon Bedrock console and start a new conversation any time.
✋ Pause - I'll come back to this later
There is nothing to pause for this project. Bedrock Agents do not run continuously, so they do not cost money when not in use. Your agent will be right where you left it when you come back.
ⓧ Delete - I don't want to use this again
Remove the agent and its associated data so your account is completely clean.
- Open the Amazon Bedrock console.
- In the left sidebar, select Agents under Build.
- Select your finance advisor agent.
- Click Delete.
- Confirm the deletion when prompted.
Memory data is deleted automatically when the agent is deleted. There are no Lambda functions, S3 buckets, or other resources to clean up.
Nice Work!
Nice Work!
Well done! 🚀 You've just built an AI-powered finance agent using Amazon Bedrock that can analyze spending data and calculate budgets autonomously.
You've learned how to:
- 🧠 Explore Amazon Bedrock and select a foundation model for your agent.
- 🤖 Create an AI agent with a custom persona using natural language instructions.
- 🐍 Enable Code Interpreter so your agent can write and execute Python code autonomously.
- 📊 Upload financial data and have the agent categorize spending and calculate budgets.
- 🔍 Inspect agent traces to understand how the AI reasons through each request.
- ✏️ Iterate on agent instructions to improve output quality through prompt engineering.
- 💎 Enable agent memory for cross-session context retention (Secret Mission).
Ready to quiz yourself? 💪
p.s. Does it say "Still tasks to complete!" at the bottom of the screen?
This means you still have screenshots left to upload, or questions left to answer!
- Press Ctrl+F (Windows) or Command+F (Mac) on your keyboard.
- Search for the text Return to later.
- Jump straight to your incomplete tasks!
- 🙋♀️ Still stuck? Ask the community!