Skip to content

Create Agent

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

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