Skip to content

Microsoft.Extensions.AI Integration

Cross-SDK comparison

See the centralized MEAI documentation for feature matrices and comparisons across all tryAGI SDKs.

The Exa SDK provides AIFunction tool wrappers compatible with Microsoft.Extensions.AI. These tools can be used with any IChatClient to give AI models web search, content retrieval, and question answering capabilities.

Installation

1
dotnet add package Exa

Available Tools

Method Tool Name Description
AsSearchTool(numResults) WebSearch Searches the web using Exa AI-powered search
AsGetContentsTool() GetWebContent Retrieves main text content from a URL
AsAnswerTool() AnswerQuestion Answers a question with citations from web sources

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using Exa;
using Microsoft.Extensions.AI;

var exa = new ExaClient(apiKey: Environment.GetEnvironmentVariable("EXA_API_KEY")!);

var options = new ChatOptions
{
    Tools =
    [
        exa.AsSearchTool(numResults: 5),
        exa.AsGetContentsTool(),
        exa.AsAnswerTool(),
    ],
};

IChatClient chatClient = /* your chat client */;

var messages = new List<ChatMessage>
{
    new(ChatRole.User, "What are the latest developments in quantum computing?"),
};

while (true)
{
    var response = await chatClient.GetResponseAsync(messages, options);
    messages.AddRange(response.ToChatMessages());

    if (response.FinishReason == ChatFinishReason.ToolCalls)
    {
        var results = await response.CallToolsAsync(options);
        messages.AddRange(results);
        continue;
    }

    Console.WriteLine(response.Text);
    break;
}

Tool Details

AsSearchTool Parameters

Parameter Type Default Description
numResults int 5 Maximum number of search results to return

AsGetContentsTool

No configurable parameters. Extracts text content from a single URL.

AsAnswerTool

No configurable parameters. Returns a direct answer with citations.