curl --request POST \
--url https://api-lr.agent.ai/v1/action/serverless_function \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data @- <<EOF
{
"language": "python",
"serverless_code": "import json\n\ndef lambda_handler(event, context):\n agent_context = {}\n \n # Handle POST requests\n if event and 'body' in event and event['body']:\n try:\n event_json = json.loads(event['body'])\n agent_context = event_json.get('context', event_json)\n except json.JSONDecodeError:\n # Handle case where body isn't valid JSON\n agent_context = {\"error\": \"Invalid JSON in request body\"}\n \n # Handle GET requests\n elif event and 'queryStringParameters' in event and event['queryStringParameters']:\n agent_context = event['queryStringParameters']\n \n # Handle API Gateway format for both\n elif event and 'pathParameters' in event and event['pathParameters']:\n agent_context = event['pathParameters']\n \n # Prepare response\n body = {\n \"message\": \"Go Agent.AI Serverless Python Functions v1.0! Your function executed successfully!\",\n \"input\": event,\n \"context\": agent_context\n }\n \n # Include CORS headers for browser access\n headers = {\n \"Content-Type\": \"application/json\",\n \"Access-Control-Allow-Origin\": \"*\",\n \"Access-Control-Allow-Headers\": \"Content-Type\",\n \"Access-Control-Allow-Methods\": \"OPTIONS,POST,GET\"\n }\n \n response = {\n \"statusCode\": 200,\n \"headers\": headers,\n \"body\": json.dumps(body)\n }\n \n return response\n",
"output_variable_name": "<string>"
}
EOF