Skip to content

Commit 9fed94c

Browse files
authored
examples: add youtube agent example (#666)
* feat(example): add YouTube to blog example with necessary configurations and dependencies * docs: add youtube example
1 parent 5da3a7f commit 9fed94c

File tree

9 files changed

+560
-13
lines changed

9 files changed

+560
-13
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
OPENAI_API_KEY=your_openai_api_key_here
2+
YOUTUBE_MCP_URL=https://server.smithery.ai/@jkawamoto/mcp-youtube-transcript/mcp?api_key=YOUR_API_KEY&profile=YOUR_PROFILE
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
dist
3+
.DS_Store
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<div align="center">
2+
<a href="https://voltagent.dev/">
3+
<img width="1800" alt="435380213-b6253409-8741-462b-a346-834cd18565a9" src="https://github.com/user-attachments/assets/452a03e7-eeda-4394-9ee7-0ffbcf37245c" />
4+
</a>
5+
6+
<br/>
7+
<br/>
8+
9+
<div align="center">
10+
<a href="https://voltagent.dev">Home Page</a> |
11+
<a href="https://voltagent.dev/docs/">Documentation</a> |
12+
<a href="https://github.com/voltagent/voltagent/tree/main/examples">Examples</a> |
13+
<a href="https://s.voltagent.dev/discord">Discord</a> |
14+
<a href="https://voltagent.dev/blog/">Blog</a>
15+
</div>
16+
</div>
17+
18+
<br/>
19+
20+
<div align="center">
21+
<strong>VoltAgent is an open source TypeScript framework for building and orchestrating AI agents.</strong><br>
22+
Escape the limitations of no-code builders and the complexity of starting from scratch.
23+
<br />
24+
<br />
25+
</div>
26+
27+
<div align="center">
28+
29+
[![npm version](https://img.shields.io/npm/v/@voltagent/core.svg)](https://www.npmjs.com/package/@voltagent/core)
30+
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](CODE_OF_CONDUCT.md)
31+
[![Discord](https://img.shields.io/discord/1361559153780195478.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://s.voltagent.dev/discord)
32+
[![Twitter Follow](https://img.shields.io/twitter/follow/voltagent_dev?style=social)](https://twitter.com/voltagent_dev)
33+
34+
</div>
35+
36+
<br/>
37+
38+
<div align="center">
39+
<a href="https://voltagent.dev/">
40+
<img width="896" alt="VoltAgent Schema" src="https://github.com/user-attachments/assets/f0627868-6153-4f63-ba7f-bdfcc5dd603d" />
41+
</a>
42+
43+
</div>
44+
45+
## VoltAgent: Build AI Agents Fast and Flexibly
46+
47+
VoltAgent is an open-source TypeScript framework for creating and managing AI agents. It provides modular components to build, customize, and scale agents with ease. From connecting to APIs and memory management to supporting multiple LLMs, VoltAgent simplifies the process of creating sophisticated AI systems. It enables fast development, maintains clean code, and offers flexibility to switch between models and tools without vendor lock-in.
48+
49+
## Try Example
50+
51+
```bash
52+
npm create voltagent-app@latest -- --example base
53+
```
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "voltagent-example-with-youtube-to-blog",
3+
"author": "",
4+
"dependencies": {
5+
"@ai-sdk/openai": "^2.0.2",
6+
"@voltagent/cli": "^0.1.11",
7+
"@voltagent/core": "^1.1.24",
8+
"@voltagent/libsql": "^1.0.7",
9+
"@voltagent/logger": "^1.0.2",
10+
"@voltagent/server-hono": "^1.0.16",
11+
"ai": "^5.0.12",
12+
"zod": "^3.25.76"
13+
},
14+
"devDependencies": {
15+
"@types/node": "^24.2.1",
16+
"tsx": "^4.19.3",
17+
"typescript": "^5.8.2"
18+
},
19+
"keywords": [
20+
"agent",
21+
"ai",
22+
"voltagent"
23+
],
24+
"license": "MIT",
25+
"private": true,
26+
"scripts": {
27+
"build": "tsc",
28+
"dev": "tsx watch --env-file=.env ./src",
29+
"start": "node dist/index.js",
30+
"volt": "volt"
31+
},
32+
"type": "module"
33+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import { openai } from "@ai-sdk/openai";
2+
import {
3+
Agent,
4+
MCPConfiguration,
5+
Memory,
6+
VoltAgent,
7+
VoltAgentObservability,
8+
} from "@voltagent/core";
9+
import { LibSQLMemoryAdapter, LibSQLObservabilityAdapter } from "@voltagent/libsql";
10+
import { createPinoLogger } from "@voltagent/logger";
11+
import { honoServer } from "@voltagent/server-hono";
12+
13+
// Create logger
14+
const logger = createPinoLogger({
15+
name: "youtube-to-blog",
16+
level: "info",
17+
});
18+
19+
// Create Memory instance with vector support for semantic search and working memory
20+
const memory = new Memory({
21+
storage: new LibSQLMemoryAdapter({
22+
storageLimit: 100, // Keep last 100 messages per conversation
23+
}),
24+
});
25+
26+
// Configure YouTube MCP with SSE transport
27+
(async () => {
28+
const youtubeMcpConfig = new MCPConfiguration({
29+
servers: {
30+
youtube: {
31+
type: "http",
32+
url: process.env.YOUTUBE_MCP_URL || "",
33+
},
34+
},
35+
});
36+
37+
// Get YouTube MCP tools
38+
const youtubeTools = await youtubeMcpConfig.getTools();
39+
40+
// Create TranscriptFetcher subagent
41+
const transcriptFetcherAgent = new Agent({
42+
name: "TranscriptFetcher",
43+
instructions: `You are a transcript fetcher. Your ONLY job is to fetch transcripts from YouTube videos.
44+
45+
IMPORTANT:
46+
- When given a YouTube URL, use your tools to extract the English transcript
47+
- Return ONLY the raw transcript text
48+
- DO NOT write blog posts
49+
- DO NOT format the transcript into articles
50+
- DO NOT add any additional content or commentary
51+
- Just extract and return the transcript as-is`,
52+
model: openai("gpt-4o-mini"),
53+
tools: youtubeTools,
54+
memory,
55+
});
56+
57+
// Create BlogWriter subagent
58+
const blogWriterAgent = new Agent({
59+
name: "BlogWriter",
60+
instructions: `You are an expert blog writer. When given a YouTube transcript, convert it into a well-structured, engaging blog post with:
61+
- A catchy, SEO-friendly title
62+
- An engaging introduction
63+
- Clear sections with subheadings
64+
- Key points and takeaways
65+
- A compelling conclusion
66+
Format the output in Markdown.`,
67+
model: openai("gpt-4o-mini"),
68+
memory,
69+
});
70+
71+
// Create Coordinator supervisor agent
72+
const coordinatorAgent = new Agent({
73+
name: "YouTubeToBlogCoordinator",
74+
instructions: `You are a coordinator that orchestrates the process of converting YouTube videos to blog posts. You DO NOT write the blog post yourself - that is the BlogWriter's job.
75+
76+
IMPORTANT: You MUST follow these steps in EXACT ORDER:
77+
78+
STEP 1: Get the Transcript
79+
- Delegate to the TranscriptFetcher agent with the YouTube URL
80+
- WAIT for the TranscriptFetcher to complete and return the full transcript
81+
- DO NOT proceed to Step 2 until you have the complete transcript
82+
83+
STEP 2: Generate the Blog Post
84+
- After you have the COMPLETE transcript, delegate to the BlogWriter agent
85+
- Pass the ENTIRE transcript to the BlogWriter
86+
- DO NOT write the blog post yourself - let the BlogWriter do it
87+
- WAIT for the BlogWriter to return the complete blog post
88+
89+
STEP 3: Return ONLY the Blog Post
90+
- Return ONLY the blog post content that the BlogWriter created
91+
- DO NOT add any additional commentary, explanations, or meta-information
92+
- Just return the blog post as-is
93+
94+
CRITICAL RULES:
95+
- Complete Step 1 entirely before starting Step 2
96+
- You are ONLY a coordinator - BlogWriter creates the blog post, NOT you
97+
- Your final response should be ONLY the blog post content from BlogWriter`,
98+
model: openai("gpt-4o-mini"),
99+
memory,
100+
subAgents: [transcriptFetcherAgent, blogWriterAgent],
101+
supervisorConfig: {
102+
fullStreamEventForwarding: {
103+
types: ["tool-call", "tool-result"],
104+
},
105+
},
106+
});
107+
108+
new VoltAgent({
109+
agents: {
110+
coordinatorAgent,
111+
transcriptFetcherAgent,
112+
blogWriterAgent,
113+
},
114+
server: honoServer(),
115+
logger,
116+
observability: new VoltAgentObservability({
117+
storage: new LibSQLObservabilityAdapter(),
118+
}),
119+
});
120+
})(); // IGNORE
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "NodeNext",
5+
"moduleResolution": "NodeNext",
6+
"esModuleInterop": true,
7+
"forceConsistentCasingInFileNames": true,
8+
"strict": true,
9+
"outDir": "dist",
10+
"skipLibCheck": true
11+
},
12+
"include": ["src"],
13+
"exclude": ["node_modules", "dist"]
14+
}

pnpm-lock.yaml

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)