// 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",},source:newCreateAgentRequestSource{Repository=repositoryUrl,Ref="main",},target:newCreateAgentRequestTarget{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}");
// 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.Agents){Console.WriteLine($"Agent {agent.Id}: {agent.Name}");Console.WriteLine($" Status: {agent.Status.ToValueString()}");Console.WriteLine($" Created: {agent.CreatedAt}");if(agent.Summaryis{Length:>0}){Console.WriteLine($" Summary: {agent.Summary}");}}// 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 91011121314151617181920212223
// 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 full conversation history for a specific agent.varresponse=awaitclient.GetAgentConversationAsync(id:agentId);// The response contains the agent ID and all messages in chronological order.foreach(varmessageinresponse.Messages){varrole=message.Type==GetAgentConversationResponseMessageType.UserMessage?"User":"Assistant";Console.WriteLine($"[{role}] {message.Text}");}
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.