The CursorAgents SDK provides AIFunction tool wrappers compatible with Microsoft.Extensions.AI. These tools can be used with any IChatClient to give AI models the ability to create and manage autonomous coding agents on GitHub repositories.
Installation
1
dotnetaddpackageCursorAgents
Create Agent Tool
Use AsCreateAgentTool() to create an AIFunction that launches a cloud coding agent. Pass it to any IChatClient via ChatOptions.Tools.
usingMicrosoft.Extensions.AI;usingCursorAgents;// Create the CursorAgents toolvarcursorClient=newCursorAgentsClient(apiKey:Environment.GetEnvironmentVariable("CURSORAGENTS_API_KEY")!);AIFunctioncreateAgentTool=cursorClient.AsCreateAgentTool(autoCreatePr:true);// Use with any IChatClient (OpenAI, Anthropic, Ollama, etc.)IChatClientchatClient=/* your chat client */;varoptions=newChatOptions{Tools=[createAgentTool],};varmessages=newList<ChatMessage>{new(ChatRole.User,"Create a coding agent to add unit tests to the UserService class "+"in https://github.com/my-org/my-repo"),};while(true){varresponse=awaitchatClient.GetResponseAsync(messages,options);messages.AddRange(response.ToChatMessages());if(response.FinishReason==ChatFinishReason.ToolCalls){varresults=awaitresponse.CallToolsAsync(options);messages.AddRange(results);continue;}Console.WriteLine(response.Text);break;}
List Agents Tool
Use AsListAgentsTool() to create an AIFunction that lists all cloud agents.
1 2 3 4 5 6 7 8 91011121314151617181920
usingMicrosoft.Extensions.AI;usingCursorAgents;varcursorClient=newCursorAgentsClient(apiKey:Environment.GetEnvironmentVariable("CURSORAGENTS_API_KEY")!);AIFunctionlistAgentsTool=cursorClient.AsListAgentsTool(limit:10);IChatClientchatClient=/* your chat client */;varoptions=newChatOptions{Tools=[listAgentsTool],};varresponse=awaitchatClient.GetResponseAsync("What coding agents are currently running?",options);Console.WriteLine(response.Text);
Get Agent Status Tool
Use AsGetAgentTool() to create an AIFunction that retrieves the status of a specific agent.
1 2 3 4 5 6 7 8 91011121314151617181920
usingMicrosoft.Extensions.AI;usingCursorAgents;varcursorClient=newCursorAgentsClient(apiKey:Environment.GetEnvironmentVariable("CURSORAGENTS_API_KEY")!);AIFunctiongetAgentTool=cursorClient.AsGetAgentTool();IChatClientchatClient=/* your chat client */;varoptions=newChatOptions{Tools=[getAgentTool],};varresponse=awaitchatClient.GetResponseAsync("What is the status of agent bc_abc123?",options);Console.WriteLine(response.Text);
Combining All Tools
You can provide all three tools simultaneously, letting the model decide which to use.
usingMicrosoft.Extensions.AI;usingCursorAgents;varcursorClient=newCursorAgentsClient(apiKey:Environment.GetEnvironmentVariable("CURSORAGENTS_API_KEY")!);varoptions=newChatOptions{Tools=[ cursorClient.AsCreateAgentTool(), cursorClient.AsListAgentsTool(), cursorClient.AsGetAgentTool(), ],};IChatClientchatClient=/* your chat client */;varmessages=newList<ChatMessage>{new(ChatRole.User,"Check if there are any running agents. If not, create one to "+"add a CI workflow to https://github.com/my-org/my-repo."),};while(true){varresponse=awaitchatClient.GetResponseAsync(messages,options);messages.AddRange(response.ToChatMessages());if(response.FinishReason==ChatFinishReason.ToolCalls){varresults=awaitresponse.CallToolsAsync(options);messages.AddRange(results);continue;}Console.WriteLine(response.Text);break;}
Tool Details
Method
Tool Name
Description
AsCreateAgentTool()
CreateCodingAgent
Launches an AI coding agent on a GitHub repository