AzureAICommunity.Agent.Middleware.YouTube
1.0.0
dotnet add package AzureAICommunity.Agent.Middleware.YouTube --version 1.0.0
NuGet\Install-Package AzureAICommunity.Agent.Middleware.YouTube -Version 1.0.0
<PackageReference Include="AzureAICommunity.Agent.Middleware.YouTube" Version="1.0.0" />
<PackageVersion Include="AzureAICommunity.Agent.Middleware.YouTube" Version="1.0.0" />
<PackageReference Include="AzureAICommunity.Agent.Middleware.YouTube" />
paket add AzureAICommunity.Agent.Middleware.YouTube --version 1.0.0
#r "nuget: AzureAICommunity.Agent.Middleware.YouTube, 1.0.0"
#:package AzureAICommunity.Agent.Middleware.YouTube@1.0.0
#addin nuget:?package=AzureAICommunity.Agent.Middleware.YouTube&version=1.0.0
#tool nuget:?package=AzureAICommunity.Agent.Middleware.YouTube&version=1.0.0
<div align="center">
๐บ AzureAICommunity โ YouTube Video Middleware (.NET)
Search YouTube videos directly from your AI agent pipeline using the YouTube Data API v3.
Let your AI agent find and return YouTube videos โ with a single line of middleware.
Getting Started ยท Configuration ยท Usage ยท How It Works ยท Type Reference ยท Contributing
</div>
Overview
AzureAICommunity.Agent.Middleware.YouTube is a plug-and-play YouTube search layer for AI agent pipelines built on Microsoft.Agents.AI and Microsoft.Extensions.AI. It exposes a SearchVideos AI tool that accepts a natural-language query, a result count, and an offset, and returns matching YouTube watch URLs with titles and descriptions โ all driven by the YouTube Data API v3.
โจ Features
| Feature | |
|---|---|
| ๐ | Natural-language search โ pass any query and get ranked YouTube video results |
| ๐บ | Channel scoping โ optionally restrict results to a specific YouTube channel |
| ๐ | Paged results โ built-in count and offset parameters for client-side paging |
| ๐ค | AI tool integration โ registers as an AITool callable by the agent automatically |
| ๐ | Drop-in middleware โ one .UseYouTubeSearch() call wires everything into the pipeline |
| ๐ชต | Structured logging โ optional ILoggerFactory for trace-level diagnostics |
| ๐ก๏ธ | Input validation โ safe defaults and argument guards throughout the pipeline |
๐ฆ Installation
dotnet add package AzureAICommunity.Agent.Middleware.YouTube
๐ Quick Start
using AzureAICommunity.Agent.Middleware.YouTube;
using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
using OllamaSharp;
var apiKey = Environment.GetEnvironmentVariable("YOUTUBE_API_KEY")!;
YouTubeConfig youTubeConfig = new YouTubeConfig
{
ApiKey = apiKey,
ChannelId = Environment.GetEnvironmentVariable("YOUTUBE_CHANNEL_ID") ?? string.Empty,
MaxResults = 25,
DefaultCount = 5
};
var tools = YouTubeTools.Create(youTubeConfig);
IChatClient ollamaClient = new OllamaApiClient("http://localhost:11434/", "llama3.2");
AIAgent originalAgent = new ChatClientAgent(ollamaClient,
instructions: """
You are a helpful assistant with access to YouTube search.
When the user asks for videos, always call the YouTube search tool.
Always include the full watch URL (https://www.youtube.com/watch?v=...) in the results.
""",
tools: tools);
AIAgent agent = new AIAgentBuilder(originalAgent)
.UseYouTubeSearch()
.Build();
var response = await agent.RunAsync("Find me tutorials on Learn Microsoft AI");
Console.WriteLine(response);
โ๏ธ Configuration
All settings are provided through a YouTubeConfig instance:
| Property | Type | Default | Description |
|---|---|---|---|
ApiKey |
string |
(required) | YouTube Data API v3 key used to authenticate requests |
ChannelId |
string |
"" |
Optional channel ID to restrict results to a specific YouTube channel |
MaxResults |
int |
25 |
Upper bound on the number of results the API may return per request |
DefaultCount |
int |
10 |
Number of videos to return when the caller does not specify a count |
LoggerFactory |
ILoggerFactory? |
null |
Optional logger factory for trace-level diagnostics |
YouTubeConfig config = new YouTubeConfig
{
ApiKey = Environment.GetEnvironmentVariable("YOUTUBE_API_KEY")!,
ChannelId = "UCxxxxxxxxxxxxxx", // Leave empty to search all of YouTube
MaxResults = 25,
DefaultCount = 5,
LoggerFactory = loggerFactory // Optional; pass null to silence logs
};
๐งโ๐ป Usage
Middleware Pipeline
Register the middleware on an AIAgentBuilder so the agent automatically intercepts and handles SearchVideos tool calls:
var tools = YouTubeTools.Create(youTubeConfig);
AIAgent agent = new AIAgentBuilder(
new ChatClientAgent(ollamaClient, instructions: "...", tools: tools))
.UseYouTubeSearch()
.Build();
var response = await agent.RunAsync("Find me tutorials on Learn Microsoft AI");
Console.WriteLine(response);
๐ Getting a YouTube Data API v3 Key
- Go to Google Cloud Console.
- Create or select a project and enable the YouTube Data API v3.
- Under Credentials, create an API key.
- Store the key in an environment variable:
# Windows PowerShell
$env:YOUTUBE_API_KEY = "YOUR_API_KEY_HERE"
# Linux / macOS
export YOUTUBE_API_KEY="YOUR_API_KEY_HERE"
โ ๏ธ Never commit your API key to source control.
๐ค Contributing
Contributions are welcome! Please open an issue to discuss what you'd like to change before submitting a pull request.
๐ Repository: https://github.com/rvinothrajendran/AgentFramework
- Fork the repository
- Create a feature branch (
git checkout -b feature/my-feature) - Commit your changes (
git commit -m 'Add my feature') - Push to the branch (
git push origin feature/my-feature) - Open a Pull Request
๐ค Author
Built and maintained by Vinoth Rajendran.
- ๐ GitHub: github.com/rvinothrajendran โ follow for more projects!
- ๐บ YouTube: youtube.com/@VinothRajendran โ subscribe for tutorials and demos!
๐ License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Google.Apis.YouTube.v3 (>= 1.73.0.4099)
- Microsoft.Agents.AI (>= 1.1.0)
- Microsoft.Extensions.AI (>= 10.4.1)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0 | 184 | 4/18/2026 |