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.