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 Roboflow SDK provides AIFunction tool wrappers from Microsoft.Extensions.AI, allowing you to use Roboflow computer vision inference as tools with any IChatClient.

Installation

1
dotnet add package Roboflow

Object Detection Tool

Use AsObjectDetectionTool() to detect objects in images using a Roboflow model:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
using Roboflow;
using Microsoft.Extensions.AI;

var roboflowClient = new RoboflowClient(apiKey: Environment.GetEnvironmentVariable("ROBOFLOW_API_KEY")!);

var detectionTool = roboflowClient.AsObjectDetectionTool(confidence: 0.5);

// Use with any IChatClient
IChatClient chatClient = /* your chat client */;
var options = new ChatOptions
{
    Tools = [detectionTool],
};

var response = await chatClient.GetResponseAsync(
    "Detect all objects in this image: https://example.com/photo.jpg",
    options);

Classification Tool

Use AsClassificationTool() to classify images:

1
2
3
4
5
6
var classificationTool = roboflowClient.AsClassificationTool(confidence: 0.5);

var options = new ChatOptions
{
    Tools = [classificationTool],
};

OCR Tool

Use AsOcrTool() to extract text from images using the DocTR OCR model:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var ocrTool = roboflowClient.AsOcrTool();

var options = new ChatOptions
{
    Tools = [ocrTool],
};

var response = await chatClient.GetResponseAsync(
    "Extract all text from this document image: https://example.com/document.jpg",
    options);

Instance Segmentation Tool

Use AsInstanceSegmentationTool() to run pixel-level instance segmentation:

1
2
3
4
5
6
var segmentationTool = roboflowClient.AsInstanceSegmentationTool(confidence: 0.5);

var options = new ChatOptions
{
    Tools = [segmentationTool],
};

Combining Tools

All four tools can be used together to give an LLM comprehensive computer vision capabilities:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
var options = new ChatOptions
{
    Tools =
    [
        roboflowClient.AsObjectDetectionTool(confidence: 0.5),
        roboflowClient.AsClassificationTool(confidence: 0.5),
        roboflowClient.AsOcrTool(),
        roboflowClient.AsInstanceSegmentationTool(confidence: 0.5),
    ],
};

Cross-SDK tool combination

Roboflow vision tools can be combined with search tools from Tavily or Exa in a single ChatOptions.Tools list for multimodal research workflows.