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.
@@ -0,0 +1,921 @@
1
+ Metadata-Version: 2.4
2
+ Name: ambivo-agents
3
+ Version: 1.0.2
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 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.
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
+ ## Table of Contents
103
+
104
+ - [Quick Start](#quick-start)
105
+ - [Agent Creation](#agent-creation)
106
+ - [Features](#features)
107
+ - [Available Agents](#available-agents)
108
+ - [Prerequisites](#prerequisites)
109
+ - [Installation](#installation)
110
+ - [Configuration](#configuration)
111
+ - [Configuration Methods](#configuration-methods)
112
+ - [Project Structure](#project-structure)
113
+ - [Usage Examples](#usage-examples)
114
+ - [Session Management](#session-management)
115
+ - [Web API Integration](#web-api-integration)
116
+ - [Command Line Interface](#command-line-interface)
117
+ - [Architecture](#architecture)
118
+ - [Docker Setup](#docker-setup)
119
+ - [Troubleshooting](#troubleshooting)
120
+ - [Security Considerations](#security-considerations)
121
+ - [Contributing](#contributing)
122
+ - [License](#license)
123
+ - [Author](#author)
124
+ - [Support](#support)
125
+
126
+ ## Quick Start
127
+
128
+ ### ModeratorAgent Example
129
+
130
+ The **ModeratorAgent** automatically routes queries to specialized agents:
131
+
132
+ ```python
133
+ from ambivo_agents import ModeratorAgent
134
+ import asyncio
135
+
136
+ async def main():
137
+ # Create the moderator
138
+ moderator, context = ModeratorAgent.create(user_id="john")
139
+
140
+ print(f"Session: {context.session_id}")
141
+
142
+ # Auto-routing examples
143
+ response1 = await moderator.chat("Download audio from https://youtube.com/watch?v=dQw4w9WgXcQ")
144
+ response2 = await moderator.chat("Search for latest AI trends")
145
+ response3 = await moderator.chat("Extract audio from video.mp4 as MP3")
146
+ response4 = await moderator.chat("What is machine learning?")
147
+
148
+ # Check available agents
149
+ status = await moderator.get_agent_status()
150
+ print(f"Available agents: {list(status['active_agents'].keys())}")
151
+
152
+ # Cleanup
153
+ await moderator.cleanup_session()
154
+
155
+ asyncio.run(main())
156
+ ```
157
+
158
+ ### Command Line Usage
159
+
160
+ ```bash
161
+ # Install and run
162
+ pip install ambivo-agents
163
+
164
+ # Interactive mode
165
+ ambivo-agents
166
+
167
+ # Single commands
168
+ ambivo-agents -q "Download audio from https://youtube.com/watch?v=example"
169
+ ambivo-agents -q "Search for Python tutorials"
170
+ ```
171
+
172
+ ## Agent Creation
173
+
174
+ ### ModeratorAgent (Recommended)
175
+
176
+ ```python
177
+ from ambivo_agents import ModeratorAgent
178
+
179
+ # Create moderator with auto-routing
180
+ moderator, context = ModeratorAgent.create(user_id="john")
181
+
182
+ # Chat with automatic agent selection
183
+ result = await moderator.chat("Download audio from https://youtube.com/watch?v=example")
184
+
185
+ # Cleanup
186
+ await moderator.cleanup_session()
187
+ ```
188
+
189
+ **Use ModeratorAgent for:**
190
+ - Multi-purpose applications
191
+ - Intelligent routing between capabilities
192
+ - Context-aware conversations
193
+ - Simplified development
194
+
195
+ ### Direct Agent Creation
196
+
197
+ ```python
198
+ from ambivo_agents import YouTubeDownloadAgent
199
+
200
+ # Create specific agent
201
+ agent, context = YouTubeDownloadAgent.create(user_id="john")
202
+
203
+ # Use agent directly
204
+ result = await agent._download_youtube_audio("https://youtube.com/watch?v=example")
205
+
206
+ # Cleanup
207
+ await agent.cleanup_session()
208
+ ```
209
+
210
+ **Use Direct Creation for:**
211
+ - Single-purpose applications
212
+ - Specific workflows with known requirements
213
+ - Performance-critical applications
214
+ - Custom integrations
215
+
216
+ ## Features
217
+
218
+ ### Core Capabilities
219
+ - **ModeratorAgent**: Intelligent multi-agent orchestrator with automatic routing
220
+ - **Smart Routing**: Automatically routes queries to appropriate specialized agents
221
+ - **Context Memory**: Maintains conversation history across interactions
222
+ - **Docker Integration**: Secure, isolated execution environment
223
+ - **Redis Memory**: Persistent conversation memory with compression
224
+ - **Multi-Provider LLM**: Automatic failover between OpenAI, Anthropic, and AWS Bedrock
225
+ - **Configuration-Driven**: All features controlled via `agent_config.yaml`
226
+
227
+ ## Available Agents
228
+
229
+ ### ModeratorAgent
230
+ - Intelligent orchestrator that routes to specialized agents
231
+ - Context-aware multi-turn conversations
232
+ - Automatic agent selection based on query analysis
233
+ - Session management and cleanup
234
+
235
+ ### Assistant Agent
236
+ - General purpose conversational AI
237
+ - Context-aware responses
238
+ - Multi-turn conversations
239
+
240
+ ### Code Executor Agent
241
+ - Secure Python and Bash execution in Docker
242
+ - Isolated environment with resource limits
243
+ - Real-time output streaming
244
+
245
+ ### Web Search Agent
246
+ - Multi-provider search (Brave, AVES APIs)
247
+ - Academic search capabilities
248
+ - Automatic provider failover
249
+
250
+ ### Web Scraper Agent
251
+ - Proxy-enabled scraping (ScraperAPI compatible)
252
+ - Playwright and requests-based scraping
253
+ - Batch URL processing with rate limiting
254
+
255
+ ### Knowledge Base Agent
256
+ - Document ingestion (PDF, DOCX, TXT, web URLs)
257
+ - Vector similarity search with Qdrant
258
+ - Semantic question answering
259
+
260
+ ### Media Editor Agent
261
+ - Audio/video processing with FFmpeg
262
+ - Format conversion, resizing, trimming
263
+ - Audio extraction and volume adjustment
264
+
265
+ ### YouTube Download Agent
266
+ - Download videos and audio from YouTube
267
+ - Docker-based execution with pytubefix
268
+ - Automatic title sanitization and metadata extraction
269
+
270
+ ## Prerequisites
271
+
272
+ ### Required
273
+ - **Python 3.11+**
274
+ - **Docker** (for code execution, media processing, YouTube downloads)
275
+ - **Redis** (Cloud Redis recommended)
276
+
277
+ ### API Keys (Optional - based on enabled features)
278
+ - **OpenAI API Key** (for GPT models)
279
+ - **Anthropic API Key** (for Claude models)
280
+ - **AWS Credentials** (for Bedrock models)
281
+ - **Brave Search API Key** (for web search)
282
+ - **AVES API Key** (for web search)
283
+ - **ScraperAPI/Proxy credentials** (for web scraping)
284
+ - **Qdrant Cloud API Key** (for Knowledge Base operations)
285
+ - **Redis Cloud credentials** (for memory management)
286
+
287
+ ## Installation
288
+
289
+ ### 1. Install Dependencies
290
+ ```bash
291
+ pip install -r requirements.txt
292
+ ```
293
+
294
+ ### 2. Setup Docker Images
295
+ ```bash
296
+ docker pull sgosain/amb-ubuntu-python-public-pod
297
+ ```
298
+
299
+ ### 3. Setup Redis
300
+
301
+ **Recommended: Cloud Redis**
302
+ ```yaml
303
+ # In agent_config.yaml
304
+ redis:
305
+ host: "your-redis-cloud-endpoint.redis.cloud"
306
+ port: 6379
307
+ password: "your-redis-password"
308
+ ```
309
+
310
+ **Alternative: Local Redis**
311
+ ```bash
312
+ # Using Docker
313
+ docker run -d --name redis -p 6379:6379 redis:latest
314
+ ```
315
+
316
+ ## Configuration
317
+
318
+ Create `agent_config.yaml` in your project root:
319
+
320
+ ```yaml
321
+ # Redis Configuration (Required)
322
+ redis:
323
+ host: "your-redis-cloud-endpoint.redis.cloud"
324
+ port: 6379
325
+ db: 0
326
+ password: "your-redis-password"
327
+
328
+ # LLM Configuration (Required - at least one provider)
329
+ llm:
330
+ preferred_provider: "openai"
331
+ temperature: 0.7
332
+ openai_api_key: "your-openai-key"
333
+ anthropic_api_key: "your-anthropic-key"
334
+ aws_access_key_id: "your-aws-key"
335
+ aws_secret_access_key: "your-aws-secret"
336
+ aws_region: "us-east-1"
337
+
338
+ # Agent Capabilities
339
+ agent_capabilities:
340
+ enable_knowledge_base: true
341
+ enable_web_search: true
342
+ enable_code_execution: true
343
+ enable_file_processing: true
344
+ enable_web_ingestion: true
345
+ enable_api_calls: true
346
+ enable_web_scraping: true
347
+ enable_proxy_mode: true
348
+ enable_media_editor: true
349
+ enable_youtube_download: true
350
+
351
+ # ModeratorAgent default agents
352
+ moderator:
353
+ default_enabled_agents:
354
+ - knowledge_base
355
+ - web_search
356
+ - assistant
357
+ - media_editor
358
+ - youtube_download
359
+ - code_executor
360
+ - web_scraper
361
+
362
+ # Service-specific configurations
363
+ web_search:
364
+ brave_api_key: "your-brave-api-key"
365
+ avesapi_api_key: "your-aves-api-key"
366
+
367
+ knowledge_base:
368
+ qdrant_url: "https://your-cluster.qdrant.tech"
369
+ qdrant_api_key: "your-qdrant-api-key"
370
+ chunk_size: 1024
371
+ chunk_overlap: 20
372
+ similarity_top_k: 5
373
+
374
+ youtube_download:
375
+ docker_image: "sgosain/amb-ubuntu-python-public-pod"
376
+ download_dir: "./youtube_downloads"
377
+ timeout: 600
378
+ memory_limit: "1g"
379
+ default_audio_only: true
380
+
381
+ docker:
382
+ timeout: 60
383
+ memory_limit: "512m"
384
+ images: ["sgosain/amb-ubuntu-python-public-pod"]
385
+ ```
386
+
387
+ ## Configuration
388
+
389
+ The library supports two configuration methods:
390
+
391
+ ### 1. Environment Variables (Recommended for Production)
392
+
393
+ **Quick Start with Environment Variables:**
394
+
395
+ ```bash
396
+ # Download and edit the full template
397
+ curl -o set_env.sh https://github.com/ambivo-corp/ambivo-agents/raw/main/set_env_template.sh
398
+ chmod +x set_env.sh
399
+
400
+ # Edit the template with your credentials, then source it
401
+ source set_env.sh
402
+ ```
403
+
404
+ **Replace ALL placeholder values** with your actual credentials:
405
+ - Redis connection details
406
+ - LLM API keys (OpenAI/Anthropic)
407
+ - Web Search API keys (Brave/AVES)
408
+ - Knowledge Base credentials (Qdrant)
409
+ - Web Scraping proxy (ScraperAPI)
410
+
411
+ **Minimal Environment Setup:**
412
+ ```bash
413
+ # Required - Redis
414
+ export AMBIVO_AGENTS_REDIS_HOST="your-redis-host.redis.cloud"
415
+ export AMBIVO_AGENTS_REDIS_PORT="6379"
416
+ export AMBIVO_AGENTS_REDIS_PASSWORD="your-redis-password"
417
+
418
+ # Required - At least one LLM provider
419
+ export AMBIVO_AGENTS_OPENAI_API_KEY="sk-your-openai-key"
420
+
421
+ # Optional - Enable specific agents
422
+ export AMBIVO_AGENTS_ENABLE_YOUTUBE_DOWNLOAD="true"
423
+ export AMBIVO_AGENTS_ENABLE_WEB_SEARCH="true"
424
+ export AMBIVO_AGENTS_MODERATOR_ENABLED_AGENTS="youtube_download,web_search,assistant"
425
+
426
+ # Run your application
427
+ python your_app.py
428
+ ```
429
+
430
+ ### 2. YAML Configuration (Traditional)
431
+
432
+ **Use the full YAML template:**
433
+
434
+ ```bash
435
+ # Download and edit the full template
436
+ curl -o agent_config_sample.yaml https://github.com/ambivo-corp/ambivo-agents/raw/main/agent_config_sample.yaml
437
+
438
+ # Copy to your config file and edit with your credentials
439
+ cp agent_config_sample.yaml agent_config.yaml
440
+ ```
441
+
442
+ **Replace ALL placeholder values** with your actual credentials, then create `agent_config.yaml` in your project root:
443
+
444
+ ```yaml
445
+ # Redis Configuration (Required)
446
+ redis:
447
+ host: "your-redis-cloud-endpoint.redis.cloud"
448
+ port: 6379
449
+ db: 0
450
+ password: "your-redis-password"
451
+
452
+ # LLM Configuration (Required - at least one provider)
453
+ llm:
454
+ preferred_provider: "openai"
455
+ temperature: 0.7
456
+ openai_api_key: "your-openai-key"
457
+ anthropic_api_key: "your-anthropic-key"
458
+ aws_access_key_id: "your-aws-key"
459
+ aws_secret_access_key: "your-aws-secret"
460
+ aws_region: "us-east-1"
461
+
462
+ # Agent Capabilities
463
+ agent_capabilities:
464
+ enable_knowledge_base: true
465
+ enable_web_search: true
466
+ enable_code_execution: true
467
+ enable_file_processing: true
468
+ enable_web_ingestion: true
469
+ enable_api_calls: true
470
+ enable_web_scraping: true
471
+ enable_proxy_mode: true
472
+ enable_media_editor: true
473
+ enable_youtube_download: true
474
+
475
+ # ModeratorAgent default agents
476
+ moderator:
477
+ default_enabled_agents:
478
+ - knowledge_base
479
+ - web_search
480
+ - assistant
481
+ - media_editor
482
+ - youtube_download
483
+ - code_executor
484
+ - web_scraper
485
+
486
+ # Service-specific configurations
487
+ web_search:
488
+ brave_api_key: "your-brave-api-key"
489
+ avesapi_api_key: "your-aves-api-key"
490
+
491
+ knowledge_base:
492
+ qdrant_url: "https://your-cluster.qdrant.tech"
493
+ qdrant_api_key: "your-qdrant-api-key"
494
+ chunk_size: 1024
495
+ chunk_overlap: 20
496
+ similarity_top_k: 5
497
+
498
+ youtube_download:
499
+ docker_image: "sgosain/amb-ubuntu-python-public-pod"
500
+ download_dir: "./youtube_downloads"
501
+ timeout: 600
502
+ memory_limit: "1g"
503
+ default_audio_only: true
504
+
505
+ docker:
506
+ timeout: 60
507
+ memory_limit: "512m"
508
+ images: ["sgosain/amb-ubuntu-python-public-pod"]
509
+ ```
510
+
511
+ ### Docker Deployment with Environment Variables
512
+
513
+ ```yaml
514
+ # docker-compose.yml
515
+ version: '3.8'
516
+ services:
517
+ ambivo-app:
518
+ image: your-app:latest
519
+ environment:
520
+ - AMBIVO_AGENTS_REDIS_HOST=redis
521
+ - AMBIVO_AGENTS_REDIS_PORT=6379
522
+ - AMBIVO_AGENTS_OPENAI_API_KEY=${OPENAI_API_KEY}
523
+ - AMBIVO_AGENTS_ENABLE_YOUTUBE_DOWNLOAD=true
524
+ volumes:
525
+ - ./downloads:/app/downloads
526
+ - /var/run/docker.sock:/var/run/docker.sock
527
+ depends_on:
528
+ - redis
529
+
530
+ redis:
531
+ image: redis:latest
532
+ ports:
533
+ - "6379:6379"
534
+ ```
535
+
536
+ **Note:** Environment variables take precedence over YAML configuration. The `agent_config.yaml` file is optional when using environment variables.
537
+
538
+ ## Project Structure
539
+
540
+ ```
541
+ ambivo_agents/
542
+ ├── agents/ # Agent implementations
543
+ │ ├── assistant.py
544
+ │ ├── code_executor.py
545
+ │ ├── knowledge_base.py
546
+ │ ├── media_editor.py
547
+ │ ├── moderator.py # ModeratorAgent (main orchestrator)
548
+ │ ├── simple_web_search.py
549
+ │ ├── web_scraper.py
550
+ │ ├── web_search.py
551
+ │ └── youtube_download.py
552
+ ├── config/ # Configuration management
553
+ ├── core/ # Core functionality
554
+ │ ├── base.py
555
+ │ ├── llm.py
556
+ │ └── memory.py
557
+ ├── executors/ # Execution environments
558
+ ├── services/ # Service layer
559
+ ├── __init__.py # Package initialization
560
+ └── cli.py # Command line interface
561
+ ```
562
+
563
+ ## Usage Examples
564
+
565
+ ### ModeratorAgent with Auto-Routing
566
+
567
+ ```python
568
+ from ambivo_agents import ModeratorAgent
569
+ import asyncio
570
+
571
+ async def basic_moderator():
572
+ moderator, context = ModeratorAgent.create(user_id="demo_user")
573
+
574
+ # Auto-routing examples
575
+ examples = [
576
+ "Download audio from https://youtube.com/watch?v=dQw4w9WgXcQ",
577
+ "Search for latest artificial intelligence news",
578
+ "Extract audio from video.mp4 as high quality MP3",
579
+ "What is machine learning and how does it work?",
580
+ ]
581
+
582
+ for query in examples:
583
+ response = await moderator.chat(query)
584
+ print(f"Response: {response[:100]}...")
585
+
586
+ await moderator.cleanup_session()
587
+
588
+ asyncio.run(basic_moderator())
589
+ ```
590
+
591
+ ### Context-Aware Conversations
592
+
593
+ ```python
594
+ async def context_conversation():
595
+ moderator, context = ModeratorAgent.create(user_id="context_demo")
596
+
597
+ # Initial request
598
+ response1 = await moderator.chat("Download audio from https://youtube.com/watch?v=example")
599
+
600
+ # Follow-up using context
601
+ response2 = await moderator.chat("Actually, download the video instead of just audio")
602
+
603
+ # Another follow-up
604
+ response3 = await moderator.chat("Get information about that video")
605
+
606
+ await moderator.cleanup_session()
607
+ ```
608
+
609
+ ### YouTube Downloads
610
+
611
+ ```python
612
+ from ambivo_agents import YouTubeDownloadAgent
613
+
614
+ async def download_youtube():
615
+ agent, context = YouTubeDownloadAgent.create(user_id="media_user")
616
+
617
+ # Download audio
618
+ result = await agent._download_youtube_audio(
619
+ "https://youtube.com/watch?v=example"
620
+ )
621
+
622
+ if result['success']:
623
+ print(f"Audio downloaded: {result['filename']}")
624
+ print(f"Path: {result['file_path']}")
625
+
626
+ await agent.cleanup_session()
627
+ ```
628
+
629
+ ### Knowledge Base Operations
630
+
631
+ ```python
632
+ from ambivo_agents import KnowledgeBaseAgent
633
+
634
+ async def knowledge_base_demo():
635
+ agent, context = KnowledgeBaseAgent.create(user_id="kb_user")
636
+
637
+ # Ingest document
638
+ result = await agent._ingest_document(
639
+ kb_name="company_kb",
640
+ doc_path="/path/to/document.pdf",
641
+ custom_meta={"department": "HR", "type": "policy"}
642
+ )
643
+
644
+ if result['success']:
645
+ # Query the knowledge base
646
+ answer = await agent._query_knowledge_base(
647
+ kb_name="company_kb",
648
+ query="What is the remote work policy?"
649
+ )
650
+
651
+ if answer['success']:
652
+ print(f"Answer: {answer['answer']}")
653
+
654
+ await agent.cleanup_session()
655
+ ```
656
+
657
+ ### Context Manager Pattern
658
+
659
+ ```python
660
+ from ambivo_agents import ModeratorAgent, AgentSession
661
+ import asyncio
662
+
663
+ async def main():
664
+ # Auto-cleanup with context manager
665
+ async with AgentSession(ModeratorAgent, user_id="sarah") as moderator:
666
+ response = await moderator.chat("Download audio from https://youtube.com/watch?v=example")
667
+ print(response)
668
+ # Moderator automatically cleaned up
669
+
670
+ asyncio.run(main())
671
+ ```
672
+
673
+ ## Session Management
674
+
675
+ ### Understanding Session vs Conversation IDs
676
+
677
+ The library uses two identifiers for context management:
678
+
679
+ - **session_id**: Represents a broader user session or application context
680
+ - **conversation_id**: Represents a specific conversation thread within a session
681
+
682
+ ```python
683
+ # Single conversation (most common)
684
+ moderator, context = ModeratorAgent.create(
685
+ user_id="john",
686
+ session_id="user_john_main",
687
+ conversation_id="user_john_main" # Same as session_id
688
+ )
689
+
690
+ # Multiple conversations per session
691
+ session_key = "user_john_tenant_abc"
692
+
693
+ # Conversation 1: Data Analysis
694
+ moderator1, context1 = ModeratorAgent.create(
695
+ user_id="john",
696
+ session_id=session_key,
697
+ conversation_id="john_data_analysis_conv"
698
+ )
699
+
700
+ # Conversation 2: YouTube Downloads
701
+ moderator2, context2 = ModeratorAgent.create(
702
+ user_id="john",
703
+ session_id=session_key,
704
+ conversation_id="john_youtube_downloads_conv"
705
+ )
706
+ ```
707
+
708
+ ## Web API Integration
709
+
710
+ ```python
711
+ from ambivo_agents import ModeratorAgent
712
+ import asyncio
713
+ import time
714
+
715
+ class ChatAPI:
716
+ def __init__(self):
717
+ self.active_moderators = {}
718
+
719
+ async def chat_endpoint(self, request_data):
720
+ user_message = request_data.get('message', '')
721
+ user_id = request_data.get('user_id', f"user_{uuid.uuid4()}")
722
+ session_id = request_data.get('session_id', f"session_{user_id}_{int(time.time())}")
723
+
724
+ try:
725
+ if session_id not in self.active_moderators:
726
+ moderator, context = ModeratorAgent.create(
727
+ user_id=user_id,
728
+ session_id=session_id
729
+ )
730
+ self.active_moderators[session_id] = moderator
731
+ else:
732
+ moderator = self.active_moderators[session_id]
733
+
734
+ response_content = await moderator.chat(user_message)
735
+
736
+ return {
737
+ 'success': True,
738
+ 'response': response_content,
739
+ 'session_id': session_id,
740
+ 'timestamp': time.time()
741
+ }
742
+
743
+ except Exception as e:
744
+ return {
745
+ 'success': False,
746
+ 'error': str(e),
747
+ 'timestamp': time.time()
748
+ }
749
+
750
+ async def cleanup_session(self, session_id):
751
+ if session_id in self.active_moderators:
752
+ await self.active_moderators[session_id].cleanup_session()
753
+ del self.active_moderators[session_id]
754
+ ```
755
+
756
+ ## Command Line Interface
757
+
758
+ ```bash
759
+ # Interactive mode with auto-routing
760
+ ambivo-agents
761
+
762
+ # Single queries
763
+ ambivo-agents -q "Download audio from https://youtube.com/watch?v=example"
764
+ ambivo-agents -q "Search for latest AI trends"
765
+ ambivo-agents -q "Extract audio from video.mp4"
766
+
767
+ # Check agent status
768
+ ambivo-agents status
769
+
770
+ # Test all agents
771
+ ambivo-agents --test
772
+
773
+ # Debug mode
774
+ ambivo-agents --debug -q "test query"
775
+ ```
776
+
777
+ ## Architecture
778
+
779
+ ### ModeratorAgent Architecture
780
+
781
+ The **ModeratorAgent** acts as an intelligent orchestrator:
782
+
783
+ ```
784
+ [User Query]
785
+
786
+ [ModeratorAgent] ← Analyzes intent and context
787
+
788
+ [Intent Analysis] ← Uses LLM + patterns + keywords
789
+
790
+ [Route Selection] ← Chooses best agent(s)
791
+
792
+ [Specialized Agent] ← YouTubeAgent, SearchAgent, etc.
793
+
794
+ [Response] ← Combined and contextualized
795
+
796
+ [User]
797
+ ```
798
+
799
+ ### Memory System
800
+ - Redis-based persistence with compression and caching
801
+ - Built-in conversation history for every agent
802
+ - Session-aware context with automatic cleanup
803
+ - Multi-session support with isolation
804
+
805
+ ### LLM Provider Management
806
+ - Automatic failover between OpenAI, Anthropic, AWS Bedrock
807
+ - Rate limiting and error handling
808
+ - Provider rotation based on availability and performance
809
+
810
+ ## Docker Setup
811
+
812
+ ### Custom Docker Image
813
+
814
+ ```dockerfile
815
+ FROM sgosain/amb-ubuntu-python-public-pod
816
+
817
+ # Install additional packages
818
+ RUN pip install your-additional-packages
819
+
820
+ # Add custom scripts
821
+ COPY your-scripts/ /opt/scripts/
822
+ ```
823
+
824
+ ## Troubleshooting
825
+
826
+ ### Common Issues
827
+
828
+ 1. **Redis Connection Failed**
829
+ ```bash
830
+ # Check if Redis is running
831
+ redis-cli ping # Should return "PONG"
832
+ ```
833
+
834
+ 2. **Docker Not Available**
835
+ ```bash
836
+ # Check Docker is running
837
+ docker ps
838
+ ```
839
+
840
+ 3. **Agent Creation Errors**
841
+ ```python
842
+ from ambivo_agents import ModeratorAgent
843
+ try:
844
+ moderator, context = ModeratorAgent.create(user_id="test")
845
+ print(f"Success: {context.session_id}")
846
+ await moderator.cleanup_session()
847
+ except Exception as e:
848
+ print(f"Error: {e}")
849
+ ```
850
+
851
+ 4. **Import Errors**
852
+ ```bash
853
+ python -c "from ambivo_agents import ModeratorAgent; print('Import success')"
854
+ ```
855
+
856
+ ### Debug Mode
857
+
858
+ Enable verbose logging:
859
+ ```yaml
860
+ service:
861
+ log_level: "DEBUG"
862
+ log_to_file: true
863
+ ```
864
+
865
+ ## Security Considerations
866
+
867
+ - **Docker Isolation**: All code execution happens in isolated containers
868
+ - **Network Restrictions**: Containers run with `network_disabled=True` by default
869
+ - **Resource Limits**: Memory and CPU limits prevent resource exhaustion
870
+ - **API Key Management**: Store sensitive keys in environment variables
871
+ - **Input Sanitization**: All user inputs are validated and sanitized
872
+ - **Session Isolation**: Each agent session is completely isolated
873
+
874
+ ## Contributing
875
+
876
+ We welcome contributions! Please see our [Contributing Guidelines](CONTRIBUTING.md) for details.
877
+
878
+ ### Development Setup
879
+
880
+ ```bash
881
+ # Clone repository
882
+ git clone https://github.com/ambivo-corp/ambivo-agents.git
883
+ cd ambivo-agents
884
+
885
+ # Install in development mode
886
+ pip install -e .
887
+
888
+ # Test ModeratorAgent
889
+ python -c "
890
+ from ambivo_agents import ModeratorAgent
891
+ import asyncio
892
+
893
+ async def test():
894
+ moderator, context = ModeratorAgent.create(user_id='test')
895
+ response = await moderator.chat('Hello!')
896
+ print(f'Response: {response}')
897
+ await moderator.cleanup_session()
898
+
899
+ asyncio.run(test())
900
+ "
901
+ ```
902
+
903
+ ## License
904
+
905
+ MIT License - see [LICENSE](LICENSE) file for details.
906
+
907
+ ## Author
908
+
909
+ **Hemant Gosain 'Sunny'**
910
+ - Company: [Ambivo](https://www.ambivo.com)
911
+ - Email: info@ambivo.com
912
+
913
+ ## Support
914
+
915
+ - Email: info@ambivo.com
916
+ - Website: https://www.ambivo.com
917
+ - Issues: [GitHub Issues](https://github.com/ambivo-corp/ambivo-agents/issues)
918
+
919
+ ---
920
+
921
+ *Developed by the Ambivo team.*