-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
113 lines (91 loc) · 3.53 KB
/
main.py
File metadata and controls
113 lines (91 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import asyncio
import os
import sys
from dotenv import load_dotenv
from rich.console import Console
from rich.panel import Panel
from rich.text import Text
from agent.chat import ChatSession
from agent.tools import ToolRegistry
from observability.logger import setup_logging
BANNER = r"""
____ _ _ _
| _ \ ___ __| | / \ __ _ ___ _ __ | |_
| |_) / _ \/ _` | / _ \ / _` |/ _ \ '_ \| __|
| _ < __/ (_| |/ ___ \ (_| | __/ | | | |_
|_| \_\___|\__,_/_/ \_\__, |\___|_| |_|\__|
|___/
"""
def build_tool_registry() -> ToolRegistry:
"""Build and populate the tool registry with all modules."""
registry = ToolRegistry()
from proxy.pool import register_pool_tools
from proxy.checker import register_checker_tools
from proxy.discovery import register_discovery_tools
from proxy.router import register_router_tools
from proxy.proxychains import register_proxychains_tools
from security.dns_leak import register_dns_tools
from security.tls_check import register_tls_tools
from security.analyzer import register_analyzer_tools
from observability.metrics import register_metrics_tools
from proxy.scheduler import register_scheduler_tools
from proxy.executor import register_executor_tools
from proxy.active_config import register_active_config_tools
register_pool_tools(registry)
register_checker_tools(registry)
register_discovery_tools(registry)
register_router_tools(registry)
register_proxychains_tools(registry)
register_executor_tools(registry)
register_active_config_tools(registry)
register_dns_tools(registry)
register_tls_tools(registry)
register_analyzer_tools(registry)
register_metrics_tools(registry)
register_scheduler_tools(registry)
return registry
async def main():
load_dotenv()
if not os.environ.get("DEEPSEEK_API_KEY"):
print("Error: DEEPSEEK_API_KEY not found in .env file.")
sys.exit(1)
setup_logging()
console = Console()
console.print(Panel(
Text(BANNER, style="bold red", justify="center"),
title="[bold white]Proxy Management AI[/bold white]",
border_style="red",
padding=(0, 2),
))
registry = build_tool_registry()
tool_count = len(registry.get_tool_definitions())
console.print(f"[dim]{tool_count} tools loaded. Type your message to interact with RedAgent. Type 'exit' or 'quit' to leave.[/dim]\n")
session = ChatSession(console, registry)
loop = asyncio.get_running_loop()
while True:
try:
user_input = await loop.run_in_executor(
None, lambda: console.input("[bold green]You > [/bold green]")
)
except (KeyboardInterrupt, EOFError):
break
stripped = user_input.strip().lower()
if stripped in ("exit", "quit", "/quit", "/exit"):
break
if not stripped:
continue
try:
await session.send_message(user_input)
except KeyboardInterrupt:
console.print("\n[dim]Interrupted.[/dim]")
except Exception as e:
console.print(f"\n[bold red]Error:[/bold red] {type(e).__name__}: {e}\n")
# Stop scheduler if running
from proxy.scheduler import DiscoveryScheduler
scheduler = DiscoveryScheduler.get_instance()
if scheduler.running:
scheduler.stop()
console.print("[dim]Discovery scheduler stopped.[/dim]")
console.print("\n[dim]RedAgent signing off.[/dim]\n")
if __name__ == "__main__":
asyncio.run(main())