Skip to content

Get Conversation

Retrieve the conversation history of a cloud agent, including user prompts and assistant responses.

This example assumes using CursorAgents; is in scope and apiKey contains your CursorAgents API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Create a client with your Cursor API key.
using var client = new CursorAgentsClient(apiKey);

var agentId =
    Environment.GetEnvironmentVariable("CURSORAGENTS_TEST_AGENT_ID") is { Length: > 0 } idValue
        ? idValue
        : throw new AssertInconclusiveException(
            "CURSORAGENTS_TEST_AGENT_ID environment variable is not found.");

// Retrieve the full conversation history for a specific agent.
var response = await client.GetAgentConversationAsync(
    id: agentId);

// The response contains the agent ID and all messages in chronological order.

foreach (var message in response.Messages)
{
    var role = message.Type == GetAgentConversationResponseMessageType.UserMessage
        ? "User"
        : "Assistant";

    Console.WriteLine($"[{role}] {message.Text}");
}