Skip to content

CursorAgents

Nuget package dotnet License: MIT Discord

Features 🔥

  • Fully generated C# SDK based on official CursorAgents OpenAPI specification using AutoSDK
  • Same day update to support new features
  • Updated and supported automatically if there are no breaking changes
  • All modern .NET features - nullability, trimming, NativeAOT, etc.
  • Support .Net Framework/.Net Standard 2.0

Usage

1
2
3
using CursorAgents;

using var client = new CursorAgentsClient(apiKey);

Create Agent

Launch a cloud agent to work autonomously on a GitHub repository.

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

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

// Launch a coding agent with a prompt, source repository, and target branch settings.
var response = await client.CreateAgentAsync(
    prompt: new CreateAgentRequestPrompt
    {
        Text = "Add a CONTRIBUTING.md file with guidelines for submitting pull requests",
    },
    source: new CreateAgentRequestSource
    {
        Repository = repositoryUrl,
        Ref = "main",
    },
    target: new CreateAgentRequestTarget
    {
        AutoCreatePr = true,
        BranchName = "cursor/add-contributing",
    });

// The response contains the agent ID, name, and initial status.

Console.WriteLine($"Agent created: {response.Id} ({response.Name})");
Console.WriteLine($"Status: {response.Status}");

List Agents

List cloud agents and check their statuses.

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

// List cloud agents for the authenticated user with a page limit.
var response = await client.ListAgentsAsync(
    limit: 10);

// The response contains a list of agents with their status and metadata.

foreach (var agent in response.Agents)
{

    Console.WriteLine($"Agent {agent.Id}: {agent.Name}");
    Console.WriteLine($"  Status: {agent.Status.ToValueString()}");
    Console.WriteLine($"  Created: {agent.CreatedAt}");

    if (agent.Summary is { Length: > 0 })
    {
        Console.WriteLine($"  Summary: {agent.Summary}");
    }
}

// Use the NextCursor property for pagination when there are more results.
if (response.NextCursor is { Length: > 0 })
{
    Console.WriteLine($"Next page cursor: {response.NextCursor}");
}

Get Conversation

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

 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}");
}

As Tool Creates Agent Tool

Verify that AsCreateAgentTool creates a valid AIFunction.

1
2
3
4
5
6
// Create a client and wrap it as an MEAI tool.
using var client = new CursorAgentsClient(apiKey);

var tool = client.AsCreateAgentTool();

// The tool has a name and description for use with any IChatClient.

As Tool Creates List Tool

Verify that AsListAgentsTool creates a valid AIFunction.

1
2
3
4
5
6
// Create a client and wrap it as an MEAI tool.
using var client = new CursorAgentsClient(apiKey);

var tool = client.AsListAgentsTool();

// The tool has a name and description for use with any IChatClient.

As Tool Creates Get Agent Tool

Verify that AsGetAgentTool creates a valid AIFunction.

1
2
3
4
5
6
// Create a client and wrap it as an MEAI tool.
using var client = new CursorAgentsClient(apiKey);

var tool = client.AsGetAgentTool();

// The tool has a name and description for use with any IChatClient.

Support

Priority place for bugs: https://github.com/tryAGI/CursorAgents/issues
Priority place for ideas and general questions: https://github.com/tryAGI/CursorAgents/discussions
Discord: https://discord.gg/Ca2xhfBf3v

Acknowledgments

JetBrains logo

This project is supported by JetBrains through the Open Source Support Program.