One of the key advantages of the MEAI AIFunction pattern is that tools from different SDKs can be combined in a single ChatOptions.Tools list. This lets an AI model search the web and translate results in one conversation.
usingMicrosoft.Extensions.AI;usingDeepL;usingExa;vardeepLClient=newDeepLClient(apiKey:Environment.GetEnvironmentVariable("DEEPL_API_KEY")!);varexaClient=newExaClient(apiKey:Environment.GetEnvironmentVariable("EXA_API_KEY")!);IChatClientchatClient=/* your chat client (OpenAI, Anthropic, etc.) */;varoptions=newChatOptions{Tools=[ // Exa search tools exaClient.AsSearchTool(numResults: 3), exaClient.AsGetContentsTool(), // DeepL translation tool deepLClient.AsTranslateTool(), ],};varmessages=newList<ChatMessage>{new(ChatRole.User,"Search for recent news about renewable energy in Germany, then translate the key findings to English."),};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;}
Combine all available tools for a complete multilingual research workflow:
1 2 3 4 5 6 7 8 910111213141516171819202122
varoptions=newChatOptions{Tools=[ // Search (pick one or more) exaClient.AsSearchTool(numResults: 5), exaClient.AsGetContentsTool(), exaClient.AsAnswerTool(), serperClient.AsNewsTool(numResults: 5), // Translation & writing deepLClient.AsTranslateTool(formality: Formality.More), deepLClient.AsRephraseTool( writingStyle: WritingStyle.Business, tone: WritingTone.Confident), ],};varresponse=awaitchatClient.GetResponseAsync("Find the latest EU regulations on AI, translate the key points to Japanese, "+"and rephrase them in a business-friendly tone.",options);