Build a Financial Research Agent
This tutorial demonstrates how to create custom Lambda Tools with different return types and use them with AI agents. You'll build a Financial Research Assistant that performs calculations, looks up stock tickers, assesses portfolio risk, and analyzes holdings.
What you will learn
By the end of this tutorial, you'll know how to:
- ✅ Create Lambda tools with custom Python code.
- ✅ Work with different return types (float, string, boolean, dictionary).
- ✅ Use automatic schema discovery from type annotations.
- ✅ Test tools independently before deployment.
- ✅ Configure agents with multiple tools.
- ✅ Update existing tools with new functionality.
- ✅ Use tools in conversational AI workflows.
What are Lambda Tools?
Lambda tools are user-defined Python 3.12 functions that run in a secure, sandboxed environment:
- Execute your custom code in an isolated container.
- Support standard Python modules:
json,math,datetime,collections,itertools,functools,re,time,typing. - Have resource limits (default: 100MB memory, 30s timeout).
- Automatically generate input/output schemas from type annotations.
Part 1. Setup and configuration
Before you begin, ensure you have:
- A Vectara account (sign up here)
- An API key with tool creation permissions
- Familiarity with REST APIs
Then, set up your environment and configure API access:
INSTALL DEPENDENCIES
Code example with bash syntax.1
CONFIGURE API ACCESS
Code example with python syntax.1
For example:
SETUP COMPLETE
Code example with python syntax.1
Part 2. Simple Calculator Tool (Returns Float)
Let's start with the simplest Lambda tool, a calculator that returns a numeric value.
Key points
- Entry point: Must define a
process()function. - Type annotations: Used for automatic schema discovery.
- Return type: This tool returns a
float, a single numeric value. - Code display: We define the function normally first (for syntax highlighting), then convert it to a string.
CREATE CALCULATOR TOOL
Code example with python syntax.1
For example:
CALCULATOR TOOL CREATED
Code example with python syntax.1
Test the Calculator
Let's test our calculator with a simple multiplication operation.
TEST CALCULATOR TOOL
Code example with python syntax.1
Expected Output:
🧪 Test Results:
Type: success
Execution Time: 772ms
🔢 Result: 25 × 4 = {'content': '100.0'}
Return Type: dict
Part 3: Stock Ticker Formatter (Returns String)
Now let's create a tool that returns a string value for a stock ticket symbol formatter.
Define the Function
STOCK TICKER FORMATTER
Code example with python syntax.1
For example:
TICKER FORMATTER TOOL CREATED
Code example with python syntax.1
Test the Ticker Formatter
Let's test looking up a company's ticker symbol.
TEST THE TICKER FORMATTER
Code example with python syntax.1
For example:
TEST RESULTS
Code example with python syntax.1
Part 4: Risk Checker (Returns Boolean)
This tool returns a bool which is perfect for yes/no decisions and validation.
Key difference
- Return type: This tool returns
bool, True or False. - Use case: Decision making, validation, risk assessment.
CREATE RISK CHECKER TOOL
Code example with python syntax.1
For example:
EXPECTED OUTPUT
Code example with python syntax.1
Test the Risk Checker
Let's test different scenarios to see the boolean return values.
TEST THE RISK CHECKER
Code example with python syntax.1
For example:
EXPECTED OUTPUT
Code example with python syntax.1
Part 5: Portfolio Analyzer (Returns Dictionary)
Finally, let's create a more complex tool that returns structured data as a
dict.
Key difference:
- Return type: This tool returns
dict, a structured data with multiple fields, - Use case: Complex analysis with multiple output values,
CREATE PORTFOLIO ANALYZER TOOL
Code example with python syntax.1
For example:
EXPECTED OUTPUT
Code example with python syntax.1
Test the Portfolio Analyzer
Let's test analyzing a portfolio with multiple holdings.
TEST THE PORTFOLIO ANALYZER
Code example with python syntax.1
For example:
EXPECTED OUTPUT
Code example with python syntax.1
Part 6: Update a Tool
Tools can be updated to add new functionality. Let's enhance the calculator with a "power" operation.
UPDATE CALCULATOR WITH POWER OPERATION
Code example with python syntax.1
For example:
EXPECTED OUTPUT
Code example with python syntax.1