serverless_function
Run custom Python or Node code inside workflows to handle complex logic and data transformations.
Instructions
Execute serverless code directly within workflows for complex operations.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"language": "<language>",
"serverless_code": "<serverless_code>",
"output_variable_name": "<output_variable_name>"
},
"name": "serverless_function"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| language | Yes | Select the language for the serverless function, such as 'Python' or 'Node'. | python |
| serverless_code | Yes | Enter the serverless function code here, using Python or Node syntax to perform specific tasks. | import json def lambda_handler(event, context): agent_context = {} # Handle POST requests if event and 'body' in event and event['body']: try: event_json = json.loads(event['body']) agent_context = event_json.get('context', event_json) except json.JSONDecodeError: # Handle case where body isn't valid JSON agent_context = {"error": "Invalid JSON in request body"} # Handle GET requests elif event and 'queryStringParameters' in event and event['queryStringParameters']: agent_context = event['queryStringParameters'] # Handle API Gateway format for both elif event and 'pathParameters' in event and event['pathParameters']: agent_context = event['pathParameters'] # Prepare response body = { "message": "Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!", "input": event, "context": agent_context } # Include CORS headers for browser access headers = { "Content-Type": "application/json", "Access-Control-Allow-Origin": "*", "Access-Control-Allow-Headers": "Content-Type", "Access-Control-Allow-Methods": "OPTIONS,POST,GET" } response = { "statusCode": 200, "headers": headers, "body": json.dumps(body) } return response |
| output_variable_name | Yes | Provide a variable name to store the result of the serverless function, like 'function_result' or 'api_response'. |