ambivo-agents 1.0.1__py3-none-any.whl → 1.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,1090 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: ambivo-agents
3
- Version: 1.0.1
4
- Summary: Multi-Agent AI System for automation
5
- Home-page: https://github.com/ambivo-corp/ambivo-agents
6
- Author: Hemant Gosain 'Sunny'
7
- Author-email: Hemant Gosain 'Sunny' <sgosain@ambivo.com>
8
- License: MIT
9
- Project-URL: Homepage, https://github.com/ambivo-corp/ambivo-agents
10
- Project-URL: Repository, https://github.com/ambivo-corp/ambivo-agents
11
- Project-URL: Issues, https://github.com/ambivo-corp/ambivo-agents/issues
12
- Project-URL: Documentation, https://github.com/ambivo-corp/ambivo-agents/blob/main/README.md
13
- Project-URL: Company, https://www.ambivo.com
14
- Classifier: Development Status :: 4 - Beta
15
- Classifier: Intended Audience :: Developers
16
- Classifier: License :: OSI Approved :: MIT License
17
- Classifier: Operating System :: OS Independent
18
- Classifier: Programming Language :: Python :: 3
19
- Classifier: Programming Language :: Python :: 3.11
20
- Classifier: Programming Language :: Python :: 3.12
21
- Classifier: Programming Language :: Python :: 3.13
22
- Requires-Python: >=3.11
23
- Description-Content-Type: text/markdown
24
- License-File: LICENSE
25
- Requires-Dist: redis>=6.2.0
26
- Requires-Dist: redis[asyncio]
27
- Requires-Dist: docker>=6.0.0
28
- Requires-Dist: asyncio-mqtt>=0.11.0
29
- Requires-Dist: cachetools
30
- Requires-Dist: lz4
31
- Requires-Dist: requests>=2.32.4
32
- Requires-Dist: click>=8.2.1
33
- Requires-Dist: openai>=1.84.0
34
- Requires-Dist: langchain>=0.3.25
35
- Requires-Dist: langchain-community>=0.3.24
36
- Requires-Dist: langchain-core>=0.3.63
37
- Requires-Dist: langchain-openai>=0.3.19
38
- Requires-Dist: langchainhub>=0.1.21
39
- Requires-Dist: langchain-text-splitters>=0.3.8
40
- Requires-Dist: langchain-anthropic>=0.3.15
41
- Requires-Dist: langchain-aws
42
- Requires-Dist: langchain-voyageai
43
- Requires-Dist: huggingface-hub
44
- Requires-Dist: llama-index-core
45
- Requires-Dist: llama-index-embeddings-langchain
46
- Requires-Dist: llama-index-llms-langchain
47
- Requires-Dist: llama-index-llms-openai
48
- Requires-Dist: llama-index-vector-stores-qdrant
49
- Requires-Dist: llama-index-readers-smart-pdf-loader
50
- Requires-Dist: pydantic>=2.11.7
51
- Requires-Dist: boto3>=1.38.42
52
- Requires-Dist: python-dotenv>=1.1.1
53
- Requires-Dist: pyyaml>=6.0.2
54
- Requires-Dist: psutil>=7.0.0
55
- Requires-Dist: qdrant-client
56
- Requires-Dist: numexpr
57
- Requires-Dist: pytest>=8.4.1
58
- Requires-Dist: pytest-asyncio>=1.0.0
59
- Requires-Dist: black>=25.1.0
60
- Requires-Dist: isort>=6.0.1
61
- Requires-Dist: unstructured
62
- Requires-Dist: langchain-unstructured
63
- Provides-Extra: test
64
- Requires-Dist: pytest>=8.4.1; extra == "test"
65
- Requires-Dist: pytest-asyncio>=1.0.0; extra == "test"
66
- Requires-Dist: pytest-timeout>=2.1.0; extra == "test"
67
- Provides-Extra: dev
68
- Requires-Dist: pytest>=8.4.1; extra == "dev"
69
- Requires-Dist: pytest-asyncio>=1.0.0; extra == "dev"
70
- Requires-Dist: black>=25.1.0; extra == "dev"
71
- Requires-Dist: isort>=6.0.1; extra == "dev"
72
- Requires-Dist: pytest-timeout>=2.1.0; extra == "dev"
73
- Provides-Extra: all
74
- Requires-Dist: pytest>=8.4.1; extra == "all"
75
- Requires-Dist: pytest-asyncio>=1.0.0; extra == "all"
76
- Requires-Dist: black>=25.1.0; extra == "all"
77
- Requires-Dist: isort>=6.0.1; extra == "all"
78
- Requires-Dist: pytest-timeout>=2.1.0; extra == "all"
79
- Requires-Dist: beautifulsoup4>=4.13.4; extra == "all"
80
- Requires-Dist: playwright>=1.40.0; extra == "all"
81
- Requires-Dist: pytubefix>=6.0.0; extra == "all"
82
- Requires-Dist: anthropic>=0.55.0; extra == "all"
83
- Dynamic: author
84
- Dynamic: home-page
85
- Dynamic: license-file
86
- Dynamic: requires-python
87
-
88
- # Ambivo Agents - Multi-Agent AI System
89
-
90
- A minimalistic toolkit for AI-powered automation including media processing, knowledge base operations, web scraping, YouTube downloads, and more.
91
-
92
- ## ⚠️ Alpha Release Disclaimer
93
-
94
- **This library is currently in alpha stage.** While functional, it may contain bugs, undergo breaking changes, and lack complete documentation. **Developers should thoroughly evaluate and test the library before considering it for production use.** Use in production environments is at your own risk.
95
-
96
- For production scenarios, we recommend:
97
- - Extensive testing in your specific environment
98
- - Implementing proper error handling and monitoring
99
- - Having rollback plans in place
100
- - Staying updated with releases for critical fixes
101
-
102
- **Development Roadmap**: We are actively working toward a stable 1.0 release. Breaking changes may occur during the alpha phase as we refine the API and improve stability.
103
-
104
- ## Table of Contents
105
-
106
- - [Quick Start](#quick-start)
107
- - [Simple ModeratorAgent Example](#simple-moderatoragent-example)
108
- - [Agent Creation](#agent-creation)
109
- - [Features](#features)
110
- - [Available Agents](#available-agents)
111
- - [Prerequisites](#prerequisites)
112
- - [Installation](#installation)
113
- - [Configuration](#configuration)
114
- - [Usage Examples](#usage-examples)
115
- - [Command Line Interface](#command-line-interface)
116
- - [Architecture](#architecture)
117
- - [Docker Setup](#docker-setup)
118
- - [Troubleshooting](#troubleshooting)
119
- - [Security Considerations](#security-considerations)
120
- - [Contributing](#contributing)
121
- - [License](#license)
122
- - [Author](#author)
123
- - [Support](#support)
124
-
125
- ## Quick Start
126
-
127
- ### Simple ModeratorAgent Example
128
-
129
- The **ModeratorAgent** is the easiest way to get started. It automatically routes your queries to the right specialized agents:
130
-
131
- ```python
132
- from ambivo_agents import ModeratorAgent
133
- import asyncio
134
-
135
- async def main():
136
- # Create the moderator (one agent to rule them all!)
137
- moderator, context = ModeratorAgent.create(user_id="john")
138
-
139
- print(f"✅ Moderator: {moderator.agent_id}")
140
- print(f"📋 Session: {context.session_id}")
141
-
142
- # Just chat! The moderator routes automatically:
143
-
144
- # This will go to YouTubeDownloadAgent
145
- response1 = await moderator.chat("Download audio from https://youtube.com/watch?v=dQw4w9WgXcQ")
146
- print(f"🎵 {response1}")
147
-
148
- # This will go to WebSearchAgent
149
- response2 = await moderator.chat("Search for latest AI trends")
150
- print(f"🔍 {response2}")
151
-
152
- # This will go to MediaEditorAgent
153
- response3 = await moderator.chat("Extract audio from video.mp4 as MP3")
154
- print(f"🎬 {response3}")
155
-
156
- # This will go to AssistantAgent
157
- response4 = await moderator.chat("What is machine learning?")
158
- print(f"💬 {response4}")
159
-
160
- # Check what agents are available
161
- status = await moderator.get_agent_status()
162
- print(f"🤖 Available agents: {list(status['active_agents'].keys())}")
163
-
164
- # Cleanup when done
165
- await moderator.cleanup_session()
166
-
167
- # Run it
168
- asyncio.run(main())
169
- ```
170
-
171
- **That's it!** The ModeratorAgent automatically:
172
- - ✅ **Routes** your queries to the right specialist
173
- - ✅ **Maintains** conversation context
174
- - ✅ **Manages** all the underlying agents
175
- - ✅ **Handles** configuration and setup
176
-
177
- ### Even Simpler - Command Line
178
-
179
- ```bash
180
- # Install and run
181
- pip install ambivo-agents
182
-
183
- # Interactive mode (auto-routing)
184
- ambivo-agents
185
-
186
- # Or single commands
187
- ambivo-agents -q "Download audio from https://youtube.com/watch?v=example"
188
- ambivo-agents -q "Search for Python tutorials"
189
- ambivo-agents -q "Extract audio from video.mp4"
190
- ```
191
-
192
- ## Simple ModeratorAgent Example
193
-
194
-
195
-
196
- ### Basic ModeratorAgent Usage
197
-
198
- ```python
199
- from ambivo_agents import ModeratorAgent
200
- import asyncio
201
-
202
- async def simple_example():
203
- # Create moderator with auto-configuration
204
- moderator, context = ModeratorAgent.create(user_id="alice")
205
-
206
- print(f"🚀 Session {context.session_id} started")
207
-
208
- # The moderator routes these automatically:
209
- tasks = [
210
- "Download https://youtube.com/watch?v=example", # → YouTube Agent
211
- "Search for latest Python frameworks", # → Web Search Agent
212
- "Convert video.mp4 to audio", # → Media Editor Agent
213
- "What's the capital of France?", # → Assistant Agent
214
- "Scrape https://example.com for content", # → Web Scraper Agent
215
- ]
216
-
217
- for task in tasks:
218
- print(f"\n👤 User: {task}")
219
- response = await moderator.chat(task)
220
- print(f"🤖 Bot: {response[:100]}...") # First 100 chars
221
-
222
- # Check routing info
223
- status = await moderator.get_agent_status()
224
- print(f"\n📊 Processed via {status['total_agents']} specialized agents")
225
-
226
- await moderator.cleanup_session()
227
-
228
- asyncio.run(simple_example())
229
- ```
230
-
231
- ### Context-Aware Conversations
232
-
233
- The ModeratorAgent maintains conversation context:
234
-
235
- ```python
236
- async def context_example():
237
- moderator, context = ModeratorAgent.create(user_id="bob")
238
-
239
- # Initial request
240
- response1 = await moderator.chat("Download audio from https://youtube.com/watch?v=example")
241
- print(response1)
242
-
243
- # Follow-up (moderator remembers the YouTube URL)
244
- response2 = await moderator.chat("Actually, download the video instead")
245
- print(response2)
246
-
247
- # Another follow-up (still remembers context)
248
- response3 = await moderator.chat("Get information about that video")
249
- print(response3)
250
-
251
- await moderator.cleanup_session()
252
- ```
253
-
254
- ### Custom Agent Configuration using enabled_agents
255
-
256
- ```python
257
- async def custom_moderator():
258
- # Enable only specific agents
259
- moderator, context = ModeratorAgent.create(
260
- user_id="charlie",
261
- enabled_agents=['youtube_download', 'web_search', 'assistant']
262
- )
263
-
264
- # Only these agents will be available for routing
265
- status = await moderator.get_agent_status()
266
- print(f"Enabled: {list(status['active_agents'].keys())}")
267
-
268
- await moderator.cleanup_session()
269
- ```
270
-
271
- ### Integration with Existing Code
272
-
273
- ```python
274
- class ChatBot:
275
- def __init__(self):
276
- self.moderator = None
277
- self.context = None
278
-
279
- async def start_session(self, user_id: str):
280
- self.moderator, self.context = ModeratorAgent.create(user_id=user_id)
281
- return self.context.session_id
282
-
283
- async def process_message(self, message: str) -> str:
284
- if not self.moderator:
285
- raise ValueError("Session not started")
286
-
287
- return await self.moderator.chat(message)
288
-
289
- async def end_session(self):
290
- if self.moderator:
291
- await self.moderator.cleanup_session()
292
-
293
- # Usage
294
- bot = ChatBot()
295
- session_id = await bot.start_session("user123")
296
- response = await bot.process_message("Download audio from YouTube")
297
- await bot.end_session()
298
- ```
299
-
300
- ## Agent Creation
301
-
302
- ### ModeratorAgent
303
-
304
-
305
-
306
- ```python
307
- from ambivo_agents import ModeratorAgent
308
-
309
- # Create moderator with auto-routing to specialized agents
310
- moderator, context = ModeratorAgent.create(user_id="john")
311
- print(f"Session: {context.session_id}")
312
-
313
- # Just chat - moderator handles the routing!
314
- result = await moderator.chat("Download audio from https://youtube.com/watch?v=example")
315
- print(result)
316
-
317
- # Cleanup when done
318
- await moderator.cleanup_session()
319
- ```
320
-
321
- **When to use ModeratorAgent:**
322
- - ✅ **Most applications** (recommended default)
323
- - ✅ **Multi-purpose chatbots** and assistants
324
- - ✅ **Intelligent routing** between different capabilities
325
- - ✅ **Context-aware** conversations
326
- - ✅ **Simplified development** - one agent does everything
327
-
328
- ### Direct Agent Creation
329
-
330
- Use direct creation for specific, single-purpose applications:
331
-
332
- ```python
333
- from ambivo_agents import YouTubeDownloadAgent
334
-
335
- # Create agent with explicit context
336
- agent, context = YouTubeDownloadAgent.create(user_id="john")
337
- print(f"Session: {context.session_id}")
338
-
339
- # Use agent directly for specific task
340
- result = await agent._download_youtube_audio("https://youtube.com/watch?v=example")
341
-
342
- # Cleanup when done
343
- await agent.cleanup_session()
344
- ```
345
-
346
- **When to use Direct Creation:**
347
- - ✅ **Single-purpose** applications (only YouTube, only search, etc.)
348
- - ✅ **Specific workflows** with known agent requirements
349
- - ✅ **Performance-critical** applications (no routing overhead)
350
- - ✅ **Custom integrations** with existing systems
351
-
352
- ### Service-Based Creation
353
-
354
- Use the service method for production multi-user systems:
355
-
356
- ```python
357
- from ambivo_agents.services import create_agent_service
358
-
359
- service = create_agent_service()
360
- session_id = service.create_session()
361
-
362
- # Service automatically routes to the appropriate agent
363
- result = await service.process_message(
364
- message="download audio from youtube.com/watch?v=example",
365
- session_id=session_id,
366
- user_id="user123"
367
- )
368
- ```
369
-
370
- **When to use Service:**
371
- - ✅ **Production systems** with multiple users - manage sessions
372
- - ✅ **Session management** across users
373
- - ✅ **Scalable architectures** with load balancing
374
- - ✅ **Advanced monitoring** and analytics
375
-
376
- ## Features
377
-
378
- ### Core Capabilities
379
- - **🤖 ModeratorAgent**: Intelligent multi-agent orchestrator with automatic routing
380
- - **🔄 Smart Routing**: Automatically routes queries to the most appropriate specialized agent
381
- - **🧠 Context Memory**: Maintains conversation history and context across interactions
382
- - **🐳 Docker Integration**: Secure, isolated execution environment for code and media processing
383
- - **📦 Redis Memory**: Persistent conversation memory with compression and caching
384
- - **🔀 Multi-Provider LLM**: Automatic failover between OpenAI, Anthropic, and AWS Bedrock
385
- - **⚙️ Configuration-Driven**: All features controlled via `agent_config.yaml`
386
-
387
- ## Available Agents
388
-
389
- ### 🎛️ **ModeratorAgent**
390
- - **Intelligent orchestrator** that routes to specialized agents
391
- - **Context-aware** multi-turn conversations
392
- - **Automatic agent selection** based on query analysis
393
- - **Session management** and cleanup
394
-
395
- ### 🤖 Assistant Agent
396
- - General purpose conversational AI
397
- - Context-aware responses
398
- - Multi-turn conversations
399
-
400
- ### 💻 Code Executor Agent
401
- - Secure Python and Bash execution in Docker
402
- - Isolated environment with resource limits
403
- - Real-time output streaming
404
-
405
- ### 🔍 Web Search Agent
406
- - Multi-provider search (Brave, AVES APIs)
407
- - Academic search capabilities
408
- - Automatic provider failover
409
-
410
- ### 🕷️ Web Scraper Agent
411
- - Proxy-enabled scraping (ScraperAPI compatible)
412
- - Playwright and requests-based scraping
413
- - Batch URL processing with rate limiting
414
-
415
- ### 📚 Knowledge Base Agent
416
- - Document ingestion (PDF, DOCX, TXT, web URLs)
417
- - Vector similarity search with Qdrant
418
- - Semantic question answering
419
-
420
- ### 🎥 Media Editor Agent
421
- - Audio/video processing with FFmpeg
422
- - Format conversion, resizing, trimming
423
- - Audio extraction and volume adjustment
424
-
425
- ### 🎬 YouTube Download Agent
426
- - Download videos and audio from YouTube
427
- - Docker-based execution with pytubefix
428
- - Automatic title sanitization and metadata extraction
429
-
430
- ## Prerequisites
431
-
432
- ### Required
433
- - **Python 3.11+**
434
- - **Docker** (for code execution, media processing, YouTube downloads)
435
- - **Redis** (Cloud Redis recommended: Redis Cloud)
436
-
437
- ### Recommended Cloud Services
438
- - **Redis Cloud**
439
- - **Qdrant Cloud** for knowledge base operations
440
- - **AWS Bedrock**, **OpenAI**, or **Anthropic** for LLM services
441
-
442
- ### API Keys (Optional - based on enabled features)
443
- - **OpenAI API Key** (for GPT models)
444
- - **Anthropic API Key** (for Claude models)
445
- - **AWS Credentials** (for Bedrock models)
446
- - **Brave Search API Key** (for web search)
447
- - **AVES API Key** (for web search)
448
- - **ScraperAPI/Proxy credentials** (for web scraping)
449
- - **Qdrant Cloud API Key** (for Knowledge Base operations)
450
- - **Redis Cloud credentials** (for memory management)
451
-
452
- ## Installation
453
-
454
- ### 1. Install Dependencies
455
- ```bash
456
-
457
- # Install requirements
458
- pip install -r requirements.txt
459
- ```
460
-
461
- ### 2. Setup Docker Images
462
- ```bash
463
- # Pull the multi-purpose container image
464
- docker pull sgosain/amb-ubuntu-python-public-pod
465
- ```
466
-
467
- ### 3. Setup Redis
468
-
469
- **Recommended: Cloud Redis **
470
- ```yaml
471
- # In agent_config.yaml
472
- redis:
473
- host: "your-redis-cloud-endpoint.redis.cloud"
474
- port: 6379
475
- password: "your-redis-password"
476
- ```
477
-
478
- **Alternative: Local Redis**
479
- ```bash
480
- # Using Docker (for development)
481
- docker run -d --name redis -p 6379:6379 redis:latest
482
-
483
- # Or install locally
484
- # sudo apt-get install redis-server # Ubuntu/Debian
485
- # brew install redis # macOS
486
- ```
487
-
488
- ## Configuration
489
-
490
- Create `agent_config.yaml` in your project root:
491
-
492
- ```yaml
493
- # Redis Configuration (Required)
494
- redis:
495
- host: "your-redis-cloud-endpoint.redis.cloud" # Recommended: Cloud Redis
496
- port: 6379
497
- db: 0
498
- password: "your-redis-password" # Required for cloud
499
- # Alternative local: host: "localhost", password: null
500
-
501
- # LLM Configuration (Required - at least one provider)
502
- llm:
503
- preferred_provider: "openai" # openai, anthropic, or bedrock
504
- temperature: 0.7
505
-
506
- # Provider API Keys
507
- openai_api_key: "your-openai-key"
508
- anthropic_api_key: "your-anthropic-key"
509
-
510
- # AWS Bedrock (optional)
511
- aws_access_key_id: "your-aws-key"
512
- aws_secret_access_key: "your-aws-secret"
513
- aws_region: "us-east-1"
514
-
515
- # Agent Capabilities (Enable/disable features)
516
- agent_capabilities:
517
- enable_knowledge_base: true
518
- enable_web_search: true
519
- enable_code_execution: true
520
- enable_file_processing: true
521
- enable_web_ingestion: true
522
- enable_api_calls: true
523
- enable_web_scraping: true
524
- enable_proxy_mode: true
525
- enable_media_editor: true
526
- enable_youtube_download: true
527
-
528
- # used by the ModeratorAgent to determine which agents to enable if not explicitly specified in code
529
- # by default all agents are enabled
530
- moderator:
531
- default_enabled_agents:
532
- - knowledge_base
533
- - web_search
534
- - assistant
535
- - media_editor
536
- - youtube_download
537
- - code_executor # Enable only if needed for security
538
- - web_scraper # Enable only if needed
539
-
540
- # Web Search Configuration (if enabled)
541
- web_search:
542
- brave_api_key: "your-brave-api-key"
543
- avesapi_api_key: "your-aves-api-key"
544
-
545
- # Web Scraping Configuration (if enabled)
546
- web_scraping:
547
- proxy_enabled: true
548
- proxy_config:
549
- http_proxy: "http://scraperapi:your-key@proxy-server.scraperapi.com:8001"
550
- default_headers:
551
- User-Agent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
552
- timeout: 60
553
- max_links_per_page: 100
554
-
555
- # Knowledge Base Configuration (if enabled)
556
- knowledge_base:
557
- qdrant_url: "https://your-cluster.qdrant.tech" # Recommended: Qdrant Cloud
558
- qdrant_api_key: "your-qdrant-api-key" # Required for cloud
559
- # Alternative local: "http://localhost:6333"
560
- chunk_size: 1024
561
- chunk_overlap: 20
562
- similarity_top_k: 5
563
-
564
- # Media Editor Configuration (if enabled)
565
- media_editor:
566
- docker_image: "sgosain/amb-ubuntu-python-public-pod"
567
- input_dir: "./media_input"
568
- output_dir: "./media_output"
569
- timeout: 300
570
- memory_limit: "2g"
571
-
572
- # YouTube Download Configuration (if enabled)
573
- youtube_download:
574
- docker_image: "sgosain/amb-ubuntu-python-public-pod"
575
- download_dir: "./youtube_downloads"
576
- timeout: 600
577
- memory_limit: "1g"
578
- default_audio_only: true
579
-
580
- # Docker Configuration
581
- docker:
582
- timeout: 60
583
- memory_limit: "512m"
584
- images: ["sgosain/amb-ubuntu-python-public-pod"]
585
-
586
- # Service Configuration
587
- service:
588
- max_sessions: 100
589
- session_timeout: 3600
590
- log_level: "INFO"
591
- log_to_file: false
592
-
593
- # Memory Management
594
- memory_management:
595
- compression:
596
- enabled: true
597
- algorithm: "lz4"
598
- cache:
599
- enabled: true
600
- max_size: 1000
601
- ttl_seconds: 300
602
- ```
603
-
604
- ## Project Structure
605
-
606
- ```
607
- ambivo_agents/
608
- ├── agents/ # Agent implementations
609
- │ ├── assistant.py
610
- │ ├── code_executor.py
611
- │ ├── knowledge_base.py
612
- │ ├── media_editor.py
613
- │ ├── moderator.py # 🎛️ ModeratorAgent (main orchestrator)
614
- │ ├── simple_web_search.py
615
- │ ├── web_scraper.py
616
- │ ├── web_search.py
617
- │ └── youtube_download.py
618
- ├── config/ # Configuration management
619
- ├── core/ # Core functionality
620
- │ ├── base.py
621
- │ ├── llm.py
622
- │ └── memory.py
623
- ├── executors/ # Execution environments
624
- ├── services/ # Service layer
625
- ├── __init__.py # Package initialization
626
- └── cli.py # Command line interface
627
- ```
628
-
629
- ## Usage Examples
630
-
631
- ### 🎛️ ModeratorAgent Examples
632
-
633
- #### Basic Usage with Auto-Routing
634
- ```python
635
- from ambivo_agents import ModeratorAgent
636
- import asyncio
637
-
638
- async def basic_moderator():
639
- # Create the moderator
640
- moderator, context = ModeratorAgent.create(user_id="demo_user")
641
-
642
- print(f"✅ Session: {context.session_id}")
643
-
644
- # Auto-routing examples
645
- examples = [
646
- "Download audio from https://youtube.com/watch?v=dQw4w9WgXcQ",
647
- "Search for latest artificial intelligence news",
648
- "Extract audio from video.mp4 as high quality MP3",
649
- "What is machine learning and how does it work?",
650
- "Scrape https://example.com for content"
651
- ]
652
-
653
- for query in examples:
654
- print(f"\n👤 User: {query}")
655
- response = await moderator.chat(query)
656
- print(f"🤖 Bot: {response[:150]}...")
657
-
658
- # Check which agents handled the requests
659
- status = await moderator.get_agent_status()
660
- print(f"\n📊 Used {status['total_agents']} specialized agents")
661
- for agent_type in status['active_agents']:
662
- print(f" • {agent_type}")
663
-
664
- await moderator.cleanup_session()
665
-
666
- asyncio.run(basic_moderator())
667
- ```
668
-
669
- #### Context-Aware Conversations
670
- ```python
671
- async def context_conversation():
672
- moderator, context = ModeratorAgent.create(user_id="context_demo")
673
-
674
- # Initial request
675
- response1 = await moderator.chat("Download audio from https://youtube.com/watch?v=example")
676
- print(f"🎵 {response1}")
677
-
678
- # Follow-up using context (moderator remembers the YouTube URL)
679
- response2 = await moderator.chat("Actually, download the video instead of just audio")
680
- print(f"🎬 {response2}")
681
-
682
- # Another follow-up
683
- response3 = await moderator.chat("Get information about that video")
684
- print(f"📊 {response3}")
685
-
686
- await moderator.cleanup_session()
687
- ```
688
-
689
- #### Custom Agent Selection
690
- ```python
691
- async def custom_agents():
692
- # Only enable specific capabilities
693
- moderator, context = ModeratorAgent.create(
694
- user_id="custom_user",
695
- enabled_agents=['youtube_download', 'web_search', 'assistant']
696
- )
697
-
698
- # Only these agents will be available
699
- status = await moderator.get_agent_status()
700
- print(f"Available agents: {list(status['active_agents'].keys())}")
701
-
702
- response = await moderator.chat("Download https://youtube.com/watch?v=example")
703
- print(response)
704
-
705
- await moderator.cleanup_session()
706
- ```
707
-
708
- ### 🎬 YouTube Downloads
709
- ```python
710
- from ambivo_agents import YouTubeDownloadAgent
711
-
712
- async def download_youtube():
713
- agent, context = YouTubeDownloadAgent.create(user_id="media_user")
714
-
715
- # Download audio
716
- result = await agent._download_youtube_audio(
717
- "https://youtube.com/watch?v=example"
718
- )
719
-
720
- if result['success']:
721
- print(f"✅ Audio downloaded: {result['filename']}")
722
- print(f"📍 Path: {result['file_path']}")
723
- print(f"📊 Size: {result['file_size_bytes']:,} bytes")
724
-
725
- # Get video info
726
- info = await agent._get_youtube_info(
727
- "https://youtube.com/watch?v=example"
728
- )
729
-
730
- if info['success']:
731
- video_info = info['video_info']
732
- print(f"📹 Title: {video_info['title']}")
733
- print(f"⏱️ Duration: {video_info['duration']} seconds")
734
-
735
- await agent.cleanup_session()
736
- ```
737
-
738
- ### 📚 Knowledge Base Operations
739
- ```python
740
- from ambivo_agents import KnowledgeBaseAgent
741
-
742
- async def knowledge_base_demo():
743
- agent, context = KnowledgeBaseAgent.create(
744
- user_id="kb_user",
745
- session_metadata={"project": "company_docs"}
746
- )
747
-
748
- print(f"Session: {context.session_id}")
749
-
750
- # Ingest document
751
- result = await agent._ingest_document(
752
- kb_name="company_kb",
753
- doc_path="/path/to/document.pdf",
754
- custom_meta={"department": "HR", "type": "policy"}
755
- )
756
-
757
- if result['success']:
758
- print("✅ Document ingested")
759
-
760
- # Query the knowledge base
761
- answer = await agent._query_knowledge_base(
762
- kb_name="company_kb",
763
- query="What is the remote work policy?"
764
- )
765
-
766
- if answer['success']:
767
- print(f"📝 Answer: {answer['answer']}")
768
-
769
- # View conversation history
770
- history = await agent.get_conversation_history(limit=5)
771
- print(f"💬 Messages in session: {len(history)}")
772
-
773
- await agent.cleanup_session()
774
- ```
775
-
776
- ### 🔍 Web Search
777
- ```python
778
- from ambivo_agents import WebSearchAgent
779
-
780
- async def search_demo():
781
- agent, context = WebSearchAgent.create(user_id="search_user")
782
-
783
- # Search the web
784
- results = await agent._search_web(
785
- "artificial intelligence trends 2024",
786
- max_results=5
787
- )
788
-
789
- if results['success']:
790
- print(f"🔍 Found {len(results['results'])} results")
791
-
792
- for i, result in enumerate(results['results'], 1):
793
- print(f"{i}. {result['title']}")
794
- print(f" {result['url']}")
795
- print(f" {result['snippet'][:100]}...")
796
-
797
- await agent.cleanup_session()
798
- ```
799
-
800
- ### 🎵 Media Processing
801
- ```python
802
- from ambivo_agents import MediaEditorAgent
803
-
804
- async def media_demo():
805
- agent, context = MediaEditorAgent.create(user_id="media_user")
806
-
807
- # Extract audio from video
808
- result = await agent._extract_audio_from_video(
809
- input_video="/path/to/video.mp4",
810
- output_format="mp3",
811
- audio_quality="high"
812
- )
813
-
814
- if result['success']:
815
- print(f"✅ Audio extracted: {result['output_file']}")
816
-
817
- await agent.cleanup_session()
818
- ```
819
-
820
- ### Context Manager Pattern (Auto-Cleanup)
821
-
822
- ```python
823
- from ambivo_agents import ModeratorAgent, AgentSession
824
- import asyncio
825
-
826
- async def main():
827
- # Auto-cleanup with context manager
828
- async with AgentSession(ModeratorAgent, user_id="sarah") as moderator:
829
- print(f"Session: {moderator.context.session_id}")
830
-
831
- # Use moderator - cleanup happens automatically
832
- response = await moderator.chat("Download audio from https://youtube.com/watch?v=example")
833
- print(response)
834
-
835
- # Check agent status
836
- status = await moderator.get_agent_status()
837
- print(f"Active agents: {list(status['active_agents'].keys())}")
838
- # Moderator automatically cleaned up here
839
-
840
- asyncio.run(main())
841
- ```
842
-
843
- ## Command Line Interface
844
-
845
- The CLI provides full command line access to all agent capabilities,
846
- allowing you to interact with the system without writing code. reads from the `agent_config.yaml` file for configuration.:
847
-
848
- ```bash
849
- # Install the CLI
850
- pip install ambivo-agents
851
-
852
- # Interactive mode with auto-routing
853
- ambivo-agents
854
-
855
- # Single queries (auto-routed)
856
- ambivo-agents -q "Download audio from https://youtube.com/watch?v=example"
857
- ambivo-agents -q "Search for latest AI trends"
858
- ambivo-agents -q "Extract audio from video.mp4"
859
-
860
- # Check agent status
861
- ambivo-agents status
862
-
863
- # Test all agents
864
- ambivo-agents --test
865
- ```
866
-
867
- ### Command Line Examples
868
- ```bash
869
- # ModeratorAgent routes these automatically:
870
-
871
- # YouTube downloads
872
- ambivo-agents -q "Download https://youtube.com/watch?v=example --audio-only"
873
- ambivo-agents -q "Get info about https://youtube.com/watch?v=example"
874
-
875
- # Web search
876
- ambivo-agents -q "Search for latest Python frameworks"
877
- ambivo-agents -q "Find news about artificial intelligence"
878
-
879
- # Media processing
880
- ambivo-agents -q "Extract audio from video.mp4 as high quality mp3"
881
- ambivo-agents -q "Convert video.avi to mp4"
882
-
883
- # General assistance
884
- ambivo-agents -q "What is machine learning?"
885
- ambivo-agents -q "Explain quantum computing"
886
-
887
- # Interactive mode with smart routing
888
- ambivo-agents
889
- > Download audio from YouTube
890
- > Search for AI news
891
- > Extract audio from my video file
892
- > What's the weather like?
893
- ```
894
-
895
- ### CLI Status and Debugging
896
-
897
- ```bash
898
- # Check agent status
899
- ambivo-agents status
900
-
901
- # View configuration
902
- ambivo-agents config
903
-
904
- # Debug mode
905
- ambivo-agents --debug -q "test query"
906
-
907
- # Test all capabilities
908
- ambivo-agents --test
909
- ```
910
-
911
- ## Architecture
912
-
913
- ### ModeratorAgent Architecture
914
-
915
- The **ModeratorAgent** acts as an intelligent orchestrator:
916
-
917
- ```
918
- [User Query]
919
-
920
- [ModeratorAgent] ← Analyzes intent and context
921
-
922
- [Intent Analysis] ← Uses LLM + patterns + keywords
923
-
924
- [Route Selection] ← Chooses best agent(s)
925
-
926
- [Specialized Agent] ← YouTubeAgent, SearchAgent, etc.
927
-
928
- [Response] ← Combined and contextualized
929
-
930
- [User]
931
- ```
932
-
933
- ### Agent Capabilities
934
- Each agent provides specialized functionality:
935
-
936
- - **🎛️ ModeratorAgent** → Intelligent routing and orchestration
937
- - **🎬 YouTube Download Agent** → Video/audio downloads with pytubefix
938
- - **🎥 Media Editor Agent** → FFmpeg-based processing
939
- - **📚 Knowledge Base Agent** → Qdrant vector search
940
- - **🔍 Web Search Agent** → Multi-provider search
941
- - **🕷️ Web Scraper Agent** → Proxy-enabled scraping
942
- - **💻 Code Executor Agent** → Docker-based execution
943
-
944
- ### Memory System
945
- - **Redis-based persistence** with compression and caching
946
- - **Built-in conversation history** for every agent
947
- - **Session-aware context** with automatic cleanup
948
- - **Multi-session support** with isolation
949
-
950
- ### LLM Provider Management
951
- - **Automatic failover** between OpenAI, Anthropic, AWS Bedrock
952
- - **Rate limiting** and error handling
953
- - **Provider rotation** based on availability and performance
954
-
955
- ## Docker Setup
956
-
957
- ### Custom Docker Image
958
- If you need additional dependencies, extend the base image:
959
-
960
- ```dockerfile
961
- FROM sgosain/amb-ubuntu-python-public-pod
962
-
963
- # Install additional packages
964
- RUN pip install your-additional-packages
965
-
966
- # Add custom scripts
967
- COPY your-scripts/ /opt/scripts/
968
- ```
969
-
970
- ### Volume Mounting
971
- The agents automatically handle volume mounting for:
972
- - Media input/output directories
973
- - YouTube download directories
974
- - Code execution workspaces
975
-
976
- ## Troubleshooting
977
-
978
- ### Common Issues
979
-
980
- 1. **ModeratorAgent Routing Issues**
981
- ```python
982
- # Check available agents
983
- status = await moderator.get_agent_status()
984
- print(f"Available: {list(status['active_agents'].keys())}")
985
-
986
- # Check configuration
987
- print(f"Enabled: {moderator.enabled_agents}")
988
- ```
989
-
990
- 2. **Redis Connection Failed**
991
- ```bash
992
- # For cloud Redis: Check connection details in agent_config.yaml
993
- # For local Redis: Check if running
994
- redis-cli ping # Should return "PONG"
995
- ```
996
-
997
- 3. **Docker Not Available**
998
- ```bash
999
- # Check Docker is running
1000
- docker ps
1001
- # Install if missing: https://docs.docker.com/get-docker/
1002
- ```
1003
-
1004
- 4. **Agent Creation Errors**
1005
- ```python
1006
- # Check moderator can be created
1007
- from ambivo_agents import ModeratorAgent
1008
- try:
1009
- moderator, context = ModeratorAgent.create(user_id="test")
1010
- print(f"✅ Success: {context.session_id}")
1011
- await moderator.cleanup_session()
1012
- except Exception as e:
1013
- print(f"❌ Error: {e}")
1014
- ```
1015
-
1016
- 5. **Import Errors**
1017
- ```bash
1018
- # Ensure clean imports work
1019
- python -c "from ambivo_agents import ModeratorAgent; print('✅ Import success')"
1020
- ```
1021
-
1022
- ### Debug Mode
1023
- Enable verbose logging:
1024
- ```yaml
1025
- service:
1026
- log_level: "DEBUG"
1027
- log_to_file: true
1028
- ```
1029
-
1030
- ## Security Considerations
1031
-
1032
- - **Docker Isolation**: All code execution happens in isolated containers
1033
- - **Network Restrictions**: Containers run with `network_disabled=True` by default
1034
- - **Resource Limits**: Memory and CPU limits prevent resource exhaustion
1035
- - **API Key Management**: Store sensitive keys in environment variables
1036
- - **Input Sanitization**: All user inputs are validated and sanitized
1037
- - **Session Isolation**: Each agent session is completely isolated
1038
-
1039
- ## Contributing
1040
-
1041
- We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.
1042
-
1043
- ### Development Setup
1044
- ```bash
1045
- # Clone repository
1046
- git clone https://github.com/ambivo-corp/ambivo-agents.git
1047
- cd ambivo-agents
1048
-
1049
- # Install in development mode
1050
- pip install -e .
1051
-
1052
- # Test ModeratorAgent
1053
- python -c "
1054
- from ambivo_agents import ModeratorAgent
1055
- import asyncio
1056
-
1057
- async def test():
1058
- moderator, context = ModeratorAgent.create(user_id='test')
1059
- response = await moderator.chat('Hello!')
1060
- print(f'Response: {response}')
1061
- await moderator.cleanup_session()
1062
-
1063
- asyncio.run(test())
1064
- "
1065
- ```
1066
-
1067
- ## License
1068
-
1069
- MIT License - see [LICENSE](LICENSE) file for details.
1070
-
1071
- **Alpha Release**: This software is provided "as is" without warranty. Users assume all risks associated with its use, particularly in production environments.
1072
-
1073
- ## Author
1074
-
1075
- **Hemant Gosain 'Sunny'**
1076
- - Company: [Ambivo](https://www.ambivo.com)
1077
- - Email: info@ambivo.com
1078
-
1079
- ## Support
1080
-
1081
- - 📧 Email: info@ambivo.com
1082
- - 🌐 Website: https://www.ambivo.com
1083
- - 📖 Documentation: [Coming Soon]
1084
- - 🐛 Issues: [GitHub Issues](https://github.com/ambivo-corp/ambivo-agents/issues)
1085
-
1086
- **Alpha Support**: As an alpha release, support is provided on a best-effort basis. Response times may vary, and some issues may require significant investigation.
1087
-
1088
- ---
1089
-
1090
- *Developed by the Ambivo team.*