ambivo-agents 1.3.3__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.
- ambivo_agents/__init__.py +89 -0
- ambivo_agents/agents/__init__.py +19 -0
- ambivo_agents/agents/assistant.py +79 -0
- ambivo_agents/agents/code_executor.py +133 -0
- ambivo_agents/agents/knowledge_base.py +595 -0
- ambivo_agents/agents/media_editor.py +777 -0
- ambivo_agents/agents/simple_web_search.py +404 -0
- ambivo_agents/agents/web_scraper.py +682 -0
- ambivo_agents/agents/web_search.py +660 -0
- ambivo_agents/agents/youtube_download.py +553 -0
- ambivo_agents/cli.py +1871 -0
- ambivo_agents/config/__init__.py +4 -0
- ambivo_agents/config/loader.py +301 -0
- ambivo_agents/core/__init__.py +33 -0
- ambivo_agents/core/base.py +880 -0
- ambivo_agents/core/llm.py +333 -0
- ambivo_agents/core/memory.py +640 -0
- ambivo_agents/executors/__init__.py +8 -0
- ambivo_agents/executors/docker_executor.py +108 -0
- ambivo_agents/executors/media_executor.py +237 -0
- ambivo_agents/executors/youtube_executor.py +404 -0
- ambivo_agents/services/__init__.py +6 -0
- ambivo_agents/services/agent_service.py +590 -0
- ambivo_agents/services/factory.py +366 -0
- ambivo_agents-1.3.3.dist-info/METADATA +773 -0
- ambivo_agents-1.3.3.dist-info/RECORD +30 -0
- ambivo_agents-1.3.3.dist-info/WHEEL +5 -0
- ambivo_agents-1.3.3.dist-info/entry_points.txt +3 -0
- ambivo_agents-1.3.3.dist-info/licenses/LICENSE +21 -0
- ambivo_agents-1.3.3.dist-info/top_level.txt +1 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
# ambivo_agents/__init__.py
|
2
|
+
"""
|
3
|
+
Ambivo Agents Framework
|
4
|
+
A minimalistic agent framework for building AI applications.
|
5
|
+
"""
|
6
|
+
|
7
|
+
__version__ = "1.0.0"
|
8
|
+
|
9
|
+
# Core imports
|
10
|
+
from .core.base import (
|
11
|
+
AgentRole,
|
12
|
+
MessageType,
|
13
|
+
AgentMessage,
|
14
|
+
AgentTool,
|
15
|
+
ExecutionContext,
|
16
|
+
BaseAgent,
|
17
|
+
ProviderConfig,
|
18
|
+
ProviderTracker,
|
19
|
+
AgentSession
|
20
|
+
)
|
21
|
+
|
22
|
+
from .core.memory import (
|
23
|
+
MemoryManagerInterface,
|
24
|
+
RedisMemoryManager,
|
25
|
+
create_redis_memory_manager
|
26
|
+
)
|
27
|
+
|
28
|
+
from .core.llm import (
|
29
|
+
LLMServiceInterface,
|
30
|
+
MultiProviderLLMService,
|
31
|
+
create_multi_provider_llm_service
|
32
|
+
)
|
33
|
+
|
34
|
+
# Service imports
|
35
|
+
from .services.factory import AgentFactory
|
36
|
+
from .services.agent_service import AgentService, create_agent_service
|
37
|
+
|
38
|
+
# Agent imports
|
39
|
+
from .agents.assistant import AssistantAgent
|
40
|
+
from .agents.code_executor import CodeExecutorAgent
|
41
|
+
from .agents.knowledge_base import KnowledgeBaseAgent
|
42
|
+
from .agents.web_search import WebSearchAgent
|
43
|
+
from .agents.web_scraper import WebScraperAgent
|
44
|
+
from .agents.media_editor import MediaEditorAgent
|
45
|
+
from .agents.youtube_download import YouTubeDownloadAgent
|
46
|
+
|
47
|
+
# Configuration
|
48
|
+
from .config.loader import load_config, ConfigurationError
|
49
|
+
|
50
|
+
__all__ = [
|
51
|
+
# Core
|
52
|
+
"AgentRole",
|
53
|
+
"MessageType",
|
54
|
+
"AgentMessage",
|
55
|
+
"AgentTool",
|
56
|
+
"ExecutionContext",
|
57
|
+
"BaseAgent",
|
58
|
+
"ProviderConfig",
|
59
|
+
"ProviderTracker",
|
60
|
+
"AgentSession",
|
61
|
+
|
62
|
+
# Memory
|
63
|
+
"MemoryManagerInterface",
|
64
|
+
"RedisMemoryManager",
|
65
|
+
"create_redis_memory_manager",
|
66
|
+
|
67
|
+
# LLM
|
68
|
+
"LLMServiceInterface",
|
69
|
+
"MultiProviderLLMService",
|
70
|
+
"create_multi_provider_llm_service",
|
71
|
+
|
72
|
+
# Services
|
73
|
+
"AgentFactory",
|
74
|
+
"AgentService",
|
75
|
+
"create_agent_service",
|
76
|
+
|
77
|
+
# Agents
|
78
|
+
"AssistantAgent",
|
79
|
+
"CodeExecutorAgent",
|
80
|
+
"KnowledgeBaseAgent",
|
81
|
+
"WebSearchAgent",
|
82
|
+
"WebScraperAgent",
|
83
|
+
"MediaEditorAgent",
|
84
|
+
"YouTubeDownloadAgent",
|
85
|
+
|
86
|
+
# Configuration
|
87
|
+
"load_config",
|
88
|
+
"ConfigurationError"
|
89
|
+
]
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# ambivo_agents/agents/__init__.py
|
2
|
+
from .assistant import AssistantAgent
|
3
|
+
from .code_executor import CodeExecutorAgent
|
4
|
+
from .knowledge_base import KnowledgeBaseAgent
|
5
|
+
from .web_search import WebSearchAgent
|
6
|
+
from .web_scraper import WebScraperAgent
|
7
|
+
from .media_editor import MediaEditorAgent
|
8
|
+
from .youtube_download import YouTubeDownloadAgent
|
9
|
+
|
10
|
+
__all__ = [
|
11
|
+
"AssistantAgent",
|
12
|
+
"CodeExecutorAgent",
|
13
|
+
"KnowledgeBaseAgent",
|
14
|
+
"WebSearchAgent",
|
15
|
+
"WebScraperAgent",
|
16
|
+
"MediaEditorAgent",
|
17
|
+
"YouTubeDownloadAgent"
|
18
|
+
]
|
19
|
+
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# ambivo_agents/agents/assistant.py
|
2
|
+
"""
|
3
|
+
Assistant Agent for general purpose assistance.
|
4
|
+
"""
|
5
|
+
|
6
|
+
import logging
|
7
|
+
import uuid
|
8
|
+
from typing import Dict, Any
|
9
|
+
|
10
|
+
from ..core.base import BaseAgent, AgentRole, AgentMessage, MessageType, ExecutionContext
|
11
|
+
|
12
|
+
|
13
|
+
class AssistantAgent(BaseAgent):
|
14
|
+
"""General purpose assistant agent"""
|
15
|
+
|
16
|
+
def __init__(self, agent_id: str| None = None, memory_manager=None, llm_service=None, **kwargs):
|
17
|
+
if agent_id is None:
|
18
|
+
agent_id = f"assistant_{str(uuid.uuid4())[:8]}"
|
19
|
+
|
20
|
+
super().__init__(
|
21
|
+
agent_id=agent_id,
|
22
|
+
role=AgentRole.ASSISTANT,
|
23
|
+
memory_manager=memory_manager,
|
24
|
+
llm_service=llm_service,
|
25
|
+
name="Assistant Agent",
|
26
|
+
description="General purpose assistant for user interactions",
|
27
|
+
**kwargs
|
28
|
+
)
|
29
|
+
|
30
|
+
async def process_message(self, message: AgentMessage, context: ExecutionContext) -> AgentMessage:
|
31
|
+
"""Process user requests and provide assistance"""
|
32
|
+
self.memory.store_message(message)
|
33
|
+
|
34
|
+
try:
|
35
|
+
history = self.memory.get_recent_messages(limit=10, conversation_id=message.conversation_id)
|
36
|
+
|
37
|
+
conversation_context = "\n".join([
|
38
|
+
f"{msg.get('sender_id', 'unknown')}: {msg.get('content', '')}"
|
39
|
+
for msg in reversed(history[-5:]) if isinstance(msg, dict)
|
40
|
+
])
|
41
|
+
|
42
|
+
if self.llm_service:
|
43
|
+
prompt = f"""You are an AI assistant. Based on the conversation context below, provide a helpful response.
|
44
|
+
|
45
|
+
Conversation context:
|
46
|
+
{conversation_context}
|
47
|
+
|
48
|
+
Current user message: {message.content}
|
49
|
+
|
50
|
+
Please provide a helpful, accurate, and contextual response."""
|
51
|
+
|
52
|
+
response_content = await self.llm_service.generate_response(
|
53
|
+
prompt=prompt,
|
54
|
+
context={'conversation_id': message.conversation_id, 'user_id': context.user_id}
|
55
|
+
)
|
56
|
+
else:
|
57
|
+
response_content = f"I understand you said: '{message.content}'. How can I help you with that?"
|
58
|
+
|
59
|
+
response = self.create_response(
|
60
|
+
content=response_content,
|
61
|
+
recipient_id=message.sender_id,
|
62
|
+
session_id=message.session_id,
|
63
|
+
conversation_id=message.conversation_id
|
64
|
+
)
|
65
|
+
|
66
|
+
self.memory.store_message(response)
|
67
|
+
return response
|
68
|
+
|
69
|
+
except Exception as e:
|
70
|
+
logging.error(f"Assistant agent error: {e}")
|
71
|
+
error_response = self.create_response(
|
72
|
+
content=f"I encountered an error processing your request: {str(e)}",
|
73
|
+
recipient_id=message.sender_id,
|
74
|
+
message_type=MessageType.ERROR,
|
75
|
+
session_id=message.session_id,
|
76
|
+
conversation_id=message.conversation_id
|
77
|
+
)
|
78
|
+
return error_response
|
79
|
+
|
@@ -0,0 +1,133 @@
|
|
1
|
+
# ambivo_agents/agents/code_executor.py
|
2
|
+
"""
|
3
|
+
Code Executor Agent for running code in secure Docker containers.
|
4
|
+
"""
|
5
|
+
|
6
|
+
import logging
|
7
|
+
import uuid
|
8
|
+
from typing import Dict, Any
|
9
|
+
|
10
|
+
from ..core.base import BaseAgent, AgentRole, AgentMessage, MessageType, ExecutionContext, AgentTool, DockerCodeExecutor
|
11
|
+
from ..config.loader import load_config, get_config_section
|
12
|
+
|
13
|
+
|
14
|
+
class CodeExecutorAgent(BaseAgent):
|
15
|
+
"""Agent specialized in code execution"""
|
16
|
+
|
17
|
+
def __init__(self, agent_id: str=None, memory_manager=None, llm_service=None, **kwargs):
|
18
|
+
if agent_id is None:
|
19
|
+
agent_id = f"code_executor_{str(uuid.uuid4())[:8]}"
|
20
|
+
|
21
|
+
super().__init__(
|
22
|
+
agent_id=agent_id,
|
23
|
+
role=AgentRole.CODE_EXECUTOR,
|
24
|
+
memory_manager=memory_manager,
|
25
|
+
llm_service=llm_service,
|
26
|
+
name="Code Executor Agent",
|
27
|
+
description="Agent for secure code execution using Docker containers",
|
28
|
+
**kwargs
|
29
|
+
)
|
30
|
+
|
31
|
+
# Load Docker configuration from YAML
|
32
|
+
try:
|
33
|
+
config = load_config()
|
34
|
+
docker_config = config.get('docker', {})
|
35
|
+
except Exception as e:
|
36
|
+
logging.warning(f"Could not load Docker config from YAML: {e}")
|
37
|
+
docker_config = {}
|
38
|
+
|
39
|
+
self.docker_executor = DockerCodeExecutor(docker_config)
|
40
|
+
self._add_code_tools()
|
41
|
+
|
42
|
+
def _add_code_tools(self):
|
43
|
+
"""Add code execution tools"""
|
44
|
+
self.add_tool(AgentTool(
|
45
|
+
name="execute_python",
|
46
|
+
description="Execute Python code in a secure Docker container",
|
47
|
+
function=self._execute_python_code,
|
48
|
+
parameters_schema={
|
49
|
+
"type": "object",
|
50
|
+
"properties": {
|
51
|
+
"code": {"type": "string", "description": "Python code to execute"},
|
52
|
+
"files": {"type": "object", "description": "Additional files needed"}
|
53
|
+
},
|
54
|
+
"required": ["code"]
|
55
|
+
}
|
56
|
+
))
|
57
|
+
|
58
|
+
self.add_tool(AgentTool(
|
59
|
+
name="execute_bash",
|
60
|
+
description="Execute bash commands in a secure Docker container",
|
61
|
+
function=self._execute_bash_code,
|
62
|
+
parameters_schema={
|
63
|
+
"type": "object",
|
64
|
+
"properties": {
|
65
|
+
"code": {"type": "string", "description": "Bash commands to execute"},
|
66
|
+
"files": {"type": "object", "description": "Additional files needed"}
|
67
|
+
},
|
68
|
+
"required": ["code"]
|
69
|
+
}
|
70
|
+
))
|
71
|
+
|
72
|
+
async def _execute_python_code(self, code: str, files: Dict[str, str] = None) -> Dict[str, Any]:
|
73
|
+
"""Execute Python code safely"""
|
74
|
+
return self.docker_executor.execute_code(code, "python", files)
|
75
|
+
|
76
|
+
async def _execute_bash_code(self, code: str, files: Dict[str, str] = None) -> Dict[str, Any]:
|
77
|
+
"""Execute bash commands safely"""
|
78
|
+
return self.docker_executor.execute_code(code, "bash", files)
|
79
|
+
|
80
|
+
async def process_message(self, message: AgentMessage, context: ExecutionContext) -> AgentMessage:
|
81
|
+
"""Process code execution requests"""
|
82
|
+
self.memory.store_message(message)
|
83
|
+
|
84
|
+
try:
|
85
|
+
content = message.content
|
86
|
+
|
87
|
+
if "```python" in content:
|
88
|
+
code_start = content.find("```python") + 9
|
89
|
+
code_end = content.find("```", code_start)
|
90
|
+
code = content[code_start:code_end].strip()
|
91
|
+
|
92
|
+
result = await self._execute_python_code(code)
|
93
|
+
|
94
|
+
if result['success']:
|
95
|
+
response_content = f"Code executed successfully:\n\n```\n{result['output']}\n```\n\nExecution time: {result['execution_time']:.2f}s"
|
96
|
+
else:
|
97
|
+
response_content = f"Code execution failed:\n\n```\n{result['error']}\n```"
|
98
|
+
|
99
|
+
elif "```bash" in content:
|
100
|
+
code_start = content.find("```bash") + 7
|
101
|
+
code_end = content.find("```", code_start)
|
102
|
+
code = content[code_start:code_end].strip()
|
103
|
+
|
104
|
+
result = await self._execute_bash_code(code)
|
105
|
+
|
106
|
+
if result['success']:
|
107
|
+
response_content = f"Commands executed successfully:\n\n```\n{result['output']}\n```\n\nExecution time: {result['execution_time']:.2f}s"
|
108
|
+
else:
|
109
|
+
response_content = f"Command execution failed:\n\n```\n{result['error']}\n```"
|
110
|
+
|
111
|
+
else:
|
112
|
+
response_content = "Please provide code wrapped in ```python or ```bash code blocks for execution."
|
113
|
+
|
114
|
+
response = self.create_response(
|
115
|
+
content=response_content,
|
116
|
+
recipient_id=message.sender_id,
|
117
|
+
session_id=message.session_id,
|
118
|
+
conversation_id=message.conversation_id
|
119
|
+
)
|
120
|
+
|
121
|
+
self.memory.store_message(response)
|
122
|
+
return response
|
123
|
+
|
124
|
+
except Exception as e:
|
125
|
+
logging.error(f"Code executor error: {e}")
|
126
|
+
error_response = self.create_response(
|
127
|
+
content=f"Error in code execution: {str(e)}",
|
128
|
+
recipient_id=message.sender_id,
|
129
|
+
message_type=MessageType.ERROR,
|
130
|
+
session_id=message.session_id,
|
131
|
+
conversation_id=message.conversation_id
|
132
|
+
)
|
133
|
+
return error_response
|