SENTIENTA

In depth tools for working with your teams:

Question: How do I build an agent myself?

Sentienta supports external agents that expose an API. For example, you can create an agent in AWS Lambda. The following steps describe how to create a basic lambda function in AWS that accepts a POST to a URL that you will create. This simple lambda will just echo the content you send in the URL. To make this a useful agent, your code would take the input from the post and do something with it instead of just returning it.

Remember that to add the agent to Sentienta, you create a new agent with a name, title, persona and the url you created. The persona will tell your agent what to do with the content and question it receives in the POST.

To create a simple AWS Lambda function with a public API that accepts POST requests, you'll use AWS Lambda in combination with Amazon API Gateway. This will involve creating a Lambda function, setting up an API Gateway to trigger the Lambda function, and configuring the API Gateway to accept POST requests.

        

Step 1: Create an AWS Lambda Function

Log in to the AWS Management Console: Go to the AWS Management Console. Navigate to Lambda: Search for and select "Lambda" in the AWS Management Console. Create a New Lambda Function: 1. Click on "Create function." 2. Choose "Author from scratch." 3. Provide a name for your function, e.g., MyPostLambda. 4. Choose a runtime, e.g., Python 3.9. 5. Set the role to "Create a new role with basic Lambda permissions." 6. Click "Create function." Write the Lambda Function Code: In the function editor, add the following code to handle POST requests: import os import json def lambda_handler(event, context): # This is the event that will be sent from Sentienta: #event = { # "agentName": "Greg", # "agentType": "Search Agent", # "agentPersona": "You are an expert at searching the web. You understand the # conversation and can formulate the perfect search query to get # information to add to the discussion.", # "queryType": "query", //This is predefined by Sentienta // # "query": "We have been discussing the latest Q1 results and how we might # adjust our capacity to improve the supply chain." #} sts = 200 response = '' queryType = event.get('queryType') # [query] if queryType == 'query': response = event.get('query') # Just echo the current dialog query return { 'statusCode': sts, 'body': response } Save the Lambda Function: Click on "Deploy" to save your Lambda function.

Step 2: Set Up an API Gateway

Navigate to API Gateway: In the AWS Management Console, search for and select "API Gateway." Create a New REST API: 1. Click on "Create API." 2. Select "REST API" and choose "Build." 3. Choose "New API" and give it a name, e.g., MyPostApi. 4. Keep the "Endpoint Type" as "Regional" and click "Create API." Create a New Resource: 1. In the API Gateway dashboard, click on "Actions" and choose "Create Resource." 2. Provide a name for your resource, e.g., postdata. 3. Click "Create Resource." Create a POST Method: 1. Select the newly created resource (/postdata). 2. Click "Actions" and select "Create Method." 3. Choose POST from the dropdown and click the checkmark. Integrate with Lambda Function: 1. Select "Lambda Function" as the integration type. 2. Use the "Use Lambda Proxy integration" option. 3. In the "Lambda Function" field, enter the name of the Lambda function created earlier (MyPostLambda). 4. Click "Save" and confirm the dialog box to give API Gateway permissions to invoke the Lambda function. Deploy the API: 1. Click on "Actions" and select "Deploy API." 2. Choose "New Stage" and give it a name, e.g., dev. 3. Click "Deploy." Get the Invoke URL: After deployment, you'll get an "Invoke URL" for the API. This URL will be the public endpoint that accepts POST requests.

Step 3: Test the API

Use Postman or cURL to Test the API: Use a tool like Postman or curl to send a POST request to the API Gateway endpoint. Example using curl: curl -X POST /postdata -H "Content-Type: application/json" -d '{"key": "value"}' Check the Response: You should receive a response from the Lambda function, echoing the data you sent.

Step 4: (Optional) Set Up Permissions and CORS

Configure CORS: If you plan to call this API from a web client (browser), you may need to set up Cross-Origin Resource Sharing (CORS) for the API Gateway resource. Go to the method in API Gateway and select "Enable CORS." Configure the allowed origins, headers, and methods.