-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathtest_orchestrator_real.py
More file actions
181 lines (150 loc) · 6.15 KB
/
test_orchestrator_real.py
File metadata and controls
181 lines (150 loc) · 6.15 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
#!/usr/bin/env python3
import asyncio
import os
import sys
from multi_agent_coding_system.misc.async_docker_container_manager import AsyncDockerContainerManager
# Add parent directory to path to enable src imports
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import time
import uuid
import tempfile
import shutil
from multi_agent_coding_system.agents.env_interaction.command_executor import DockerExecutor
from multi_agent_coding_system.agents.orchestrator_agent import OrchestratorAgent
from pathlib import Path
async def test_orchestator_simple_task(
instruction: str, run_id: str, temperature=0.1, logging_dir=None
):
"""Test orchestrator with a simple task.
Args:
instruction: The task instruction to execute
temperature: LLM temperature setting
logging_dir: Optional directory for turn-by-turn logging
"""
# Generate unique container name
container_name = f"test_orchestrator_{run_id}"
# Set up logging directory if requested
if logging_dir:
logging_path = Path(logging_dir)
logging_path.mkdir(exist_ok=True, parents=True)
print(f"Logging turns to: {logging_path}")
else:
logging_path = None
# Create temporary directory for Dockerfile
temp_dir = tempfile.mkdtemp(prefix="test_orchestrator_")
dockerfile_content = """FROM ubuntu:latest
RUN apt-get update && apt-get install -y bash
WORKDIR /workspace
CMD ["/bin/bash"]
"""
# Initialize the Docker manager
manager = AsyncDockerContainerManager()
container_id = None
try:
# Write Dockerfile to temp directory
dockerfile_path = Path(temp_dir) / "Dockerfile"
dockerfile_path.write_text(dockerfile_content)
# Start Docker container using the manager
print(f"Starting Docker container with image: {container_name}")
await manager._ensure_initialized()
container_id = await manager.spin_up_container_from_dir(
build_context_dir=temp_dir,
image_name=container_name
)
print(f"Container started with ID: {container_id}")
# Wait a moment for container to stabilize
await asyncio.sleep(1)
# Use container ID instead of name for DockerExecutor
# Note: DockerExecutor expects container name, but we can use ID
executor = DockerExecutor(container_id)
orchestrator = OrchestratorAgent(
temperature=temperature,
)
orchestrator.setup(executor, logging_dir=logging_path, session_id=run_id)
print("\nExecuting task...")
result = await orchestrator.run(instruction, max_turns=15)
# Display results
print(f"\n{'=' * 40}")
print("EXECUTION RESULT:")
print(f"{'=' * 40}")
print(f"Completed: {result['completed']}")
print(f"Finish message: {result['finish_message']}")
print(f"Turns executed: {result['turns_executed']}")
print(f"Max turns reached: {result['max_turns_reached']}")
# Check if files were created in container
print(f"\n{'=' * 40}")
print("VERIFICATION:")
print(f"{'=' * 40}")
# Check 5 txt files exist using the manager's execute_command
stdout, stderr = await manager.execute_command(
container_id=container_id,
command="cd /workspace && ls *.txt 2>/dev/null | wc -l"
)
num_text_files = stdout.strip() if stdout else "0"
if num_text_files and int(num_text_files) >= 5:
print(f"✓ Found {num_text_files} .txt files in /workspace")
else:
print(f"✗ Expected 5 .txt files, but found {num_text_files}")
stdout, stderr = await manager.execute_command(
container_id=container_id,
command="cd /workspace && ls -l"
)
print(" - Listing files in /workspace:")
print(stdout)
return result
finally:
# Clean up Docker container and temporary directory
try:
if container_id:
print(f"\nStopping and removing container: {container_id}")
await manager.close_container(container_id)
await manager.close()
except Exception as e:
print(f"Error cleaning up container: {e}")
# Clean up temp directory
try:
shutil.rmtree(temp_dir)
except Exception as e:
print(f"Error cleaning up temp directory: {e}")
async def main():
"""Main test runner."""
os.environ["LITE_LLM_API_KEY"] = "" # TODO: Set this
os.environ["ORCA_ORCHESTRATOR_MODEL"] = (
"openrouter/qwen/qwen3-14b"
# "openrouter/qwen/qwen3-30b-a3b"
# "openrouter/openai/gpt-5"
# "openrouter/nvidia/nemotron-nano-9b-v2"
# "openrouter/qwen/qwen3-8b"
# "openrouter/microsoft/phi-4-reasoning-plus"
# "openrouter/meta-llama/llama-3.3-8b-instruct"
# "openrouter/mistralai/devstral-small"
# "openrouter/microsoft/phi-4"
# "openrouter/nvidia/nemotron-nano-9b-v2"
# "openrouter/arcee-ai/afm-4.5b"
# "openrouter/qwen/qwen3-30b-a3b-instruct-2507"
# "openrouter/qwen/qwen3-next-80b-a3b-instruct"
# "openrouter/qwen/qwen3-coder"
# "openrouter/qwen/qwen3-coder-30b-a3b-instruct"
# "openrouter/qwen/qwen3-32b"
)
os.environ["ORCA_SUBAGENT_MODEL"] = (
"openrouter/qwen/qwen3-coder-30b-a3b-instruct"
# "openrouter/nvidia/nemotron-nano-9b-v2"
# "openrouter/openai/gpt-5"
# "openrouter/x-ai/grok-code-fast-1"
# "openrouter/qwen/qwen3-coder"
# "openrouter/qwen/qwen3-32b"
# "openrouter/qwen/qwen3-next-80b-a3b-instruct"
)
instruction = (
"Create 5 txt files, each with a poem about a different programming language."
)
time_stamp_dd_mm_hh_mm = time.strftime("%d_%H%M", time.localtime())
run_id = time_stamp_dd_mm_hh_mm + uuid.uuid4().hex[:8]
logging_dir = f"./session_logs/"
result = await test_orchestator_simple_task(
instruction=instruction, run_id=run_id, temperature=0.7, logging_dir=logging_dir
)
print(f"\nFinal result: {result}")
if __name__ == "__main__":
asyncio.run(main())