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",
    },
    repos:
    [
        new RepoConfig
        {
            Url = repositoryUrl,
            StartingRef = "main",
        },
    ],
    branchName: "cursor/add-contributing",
    autoCreatePR: true);

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

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