-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__main__.py
More file actions
188 lines (146 loc) · 5.03 KB
/
__main__.py
File metadata and controls
188 lines (146 loc) · 5.03 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
"""Main entry point for the MultiCoder system.
This module provides the entry point for running the complete
MultiCoder system with all agents or individual components.
"""
import argparse
import asyncio
import logging
import os
import sys
from typing import List, Optional
# Ajouter le répertoire parent au chemin de recherche de Python
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
from config.settings import get_config
from core.agents import Coordinator, CodeGenerator, CodeValidator
from utils.logging import configure_logger as configure_logging
async def run_coordinator(log_level: str) -> None:
"""Run the coordinator agent.
Args:
log_level: Logging level.
"""
# Import here to avoid circular imports
from core.mcp.bus import message_bus
# Start the MCP bus first
await message_bus.start()
# Create and start the agent
agent = Coordinator(log_level=getattr(logging, log_level))
await agent.start()
try:
# Keep running until interrupted
while True:
await asyncio.sleep(1)
except (KeyboardInterrupt, asyncio.CancelledError):
print("\nStopping coordinator...")
finally:
await agent.stop()
await message_bus.stop()
async def run_generator(log_level: str) -> None:
"""Run the code generator agent.
Args:
log_level: Logging level.
"""
# Import here to avoid circular imports
from core.mcp.bus import message_bus
# Start the MCP bus first
await message_bus.start()
# Create and start the agent
agent = CodeGenerator(log_level=getattr(logging, log_level))
await agent.start()
try:
# Keep running until interrupted
while True:
await asyncio.sleep(1)
except (KeyboardInterrupt, asyncio.CancelledError):
print("\nStopping code generator...")
finally:
await agent.stop()
await message_bus.stop()
async def run_validator(log_level: str) -> None:
"""Run the code validator agent.
Args:
log_level: Logging level.
"""
# Import here to avoid circular imports
from core.mcp.bus import message_bus
# Start the MCP bus first
await message_bus.start()
# Create and start the agent
agent = CodeValidator(log_level=getattr(logging, log_level))
await agent.start()
try:
# Keep running until interrupted
while True:
await asyncio.sleep(1)
except (KeyboardInterrupt, asyncio.CancelledError):
print("\nStopping code validator...")
finally:
await agent.stop()
await message_bus.stop()
async def run_all(log_level: str) -> None:
"""Run all the agents together.
Args:
log_level: Logging level.
"""
# Import here to avoid circular imports
from core.mcp.bus import message_bus
# Create all agents
coordinator = Coordinator(log_level=getattr(logging, log_level))
generator = CodeGenerator(log_level=getattr(logging, log_level))
validator = CodeValidator(log_level=getattr(logging, log_level))
# Start the MCP bus first
await message_bus.start()
# Start all agents
await coordinator.start()
await generator.start()
await validator.start()
print("\n🤖 MultiCoder system running (Press Ctrl+C to stop)")
try:
# Keep running until interrupted
while True:
await asyncio.sleep(1)
except (KeyboardInterrupt, asyncio.CancelledError):
print("\nStopping all agents...")
finally:
# Stop all agents
await validator.stop()
await generator.stop()
await coordinator.stop()
# Stop the MCP bus last
await message_bus.stop()
def parse_args() -> argparse.Namespace:
"""Parse command line arguments.
Returns:
Parsed arguments.
"""
config = get_config()
parser = argparse.ArgumentParser(description="MultiCoder: Multi-agent code generation system")
parser.add_argument(
"--component", "-c",
type=str,
choices=["all", "coordinator", "generator", "validator"],
default="all",
help="Component to run (default: all)"
)
parser.add_argument(
"--log-level",
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
default=config["logging"]["level"],
help=f"Set logging level (default: {config['logging']['level']})"
)
return parser.parse_args()
async def main() -> None:
"""Main entry point for the application."""
args = parse_args()
# Configure logging
configure_logging("multicoder", args.log_level)
# Run the selected component
if args.component == "coordinator":
await run_coordinator(args.log_level)
elif args.component == "generator":
await run_generator(args.log_level)
elif args.component == "validator":
await run_validator(args.log_level)
else: # all
await run_all(args.log_level)
if __name__ == "__main__":
asyncio.run(main())