Skip to main content
Version: 2.0

Lambda tools

As your AI agents take on more complex workflows, they might need to perform actions that go beyond what built-in tools can handle. For example, applying custom business logic or transforming data.

Lambda Tools enable you to create custom Python functions that your agents can run during conversations. Think of them as custom skills that teach your agent how to handle specialized tasks. These user-defined functions run in secure, sandboxed environments, allowing you to extend agent capabilities with custom business logic, data processing, or integrations. Check out our tutorial on building a financial research agent.

Lambda Tools are user-defined functions that:

  • Execute in a sandboxed Python 3.12 environment with gVisor isolation.
  • Have automatic schema discovery from function type annotations.
  • Support a curated set of libraries: json, math, datetime, collections, itertools, functools, re, time, typing.
  • Include resource limits: 100MB memory (up to 1GB), 30-second timeout (up to 300 seconds).
  • Provide complete audit trails of execution history.
Note

Lambda Tools run without network access. You have read-only file system access, and you cannot install custom packages. This ensures secure execution in multi-tenant environments.

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 $ref to 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

Create a lambda tool

To create a Lambda Tool, review the prerequisites, define a function, and use the API.

  1. Meet the following prerequisites:
    • Access to the Vectara API with tool creation permissions.
    • Basic Python familiarity.
    • API key.
  2. 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.
    1
    Notes
    • Use type annotations for automatic schema discovery
    • Parameters with default values become optional in the schema
    • Return a JSON-serializable dictionary
  3. Create the Lambda Tool with the API.

    CREATE LAMBDA TOOL REQUEST

    Code example with curl syntax.
    1
    Example response:

    CREATE 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 decoding
  • math - Mathematical functions
  • datetime - Date and time handling
  • collections - Container datatypes (deque, Counter, OrderedDict, etc.)
  • itertools - Iterator functions
  • functools - Higher-order functions and operations on callable objects
  • re - Regular expression operations
  • time - Time access and conversions
  • typing - Type hints and annotations (List, Dict, Optional, Union, TypedDict, etc.)
Security Constraints

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