|
| 1 | +# Twelve Labs Integration for Microsoft Agent Framework |
| 2 | + |
| 3 | +Add video intelligence capabilities to your agents using Twelve Labs Pegasus 1.2 APIs. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🎥 **Video Upload & Indexing** - Upload videos from files or URLs |
| 8 | +- 💬 **Interactive Q&A** - Chat with video content using natural language |
| 9 | +- 📝 **Summarization** - Generate comprehensive summaries |
| 10 | +- 📑 **Chapter Generation** - Create chapter markers with timestamps |
| 11 | +- ✨ **Highlight Extraction** - Extract key moments and highlights |
| 12 | +- 📊 **Batch Processing** - Process multiple videos concurrently |
| 13 | + |
| 14 | +## Installation |
| 15 | + |
| 16 | +### From Source (Development) |
| 17 | + |
| 18 | +```bash |
| 19 | +# Clone the repository |
| 20 | +git clone https://github.com/microsoft/agent-framework.git |
| 21 | +cd agent-framework/python/packages/twelvelabs |
| 22 | + |
| 23 | +# Install in development mode |
| 24 | +pip install -e . |
| 25 | +``` |
| 26 | + |
| 27 | +### Requirements |
| 28 | + |
| 29 | +- Python 3.10+ |
| 30 | +- `twelvelabs>=1.0.2` (automatically installed) |
| 31 | +- `agent-framework>=1.0.0b251001` (automatically installed) |
| 32 | +- Valid Twelve Labs API key |
| 33 | + |
| 34 | +## Quick Start |
| 35 | + |
| 36 | +Set your API key from [Twelve Labs](https://twelvelabs.io): |
| 37 | + |
| 38 | +```bash |
| 39 | +export TWELVELABS_API_KEY="your-api-key" |
| 40 | +``` |
| 41 | + |
| 42 | +### Option 1: Add Video Tools to Your Existing Agent |
| 43 | + |
| 44 | +```python |
| 45 | +from agent_framework import ChatAgent |
| 46 | +from agent_framework.openai import OpenAIChatClient |
| 47 | +from agent_framework_twelvelabs import TwelveLabsTools |
| 48 | + |
| 49 | +# Add video capabilities to any agent |
| 50 | +tools = TwelveLabsTools() |
| 51 | +agent = ChatAgent( |
| 52 | + chat_client=OpenAIChatClient(), # or any chat client |
| 53 | + instructions="You are a helpful assistant", |
| 54 | + tools=tools.get_all_tools() # Adds 8 video functions |
| 55 | +) |
| 56 | + |
| 57 | +# Now your agent can process videos |
| 58 | +result = await agent.run("Upload and analyze video.mp4") |
| 59 | +``` |
| 60 | + |
| 61 | +### Option 2: Use Pre-configured Video Agent |
| 62 | + |
| 63 | +```python |
| 64 | +import asyncio |
| 65 | +from agent_framework import ChatMessage |
| 66 | +from agent_framework.openai import OpenAIChatClient |
| 67 | +from agent_framework_twelvelabs import VideoProcessingAgent |
| 68 | + |
| 69 | +async def main(): |
| 70 | + # Create agent |
| 71 | + agent = VideoProcessingAgent( |
| 72 | + chat_client=OpenAIChatClient( |
| 73 | + api_key="your-openai-key", |
| 74 | + model_id="gpt-4" |
| 75 | + ) |
| 76 | + ) |
| 77 | + |
| 78 | + # Build conversation with message history |
| 79 | + messages = [] |
| 80 | + |
| 81 | + # Upload video |
| 82 | + messages.append(ChatMessage(role="user", text="Upload video.mp4")) |
| 83 | + response = await agent.run(messages) |
| 84 | + print(f"Upload: {response}") |
| 85 | + messages.append(ChatMessage(role="assistant", text=str(response))) |
| 86 | + |
| 87 | + # Ask about the video - agent maintains context |
| 88 | + messages.append(ChatMessage(role="user", text="What do you see in this video?")) |
| 89 | + response = await agent.run(messages) |
| 90 | + print(f"Analysis: {response}") |
| 91 | + |
| 92 | + # Generate chapters |
| 93 | + messages.append(ChatMessage(role="user", text="Generate chapter markers for this video")) |
| 94 | + response = await agent.run(messages) |
| 95 | + print(f"Chapters: {response}") |
| 96 | + |
| 97 | +asyncio.run(main()) |
| 98 | +``` |
| 99 | + |
| 100 | +### Option 3: Direct Client Usage (No Agent) |
| 101 | + |
| 102 | +```python |
| 103 | +from agent_framework_twelvelabs import TwelveLabsClient |
| 104 | + |
| 105 | +# For custom workflows without an agent |
| 106 | +client = TwelveLabsClient() |
| 107 | + |
| 108 | +# Upload video |
| 109 | +metadata = await client.upload_video( |
| 110 | + url="https://example.com/video.mp4" # or file_path="video.mp4" |
| 111 | +) |
| 112 | + |
| 113 | +# Chat with video |
| 114 | +response = await client.chat_with_video( |
| 115 | + video_id=metadata.video_id, |
| 116 | + query="What products are shown?" |
| 117 | +) |
| 118 | + |
| 119 | +# Generate summary |
| 120 | +summary = await client.summarize_video(video_id=metadata.video_id) |
| 121 | + |
| 122 | +# Generate chapters |
| 123 | +chapters = await client.generate_chapters(video_id=metadata.video_id) |
| 124 | + |
| 125 | +# Generate highlights |
| 126 | +highlights = await client.generate_highlights(video_id=metadata.video_id) |
| 127 | +``` |
| 128 | + |
| 129 | +## Configuration |
| 130 | + |
| 131 | +```bash |
| 132 | +export TWELVELABS_API_KEY="your-api-key" |
| 133 | +``` |
| 134 | + |
| 135 | +Additional configuration options are available through environment variables or `TwelveLabsSettings`. |
| 136 | + |
| 137 | +## Available Tools |
| 138 | + |
| 139 | +These 8 AI functions are added to your agent when using TwelveLabsTools: |
| 140 | + |
| 141 | +- `upload_video` - Upload and index videos from file path or URL |
| 142 | +- `chat_with_video` - Q&A with video content |
| 143 | +- `summarize_video` - Generate comprehensive video summaries |
| 144 | +- `generate_chapters` - Create chapter markers with timestamps |
| 145 | +- `generate_highlights` - Extract key highlights and moments |
| 146 | +- `get_video_info` - Get video metadata |
| 147 | +- `delete_video` - Remove indexed videos |
| 148 | +- `batch_process_videos` - Process multiple videos concurrently |
| 149 | + |
| 150 | +The agent can automatically call these tools based on user requests. |
| 151 | + |
| 152 | +## Video Requirements |
| 153 | + |
| 154 | +### Supported Formats |
| 155 | +- All FFmpeg-compatible video and audio codecs |
| 156 | +- Common formats: MP4, AVI, MOV, MKV, WebM |
| 157 | + |
| 158 | +### Technical Specifications |
| 159 | +- **Resolution**: 360x360 minimum, 3840x2160 maximum |
| 160 | +- **Aspect Ratios**: 1:1, 4:3, 4:5, 5:4, 16:9, 9:16, 17:9 |
| 161 | +- **Duration**: 4 seconds to 60 minutes (Pegasus 1.2) |
| 162 | +- **File Size**: Up to 5GB (configurable) |
0 commit comments