Skip to content

Microsoft.Extensions.AI Integration

The Braintrust SDK provides AIFunction tools that can be used with any Microsoft.Extensions.AI.IChatClient to give AI agents access to Braintrust's prompt management and experiment tracking capabilities.

Available Tools

Method Tool Name Description
AsListProjectsTool() ListProjects Lists available projects
AsListPromptsTool() ListPrompts Lists prompt templates, optionally filtered by project
AsGetPromptTool() GetPrompt Retrieves a specific prompt by slug
AsListExperimentsTool() ListExperiments Lists experiments, optionally filtered by project

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
using Braintrust;
using Microsoft.Extensions.AI;

// Create the Braintrust client
var braintrust = new BraintrustClient(apiKey);

// Create tools
var tools = new AIFunction[]
{
    braintrust.AsListProjectsTool(),
    braintrust.AsListPromptsTool(),
    braintrust.AsGetPromptTool(),
    braintrust.AsListExperimentsTool(),
};

// Use with any IChatClient (OpenAI, Anthropic, etc.)
IChatClient chatClient = /* your chat client */;

var response = await chatClient.GetResponseAsync(
    "List all my Braintrust projects and their prompts.",
    new ChatOptions { Tools = tools });

Tool Details

ListProjects

Returns a JSON array of projects with id and name fields.

1
var tool = client.AsListProjectsTool(limit: 10);

ListPrompts

Returns a JSON array of prompts with id, name, slug, description, and tags fields. Accepts an optional projectName parameter to filter by project.

1
var tool = client.AsListPromptsTool(limit: 20);

GetPrompt

Returns a single prompt's details by slug, including id, name, slug, description, tags, function_type, and created date.

1
var tool = client.AsGetPromptTool();

ListExperiments

Returns a JSON array of experiments with id, name, and created fields. Accepts an optional projectName parameter to filter by project.

1
var tool = client.AsListExperimentsTool(limit: 20);