MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / main

Function main

src/harness/agentic_loop/run_loop.py:100–158  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

98
99
100def main():
101 from harness.paths import ensure_runtime_dirs, init_run_env
102
103 load_dotenv(find_dotenv(), override=True)
104 ensure_runtime_dirs()
105 _run_id, host_run = init_run_env("agentic_loop")
106 args = parse_args()
107
108 output_dir = (
109 str(Path(args.output_dir).expanduser().resolve())
110 if args.output_dir
111 else str(host_run)
112 )
113 Path(output_dir).mkdir(parents=True, exist_ok=True)
114
115 # Build MCP URL from env or args
116 mcp_url = args.mcp_url
117 if not mcp_url:
118 hostname = os.getenv("MCP_HOSTNAME", "localhost")
119 port = os.getenv("MCP_PORT", "7002")
120 basepath = os.getenv("MCP_BASEPATH", "/mcp")
121 mcp_url = f"http://{hostname}:{port}{basepath}"
122
123 config = LoopConfig(
124 model=args.model,
125 mcp_url=mcp_url,
126 max_turns=args.max_turns,
127 temperature=args.temperature,
128 output_dir=output_dir,
129 plan_generator_model=args.plan_generator_model,
130 plan_executor_model=args.plan_executor_model,
131 )
132
133 mcp_client = MCPClient(url=config.mcp_url)
134 llm_client = LLMClient()
135
136 # Mirror host layout inside the container: /workspace/outputs/<run_name>/.
137 host_out = Path(output_dir)
138 sandbox_out = f"outputs/{host_out.name}"
139
140 logger = Logger(
141 mcp_client,
142 log_file=f"{sandbox_out}/agent_run.log",
143 to_stdout=True,
144 host_log_path=host_out / "agent_run.log",
145 event_log_path=f"{sandbox_out}/agent_events.log",
146 host_event_log_path=host_out / "agent_events.log",
147 )
148
149 loop = AgenticLoop(mcp_client, llm_client, config, logger)
150
151 try:
152 if args.task:
153 result = loop.run(args.task, plan_mode=args.plan_mode)
154 print(result)
155 else:
156 loop.run_interactive()
157 finally:

Callers 1

run_loop.pyFile · 0.70

Calls 12

runMethod · 0.95
run_interactiveMethod · 0.95
closeMethod · 0.95
ensure_runtime_dirsFunction · 0.90
init_run_envFunction · 0.90
MCPClientClass · 0.90
LLMClientClass · 0.90
LoggerClass · 0.90
LoopConfigClass · 0.85
AgenticLoopClass · 0.85
resolveMethod · 0.80
parse_argsFunction · 0.70

Tested by

no test coverage detected