Skip to main content

Copilot Agent

Copilot Agents are similar to an Assistant Agent but with an added capability to update the user interface through callbacks. This feature allows the agent to interact more dynamically with the UI, providing real-time assistance and updates.

For example, a Copilot Agent can be integrated into a complex form, helping users complete the form by filling in inputs, providing feedback, and making adjustments as needed.

Use cases

  • Form Completion Assistant: Given a complex form, the agent helps the user by auto-filling inputs, validating entries, and providing real-time feedback.
  • Real-time Data Entry Assistant: In a data entry application, the agent assists by automatically populating fields, correcting errors, and ensuring data consistency.
  • E-commerce Shopping Assistant: While browsing an online store, the agent can suggest products, apply filters, and add items to the cart based on user preferences.

Should I use this agent?

✅ You need an agent that can interact dynamically with the user interface, providing real-time assistance and updates.

⛔ You do not need real-time UI updates or callbacks. In those cases, you may want to use an Assistant Agent instead.

Creating a Copilot Agent

To create a Copilot Agent, follow this guide.

Usage examples

Let's say you have a Copilot Agent that assists with booking flights. You can interact with it as follows:

cURL

# Step 1: Generate the conversation and get the chatId
curl -X POST \
-L "https://api.serenitystar.ai/api/agent/travel-booking/conversation" \
-H "Content-Type: application/json" \
-H "X-API-KEY: <YOUR_API_KEY>"

# Step 2: Execute the conversation using the chatId obtained from the first step
curl -X POST \
-L "https://api.serenitystar.ai/api/agent/travel-booking/execute" \
-H "Content-Type: application/json" \
-H "X-API-KEY: <YOUR_API_KEY>" \
-d '[
{
"Key": "message",
"Value": "I want to book a flight from New York to London on December 25th."
},
{
"Key": "chatId",
"Value": "<YOUR_CHAT_ID>"
}
]'

C#

using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

class Program
{
static async Task Main()
{
var client = new HttpClient();

// Step 1: Generate the conversation and get the chatId
var createConversationRequest = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://api.serenitystar.ai/api/agent/travel-booking/conversation"),
Headers =
{
{ "X-API-KEY", "<YOUR_API_KEY>" },
{ "Content-Type", "application/json" },
}
};

var createConversationResponse = await client.SendAsync(createConversationRequest);
var conversationContent = await createConversationResponse.Content.ReadAsStringAsync();
var chatId = JObject.Parse(conversationContent)["chatId"].ToString();

// Step 2: Execute the conversation using the chatId obtained from the first step
var executionRequest = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://api.serenitystar.ai/api/agent/travel-booking/execute"),
Headers =
{
{ "X-API-KEY", "<YOUR_API_KEY>" },
{ "Content-Type", "application/json" },
},
Content = new StringContent($@"[
{{
""Key"": ""message"",
""Value"": ""I want to book a flight from New York to London on December 25th.""
}},
{{
""Key"": ""chatId"",
""Value"": ""{chatId}""
}}
]", Encoding.UTF8, "application/json"),
};

var executionResponse = await client.SendAsync(executionRequest);
var executionContent = await executionResponse.Content.ReadAsStringAsync();
Console.WriteLine(executionContent);
}
}

Python

import requests
import json

# Step 1: Generate the conversation and get the chatId
create_conversation_url = 'https://api.serenitystar.ai/api/agent/travel-booking/conversation'
headers = {
'Content-Type': 'application/json',
'X-API-KEY': '<YOUR_API_KEY>'
}

create_conversation_response = requests.post(create_conversation_url, headers=headers)
conversation_content = create_conversation_response.json()
chatId = conversation_content.get('chatId')

# Step 2: Execute the conversation using the chatId obtained from the first step
execution_url = 'https://api.serenitystar.ai/api/agent/travel-booking/execute'
payload = json.dumps([
{
"Key": "message",
"Value": "I want to book a flight from New York to London on December 25th."
},
{
"Key": "chatId",
"Value": chatId
}
])

execution_response = requests.post(execution_url, headers=headers, data=payload)
print(execution_response.text)