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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AzureAICommunity.Agent.Middleware.YouTube" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AzureAICommunity.Agent.Middleware.YouTube" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AzureAICommunity.Agent.Middleware.YouTube" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AzureAICommunity.Agent.Middleware.YouTube --version 1.0.0
                    
#r "nuget: AzureAICommunity.Agent.Middleware.YouTube, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AzureAICommunity.Agent.Middleware.YouTube@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AzureAICommunity.Agent.Middleware.YouTube&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AzureAICommunity.Agent.Middleware.YouTube&version=1.0.0
                    
Install as a Cake Tool

<div align="center">

๐Ÿ“บ AzureAICommunity โ€“ YouTube Video Middleware (.NET)

Search YouTube videos directly from your AI agent pipeline using the YouTube Data API v3.

NuGet Version NuGet Downloads License .NET GitHub Repo GitHub Follow YouTube Channel

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

  1. Go to Google Cloud Console.
  2. Create or select a project and enable the YouTube Data API v3.
  3. Under Credentials, create an API key.
  4. 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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-feature)
  3. Commit your changes (git commit -m 'Add my feature')
  4. Push to the branch (git push origin feature/my-feature)
  5. Open a Pull Request

๐Ÿ‘ค Author

Built and maintained by Vinoth Rajendran.


๐Ÿ“„ License

MIT

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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