Create and test lambda tools
To create a Lambda Tool with the API:
- Meet the following prerequisites:
- Access to the Vectara API with tool creation permissions.
- Basic Python familiarity.
- API key.
- Define a simple function. The entry point must be
process.
This example calculates customer scores based on their activity metrics:CUSTOMER_SCORE_CALCULATOR.PY
Code example with python syntax.1Notes- Use type annotations for automatic schema discovery.
- Parameters with default values become optional in the schema.
- Return a JSON-serializable dictionary.
- Create the Lambda Tool with the API.
Example response:
CREATE LAMBDA TOOL REQUEST
Code example with curl syntax.1CREATE LAMBDA TOOL RESPONSE
Code example with json syntax.1
The input and output schemas were automatically discovered from the function's type annotations.
Test Lambda Tools​
Before deploying your Lambda Tool to agents, test it with sample inputs to verify correct behavior.
Test your Lambda Tool​
TEST LAMBDA TOOL REQUEST
Code example with curl syntax.1
Test Response:
TEST LAMBDA TOOL RESPONSE
Code example with json syntax.1
Update lambda tools​
Modify existing Lambda Tools to update code, configuration, or metadata:
UPDATE LAMBDA TOOL REQUEST
Code example with curl syntax.1
When you update the code, schemas are automatically re-discovered from the new function signature.
List all lambda tools​
LIST LAMBDA TOOLS
Code example with curl syntax.1
Disable a lambda tool​
DISABLE LAMBDA TOOL
Code example with curl syntax.1
Delete a lambda tool​
DELETE LAMBDA TOOL
Code example with curl syntax.1
Available Python libraries​
Lambda Tools run in a secure sandbox with access to the following Python 3.12 standard library modules:
json- JSON encoding and decodingmath- Mathematical functionsdatetime- Date and time handlingcollections- Container datatypes (deque, Counter, OrderedDict, etc.)itertools- Iterator functionsfunctools- Higher-order functions and operations on callable objectsre- Regular expression operationstime- Time access and conversionstyping- Type hints and annotations (List, Dict, Optional, Union, TypedDict, etc.)
Lambda Tools cannot:
- Install additional packages (pip install is not available)
- Access the network (all network operations are blocked)
- Write to the file system (read-only environment)
- Execute system commands
- Import modules outside the allowed list
Use a lambda tool with an agent​
After creating a Lambda Tool, you can configure agents to use it through inline tool configurations. You reference the tool by its ID and optionally provide argument overrides.
Inline configuration​
Use an inline configuration to point an agent to an existing Lambda Tool by ID:
INLINE LAMBDA TOOL CONFIGURATION (INSIDE AGENT)
Code example with json syntax.1
The argument_override field allows you to:
- Hardcode specific values that the LLM cannot change (e.g.,
"customer_tier": "enterprise") - Use dynamic context references with
$refto pull values from session or agent metadata (e.g.,{"$ref": "session.metadata.search_query"})
Reusable Lambda tool configuration​
You can also create a reusable LambdaToolConfiguration that can be referenced across multiple agents.
This approach is useful for consistent, governed usage of Lambda Tools.
CREATE REUSABLE LAMBDA TOOL CONFIGURATION
Code example with curl syntax.1
Then reference this configuration in your agent:
REFERENCE LAMBDA TOOL CONFIGURATION IN AGENT
Code example with json syntax.1