// Create a client with your Cursor API key.usingvarclient=newCursorAgentsClient(apiKey);varrepositoryUrl=Environment.GetEnvironmentVariable("CURSORAGENTS_TEST_REPO")is{Length:>0}repoValue?repoValue:thrownewAssertInconclusiveException("CURSORAGENTS_TEST_REPO environment variable is not found.");// Launch a coding agent with a prompt, source repository, and target branch settings.varresponse=awaitclient.CreateAgentAsync(prompt:newCreateAgentRequestPrompt{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}");
// Create a client with your Cursor API key.usingvarclient=newCursorAgentsClient(apiKey);// List cloud agents for the authenticated user with a page limit.varresponse=awaitclient.ListAgentsAsync(limit:10);// The response contains a list of agents with their status and metadata.foreach(varagentinresponse.Items){Console.WriteLine($"Agent {agent.Id}: {agent.Name}");Console.WriteLine($" Status: {agent.Status.ToValueString()}");Console.WriteLine($" Created: {agent.CreatedAt}");if(agent.LatestRunIdis{Length:>0}){Console.WriteLine($" Latest run: {agent.LatestRunId}");}}// Use the NextCursor property for pagination when there are more results.if(response.NextCursoris{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 91011121314151617181920
// Create a client with your Cursor API key.usingvarclient=newCursorAgentsClient(apiKey);varagentId=Environment.GetEnvironmentVariable("CURSORAGENTS_TEST_AGENT_ID")is{Length:>0}idValue?idValue:thrownewAssertInconclusiveException("CURSORAGENTS_TEST_AGENT_ID environment variable is not found.");// Retrieve the current metadata for a specific agent.varresponse=awaitclient.GetAgentAsync(id:agentId);// The response contains the agent ID and current status.if(response.Summaryis{}summary){Console.WriteLine($"Agent {summary.Id}: {summary.Name}");Console.WriteLine($"Status: {summary.Status.ToValueString()}");}
As Tool Creates Agent Tool
Verify that AsCreateAgentTool creates a valid AIFunction.
123456
// Create a client and wrap it as an MEAI tool.usingvarclient=newCursorAgentsClient(apiKey);vartool=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.
123456
// Create a client and wrap it as an MEAI tool.usingvarclient=newCursorAgentsClient(apiKey);vartool=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.
123456
// Create a client and wrap it as an MEAI tool.usingvarclient=newCursorAgentsClient(apiKey);vartool=client.AsGetAgentTool();// The tool has a name and description for use with any IChatClient.