The RetellAI 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 manage Retell AI voice agents, phone calls, and phone numbers.
Installation
1
dotnetaddpackageRetellAI
List Agents Tool
Use AsListAgentsTool() to create an AIFunction that lists all Retell AI voice agents.
1 2 3 4 5 6 7 8 9101112131415161718192021
usingMicrosoft.Extensions.AI;usingRetellAI;varretellClient=newRetellAiClient(apiKey:Environment.GetEnvironmentVariable("RETELLAI_API_KEY")!);AIFunctionlistAgentsTool=retellClient.AsListAgentsTool(limit:20);// Use with any IChatClient (OpenAI, Anthropic, Ollama, etc.)IChatClientchatClient=/* your chat client */;varoptions=newChatOptions{Tools=[listAgentsTool],};varresponse=awaitchatClient.GetResponseAsync("What voice agents do I have configured?",options);Console.WriteLine(response.Text);
Get Agent Tool
Use AsGetAgentTool() to create an AIFunction that retrieves details of a specific agent.
1 2 3 4 5 6 7 8 91011121314151617181920
usingMicrosoft.Extensions.AI;usingRetellAI;varretellClient=newRetellAiClient(apiKey:Environment.GetEnvironmentVariable("RETELLAI_API_KEY")!);AIFunctiongetAgentTool=retellClient.AsGetAgentTool();IChatClientchatClient=/* your chat client */;varoptions=newChatOptions{Tools=[getAgentTool],};varresponse=awaitchatClient.GetResponseAsync("Get the details of agent oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD",options);Console.WriteLine(response.Text);
Create Phone Call Tool
Use AsCreatePhoneCallTool() to create an AIFunction that initiates outbound phone calls.
usingMicrosoft.Extensions.AI;usingRetellAI;varretellClient=newRetellAiClient(apiKey:Environment.GetEnvironmentVariable("RETELLAI_API_KEY")!);AIFunctioncreateCallTool=retellClient.AsCreatePhoneCallTool();IChatClientchatClient=/* your chat client */;varoptions=newChatOptions{Tools=[createCallTool],};varmessages=newList<ChatMessage>{new(ChatRole.User,"Call +12137774445 from +14157774444 using my support agent."),};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 Calls Tool
Use AsListCallsTool() to create an AIFunction that lists recent voice calls.
1 2 3 4 5 6 7 8 91011121314151617181920
usingMicrosoft.Extensions.AI;usingRetellAI;varretellClient=newRetellAiClient(apiKey:Environment.GetEnvironmentVariable("RETELLAI_API_KEY")!);AIFunctionlistCallsTool=retellClient.AsListCallsTool(limit:20);IChatClientchatClient=/* your chat client */;varoptions=newChatOptions{Tools=[listCallsTool],};varresponse=awaitchatClient.GetResponseAsync("Show me the most recent voice calls.",options);Console.WriteLine(response.Text);
Get Call Details Tool
Use AsGetCallTool() to create an AIFunction that retrieves details of a specific call, including its transcript.
1 2 3 4 5 6 7 8 91011121314151617181920
usingMicrosoft.Extensions.AI;usingRetellAI;varretellClient=newRetellAiClient(apiKey:Environment.GetEnvironmentVariable("RETELLAI_API_KEY")!);AIFunctiongetCallTool=retellClient.AsGetCallTool();IChatClientchatClient=/* your chat client */;varoptions=newChatOptions{Tools=[getCallTool],};varresponse=awaitchatClient.GetResponseAsync("Get the transcript and details for call Jabr9TXYYJHfvl6Syypi88rdAHYHmcq6",options);Console.WriteLine(response.Text);
List Phone Numbers Tool
Use AsListPhoneNumbersTool() to create an AIFunction that lists all configured phone numbers.
1 2 3 4 5 6 7 8 91011121314151617181920
usingMicrosoft.Extensions.AI;usingRetellAI;varretellClient=newRetellAiClient(apiKey:Environment.GetEnvironmentVariable("RETELLAI_API_KEY")!);AIFunctionlistPhoneNumbersTool=retellClient.AsListPhoneNumbersTool();IChatClientchatClient=/* your chat client */;varoptions=newChatOptions{Tools=[listPhoneNumbersTool],};varresponse=awaitchatClient.GetResponseAsync("What phone numbers do I have available?",options);Console.WriteLine(response.Text);
Combining All Tools
You can provide all six tools simultaneously, letting the model decide which to use.
usingMicrosoft.Extensions.AI;usingRetellAI;varretellClient=newRetellAiClient(apiKey:Environment.GetEnvironmentVariable("RETELLAI_API_KEY")!);varoptions=newChatOptions{Tools=[ retellClient.AsListAgentsTool(), retellClient.AsGetAgentTool(), retellClient.AsCreatePhoneCallTool(), retellClient.AsListCallsTool(), retellClient.AsGetCallTool(), retellClient.AsListPhoneNumbersTool(), ],};IChatClientchatClient=/* your chat client */;varmessages=newList<ChatMessage>{new(ChatRole.User,"Check what phone numbers I have, then list my agents. "+"If I have both, make a call from the first number to +12025551234."),};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
AsListAgentsTool()
ListRetellAgents
Lists all voice agents with IDs, names, and status
AsGetAgentTool()
GetRetellAgent
Gets details of a specific agent by ID
AsCreatePhoneCallTool()
CreateRetellPhoneCall
Creates an outbound phone call
AsListCallsTool()
ListRetellCalls
Lists recent voice calls with status and duration
AsGetCallTool()
GetRetellCall
Gets call details including transcript and recording