astraagent 2.25.6
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.
- package/.env.template +22 -0
- package/LICENSE +21 -0
- package/README.md +333 -0
- package/astra/__init__.py +15 -0
- package/astra/__pycache__/__init__.cpython-314.pyc +0 -0
- package/astra/__pycache__/chat.cpython-314.pyc +0 -0
- package/astra/__pycache__/cli.cpython-314.pyc +0 -0
- package/astra/__pycache__/prompts.cpython-314.pyc +0 -0
- package/astra/__pycache__/updater.cpython-314.pyc +0 -0
- package/astra/chat.py +763 -0
- package/astra/cli.py +913 -0
- package/astra/core/__init__.py +8 -0
- package/astra/core/__pycache__/__init__.cpython-314.pyc +0 -0
- package/astra/core/__pycache__/agent.cpython-314.pyc +0 -0
- package/astra/core/__pycache__/config.cpython-314.pyc +0 -0
- package/astra/core/__pycache__/memory.cpython-314.pyc +0 -0
- package/astra/core/__pycache__/reasoning.cpython-314.pyc +0 -0
- package/astra/core/__pycache__/state.cpython-314.pyc +0 -0
- package/astra/core/agent.py +515 -0
- package/astra/core/config.py +247 -0
- package/astra/core/memory.py +782 -0
- package/astra/core/reasoning.py +423 -0
- package/astra/core/state.py +366 -0
- package/astra/core/voice.py +144 -0
- package/astra/llm/__init__.py +32 -0
- package/astra/llm/__pycache__/__init__.cpython-314.pyc +0 -0
- package/astra/llm/__pycache__/providers.cpython-314.pyc +0 -0
- package/astra/llm/providers.py +530 -0
- package/astra/planning/__init__.py +117 -0
- package/astra/prompts.py +289 -0
- package/astra/reflection/__init__.py +181 -0
- package/astra/search.py +469 -0
- package/astra/tasks.py +466 -0
- package/astra/tools/__init__.py +17 -0
- package/astra/tools/__pycache__/__init__.cpython-314.pyc +0 -0
- package/astra/tools/__pycache__/advanced.cpython-314.pyc +0 -0
- package/astra/tools/__pycache__/base.cpython-314.pyc +0 -0
- package/astra/tools/__pycache__/browser.cpython-314.pyc +0 -0
- package/astra/tools/__pycache__/file.cpython-314.pyc +0 -0
- package/astra/tools/__pycache__/git.cpython-314.pyc +0 -0
- package/astra/tools/__pycache__/memory_tool.cpython-314.pyc +0 -0
- package/astra/tools/__pycache__/python.cpython-314.pyc +0 -0
- package/astra/tools/__pycache__/shell.cpython-314.pyc +0 -0
- package/astra/tools/__pycache__/web.cpython-314.pyc +0 -0
- package/astra/tools/__pycache__/windows.cpython-314.pyc +0 -0
- package/astra/tools/advanced.py +251 -0
- package/astra/tools/base.py +344 -0
- package/astra/tools/browser.py +93 -0
- package/astra/tools/file.py +476 -0
- package/astra/tools/git.py +74 -0
- package/astra/tools/memory_tool.py +89 -0
- package/astra/tools/python.py +238 -0
- package/astra/tools/shell.py +183 -0
- package/astra/tools/web.py +804 -0
- package/astra/tools/windows.py +542 -0
- package/astra/updater.py +450 -0
- package/astra/utils/__init__.py +230 -0
- package/bin/astraagent.js +73 -0
- package/bin/postinstall.js +25 -0
- package/config.json.template +52 -0
- package/main.py +16 -0
- package/package.json +51 -0
- package/pyproject.toml +72 -0
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Configuration management for AstraAgent.
|
|
3
|
+
Handles all agent settings, API keys, and runtime parameters.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
import os
|
|
7
|
+
import json
|
|
8
|
+
from dataclasses import dataclass, field, asdict
|
|
9
|
+
from typing import Optional, Dict, Any, List
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from enum import Enum
|
|
12
|
+
|
|
13
|
+
# Load environment variables from .env file
|
|
14
|
+
try:
|
|
15
|
+
from dotenv import load_dotenv
|
|
16
|
+
load_dotenv()
|
|
17
|
+
except ImportError:
|
|
18
|
+
# If python-dotenv not installed, just use os.getenv
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class LogLevel(Enum):
|
|
23
|
+
"""Logging verbosity levels."""
|
|
24
|
+
DEBUG = "debug"
|
|
25
|
+
INFO = "info"
|
|
26
|
+
WARNING = "warning"
|
|
27
|
+
ERROR = "error"
|
|
28
|
+
CRITICAL = "critical"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ExecutionMode(Enum):
|
|
32
|
+
"""Agent execution modes."""
|
|
33
|
+
AUTONOMOUS = "autonomous" # Fully autonomous
|
|
34
|
+
SUPERVISED = "supervised" # Requires approval for actions
|
|
35
|
+
INTERACTIVE = "interactive" # Step-by-step with user
|
|
36
|
+
DRY_RUN = "dry_run" # Simulate without execution
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass
|
|
40
|
+
class LLMConfig:
|
|
41
|
+
"""Configuration for the LLM backend - Local Server."""
|
|
42
|
+
provider: str = "local"
|
|
43
|
+
model: str = "default"
|
|
44
|
+
api_key: Optional[str] = None
|
|
45
|
+
api_base: Optional[str] = None
|
|
46
|
+
temperature: float = 0.7
|
|
47
|
+
max_tokens: int = 4096
|
|
48
|
+
top_p: float = 1.0
|
|
49
|
+
frequency_penalty: float = 0.0
|
|
50
|
+
presence_penalty: float = 0.0
|
|
51
|
+
timeout: int = 120
|
|
52
|
+
max_retries: int = 3
|
|
53
|
+
|
|
54
|
+
def __post_init__(self):
|
|
55
|
+
# Try to get API key from environment if not provided
|
|
56
|
+
if not self.api_key:
|
|
57
|
+
self.api_key = os.getenv("LOCAL_API_KEY")
|
|
58
|
+
if not self.api_base:
|
|
59
|
+
self.api_base = os.getenv("LOCAL_API_BASE") or "http://localhost:8000/api/v1"
|
|
60
|
+
|
|
61
|
+
def validate(self) -> None:
|
|
62
|
+
"""Validate configuration is complete."""
|
|
63
|
+
if not self.api_key or not self.api_key.strip():
|
|
64
|
+
raise ValueError(
|
|
65
|
+
"LOCAL_API_KEY is not set. Please:\n"
|
|
66
|
+
" 1. Copy .env.template to .env\n"
|
|
67
|
+
" 2. Set LOCAL_API_KEY=your-key in .env\n"
|
|
68
|
+
" Or set environment variable:\n"
|
|
69
|
+
f" Windows: set LOCAL_API_KEY=your-key\n"
|
|
70
|
+
f" Linux/Mac: export LOCAL_API_KEY=your-key"
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
@dataclass
|
|
75
|
+
class ToolConfig:
|
|
76
|
+
"""Configuration for tool system."""
|
|
77
|
+
enabled_tools: List[str] = field(default_factory=lambda: ["all"])
|
|
78
|
+
disabled_tools: List[str] = field(default_factory=list)
|
|
79
|
+
tool_timeout: int = 300
|
|
80
|
+
max_tool_retries: int = 2
|
|
81
|
+
sandbox_enabled: bool = True
|
|
82
|
+
allow_shell_commands: bool = True
|
|
83
|
+
allow_network_access: bool = True
|
|
84
|
+
allow_file_write: bool = True
|
|
85
|
+
restricted_paths: List[str] = field(default_factory=list)
|
|
86
|
+
allowed_extensions: List[str] = field(default_factory=lambda: [
|
|
87
|
+
".py", ".js", ".ts", ".json", ".yaml", ".yml", ".md",
|
|
88
|
+
".txt", ".html", ".css", ".sh", ".bat", ".ps1"
|
|
89
|
+
])
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@dataclass
|
|
93
|
+
class MemoryConfig:
|
|
94
|
+
"""Configuration for memory system."""
|
|
95
|
+
enabled: bool = True
|
|
96
|
+
max_short_term_items: int = 100
|
|
97
|
+
max_long_term_items: int = 10000
|
|
98
|
+
persistence_path: Optional[str] = None
|
|
99
|
+
auto_save: bool = True
|
|
100
|
+
save_interval: int = 60 # seconds
|
|
101
|
+
embedding_model: str = "text-embedding-3-small"
|
|
102
|
+
similarity_threshold: float = 0.75
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@dataclass
|
|
106
|
+
class SafetyConfig:
|
|
107
|
+
"""Configuration for safety guardrails."""
|
|
108
|
+
enabled: bool = True
|
|
109
|
+
max_actions_per_task: int = 100
|
|
110
|
+
max_execution_time: int = 3600 # 1 hour
|
|
111
|
+
require_approval_for: List[str] = field(default_factory=lambda: [
|
|
112
|
+
"shell_dangerous",
|
|
113
|
+
"file_delete",
|
|
114
|
+
"network_external",
|
|
115
|
+
"system_modify"
|
|
116
|
+
])
|
|
117
|
+
blocked_commands: List[str] = field(default_factory=lambda: [
|
|
118
|
+
"rm -rf /",
|
|
119
|
+
"format",
|
|
120
|
+
"mkfs",
|
|
121
|
+
"dd if=",
|
|
122
|
+
":(){:|:&};:",
|
|
123
|
+
])
|
|
124
|
+
allowed_domains: List[str] = field(default_factory=list) # Empty = all allowed
|
|
125
|
+
max_file_size_mb: int = 100
|
|
126
|
+
enable_content_filter: bool = True
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@dataclass
|
|
130
|
+
class LoggingConfig:
|
|
131
|
+
"""Configuration for logging."""
|
|
132
|
+
level: LogLevel = LogLevel.INFO
|
|
133
|
+
log_to_file: bool = True
|
|
134
|
+
log_to_console: bool = True
|
|
135
|
+
log_directory: str = "./logs"
|
|
136
|
+
max_log_files: int = 10
|
|
137
|
+
log_format: str = "%(asctime)s | %(levelname)s | %(name)s | %(message)s"
|
|
138
|
+
include_timestamps: bool = True
|
|
139
|
+
include_tool_outputs: bool = True
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@dataclass
|
|
143
|
+
class AgentConfig:
|
|
144
|
+
"""Master configuration for AstraAgent."""
|
|
145
|
+
# Identity
|
|
146
|
+
name: str = "AstraAgent"
|
|
147
|
+
version: str = "1.0.0"
|
|
148
|
+
description: str = "Autonomous AI Agent"
|
|
149
|
+
|
|
150
|
+
# Execution
|
|
151
|
+
mode: ExecutionMode = ExecutionMode.AUTONOMOUS
|
|
152
|
+
max_iterations: int = 50
|
|
153
|
+
reflection_enabled: bool = True
|
|
154
|
+
planning_enabled: bool = True
|
|
155
|
+
self_correction_enabled: bool = True
|
|
156
|
+
|
|
157
|
+
# Workspace
|
|
158
|
+
workspace_path: str = "./"
|
|
159
|
+
artifacts_path: str = "./artifacts"
|
|
160
|
+
temp_path: str = "./temp"
|
|
161
|
+
|
|
162
|
+
# Sub-configurations
|
|
163
|
+
llm: LLMConfig = field(default_factory=LLMConfig)
|
|
164
|
+
tools: ToolConfig = field(default_factory=ToolConfig)
|
|
165
|
+
memory: MemoryConfig = field(default_factory=MemoryConfig)
|
|
166
|
+
safety: SafetyConfig = field(default_factory=SafetyConfig)
|
|
167
|
+
logging: LoggingConfig = field(default_factory=LoggingConfig)
|
|
168
|
+
|
|
169
|
+
# Advanced
|
|
170
|
+
parallel_execution: bool = False
|
|
171
|
+
max_parallel_tasks: int = 4
|
|
172
|
+
enable_caching: bool = True
|
|
173
|
+
cache_ttl: int = 3600
|
|
174
|
+
|
|
175
|
+
def __post_init__(self):
|
|
176
|
+
"""Initialize paths and validate configuration."""
|
|
177
|
+
# Create necessary directories
|
|
178
|
+
for path_attr in ['workspace_path', 'artifacts_path', 'temp_path']:
|
|
179
|
+
path = Path(getattr(self, path_attr))
|
|
180
|
+
path.mkdir(parents=True, exist_ok=True)
|
|
181
|
+
|
|
182
|
+
# Set memory persistence path if not set
|
|
183
|
+
if self.memory.enabled and not self.memory.persistence_path:
|
|
184
|
+
self.memory.persistence_path = str(Path(self.workspace_path) / ".astra_memory")
|
|
185
|
+
|
|
186
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
187
|
+
"""Convert config to dictionary."""
|
|
188
|
+
return asdict(self)
|
|
189
|
+
|
|
190
|
+
def save(self, path: str):
|
|
191
|
+
"""Save configuration to JSON file."""
|
|
192
|
+
with open(path, 'w') as f:
|
|
193
|
+
json.dump(self.to_dict(), f, indent=2, default=str)
|
|
194
|
+
|
|
195
|
+
@classmethod
|
|
196
|
+
def load(cls, path: str) -> 'AgentConfig':
|
|
197
|
+
"""Load configuration from JSON file."""
|
|
198
|
+
with open(path, 'r') as f:
|
|
199
|
+
data = json.load(f)
|
|
200
|
+
return cls.from_dict(data)
|
|
201
|
+
|
|
202
|
+
@classmethod
|
|
203
|
+
def from_dict(cls, data: Dict[str, Any]) -> 'AgentConfig':
|
|
204
|
+
"""Create config from dictionary."""
|
|
205
|
+
# Handle nested configs
|
|
206
|
+
if 'llm' in data and isinstance(data['llm'], dict):
|
|
207
|
+
data['llm'] = LLMConfig(**data['llm'])
|
|
208
|
+
if 'tools' in data and isinstance(data['tools'], dict):
|
|
209
|
+
data['tools'] = ToolConfig(**data['tools'])
|
|
210
|
+
if 'memory' in data and isinstance(data['memory'], dict):
|
|
211
|
+
data['memory'] = MemoryConfig(**data['memory'])
|
|
212
|
+
if 'safety' in data and isinstance(data['safety'], dict):
|
|
213
|
+
data['safety'] = SafetyConfig(**data['safety'])
|
|
214
|
+
if 'logging' in data and isinstance(data['logging'], dict):
|
|
215
|
+
if 'level' in data['logging']:
|
|
216
|
+
data['logging']['level'] = LogLevel(data['logging']['level'])
|
|
217
|
+
data['logging'] = LoggingConfig(**data['logging'])
|
|
218
|
+
if 'mode' in data:
|
|
219
|
+
data['mode'] = ExecutionMode(data['mode'])
|
|
220
|
+
|
|
221
|
+
return cls(**data)
|
|
222
|
+
|
|
223
|
+
@classmethod
|
|
224
|
+
def from_env(cls) -> 'AgentConfig':
|
|
225
|
+
"""Create config from environment variables."""
|
|
226
|
+
config = cls()
|
|
227
|
+
|
|
228
|
+
# Override from environment
|
|
229
|
+
if os.getenv("ASTRA_MODE"):
|
|
230
|
+
config.mode = ExecutionMode(os.getenv("ASTRA_MODE"))
|
|
231
|
+
if os.getenv("ASTRA_WORKSPACE"):
|
|
232
|
+
config.workspace_path = os.getenv("ASTRA_WORKSPACE")
|
|
233
|
+
if os.getenv("ASTRA_MODEL"):
|
|
234
|
+
config.llm.model = os.getenv("ASTRA_MODEL")
|
|
235
|
+
if os.getenv("ASTRA_PROVIDER"):
|
|
236
|
+
config.llm.provider = os.getenv("ASTRA_PROVIDER")
|
|
237
|
+
|
|
238
|
+
# Check for Local Server API key
|
|
239
|
+
if os.getenv("LOCAL_API_KEY"):
|
|
240
|
+
config.llm.api_key = os.getenv("LOCAL_API_KEY")
|
|
241
|
+
if os.getenv("LOCAL_API_BASE"):
|
|
242
|
+
config.llm.api_base = os.getenv("LOCAL_API_BASE")
|
|
243
|
+
|
|
244
|
+
if os.getenv("ASTRA_MAX_ITERATIONS"):
|
|
245
|
+
config.max_iterations = int(os.getenv("ASTRA_MAX_ITERATIONS"))
|
|
246
|
+
|
|
247
|
+
return config
|