Call Serverless Function
Overview
Serverless Functions allow your agents to execute custom code in the cloud without managing infrastructure. This powerful capability enables complex operations and integrations beyond what standard actions can provide.
Use Cases
-
Custom Logic Implementation: Execute specialized code for unique business requirements
-
External System Integration: Connect with third-party services and APIs
-
Advanced Data Processing: Perform complex calculations and transformations
-
Extended Functionality: Add capabilities not available in standard Agent.ai actions
How Serverless Functions Work
Serverless Functions in Agent.ai:
-
Run in AWS Lambda (fully managed by Agent.ai)
-
Support Python and Node.js
-
Automatically deploy when you save the action
-
Generate a REST API endpoint for programmatic access
Creating a Serverless Function
-
In the Actions tab, click “Add action”
-
Select the “Advanced” category
-
Choose “Call Serverless Function”
Configuration Fields
Language
-
Description: Select the programming language for the serverless function.
-
Options: Python, Node
-
Required: Yes
Serverless Code
-
Description: Write your custom code.
-
Example: Python or Node script performing custom logic.
-
Required: Yes
Serverless API URL
-
Description: Provide the API URL for the deployed serverless function.
-
Required: Yes (auto-generated upon deployment)
Output Variable Name
-
Description: Assign a variable name to store the result of the serverless function.
-
Example: “function_result” or “api_response.”
-
Validation: Only letters, numbers, and underscores (_) are allowed.
-
Required: Yes
Deploy and Save
-
Click “Deploy to AWS Lambda”
-
After successful deployment, the API URL will be populated automatically
Using Function Results
The function’s output is stored in your specified variable name. You can access specific data points using dot notation, for example:
-
{{variable_name.message}}
-
{{variable_name.input}}
Example: Serverless Function Agent
See this simple Message Analysis Agent that demonstrates how to use Serverless Functions:
-
Step 1: Get user input text message
-
Step 2: Call a serverless function that analyzes:
-
Word count
-
Character count
-
Sentiment (positive/negative/neutral)
-
-
Step 3: Display the results in a formatted output
This sample agent shows how Serverless Functions can extend your agent’s capabilities with custom logic that would be difficult to implement using standard actions alone.