1111# Import debug functionality
1212from agentex .lib .cli .debug import DebugConfig , start_acp_server_debug , start_temporal_worker_debug
1313from agentex .lib .utils .logging import make_logger
14+ from agentex .lib .constants .ports import (
15+ REDIS_URL as _DEFAULT_REDIS_URL ,
16+ TEMPORAL_ADDRESS as _DEFAULT_TEMPORAL_ADDRESS ,
17+ )
1418from agentex .lib .cli .utils .path_utils import (
1519 get_file_paths ,
1620 calculate_uvicorn_target_for_local ,
@@ -94,16 +98,16 @@ async def start_temporal_worker_with_reload(
9498 worker_process = await start_temporal_worker (worker_path , env , manifest_dir )
9599 process_manager .add_process (worker_process )
96100 return asyncio .create_task (stream_process_output (worker_process , "WORKER" ))
97-
101+
98102 async def worker_runner () -> None :
99103 current_process : asyncio .subprocess .Process | None = None
100104 output_task : asyncio .Task [None ] | None = None
101-
105+
102106 console .print (f"[blue]Starting Temporal worker with auto-reload from { worker_path } ...[/blue]" )
103-
107+
104108 async def start_worker () -> asyncio .subprocess .Process :
105109 nonlocal current_process , output_task
106-
110+
107111 # PRE-RESTART CLEANUP - NEW!
108112 if current_process is not None :
109113 # Extract agent name from worker path for cleanup
@@ -112,7 +116,7 @@ async def start_worker() -> asyncio.subprocess.Process:
112116 console .print (f"FOUND AGENT_NAME FROM ENV VARS: { agent_name } { agent_name is None } " )
113117 if agent_name is None :
114118 agent_name = worker_path .parent .parent .name
115-
119+
116120 # Perform cleanup if configured
117121 if should_cleanup_on_restart ():
118122 console .print ("[yellow]Cleaning up workflows before worker restart...[/yellow]" )
@@ -121,7 +125,7 @@ async def start_worker() -> asyncio.subprocess.Process:
121125 except Exception as e :
122126 logger .warning (f"Cleanup failed: { e } " )
123127 console .print (f"[yellow]⚠ Cleanup failed: { str (e )} [/yellow]" )
124-
128+
125129 # Clean up previous process
126130 if current_process and current_process .returncode is None :
127131 current_process .terminate ()
@@ -130,41 +134,41 @@ async def start_worker() -> asyncio.subprocess.Process:
130134 except asyncio .TimeoutError :
131135 current_process .kill ()
132136 await current_process .wait ()
133-
137+
134138 # Cancel previous output task
135139 if output_task :
136140 output_task .cancel ()
137141 try :
138142 await output_task
139143 except asyncio .CancelledError :
140144 pass
141-
145+
142146 current_process = await start_temporal_worker (worker_path , env , manifest_dir )
143147 process_manager .add_process (current_process )
144148 console .print ("[green]Temporal worker started[/green]" )
145149 return current_process
146-
150+
147151 try :
148152 # Start initial worker
149153 current_process = await start_worker ()
150154 if current_process :
151155 output_task = asyncio .create_task (stream_process_output (current_process , "WORKER" ))
152-
156+
153157 # Watch for file changes
154158 async for changes in awatch (manifest_dir , recursive = True ):
155159 # Filter for Python files
156- py_changes = [(change , path ) for change , path in changes if str (path ).endswith (' .py' )]
157-
160+ py_changes = [(change , path ) for change , path in changes if str (path ).endswith (" .py" )]
161+
158162 if py_changes :
159163 changed_files = [str (Path (path ).relative_to (worker_path .parent )) for _ , path in py_changes ]
160164 console .print (f"[yellow]File changes detected: { changed_files } [/yellow]" )
161165 console .print ("[yellow]Restarting Temporal worker...[/yellow]" )
162-
166+
163167 # Restart worker (with cleanup handled in start_worker)
164168 await start_worker ()
165169 if current_process :
166170 output_task = asyncio .create_task (stream_process_output (current_process , "WORKER" ))
167-
171+
168172 except asyncio .CancelledError :
169173 # Clean shutdown
170174 if output_task :
@@ -173,7 +177,7 @@ async def start_worker() -> asyncio.subprocess.Process:
173177 await output_task
174178 except asyncio .CancelledError :
175179 pass
176-
180+
177181 if current_process and current_process .returncode is None :
178182 current_process .terminate ()
179183 try :
@@ -182,7 +186,7 @@ async def start_worker() -> asyncio.subprocess.Process:
182186 current_process .kill ()
183187 await current_process .wait ()
184188 raise
185-
189+
186190 return asyncio .create_task (worker_runner ())
187191
188192
@@ -192,7 +196,7 @@ async def start_acp_server(
192196 """Start the ACP server process"""
193197 # Use file path relative to manifest directory if possible
194198 uvicorn_target = calculate_uvicorn_target_for_local (acp_path , manifest_dir )
195-
199+
196200 cmd = [
197201 sys .executable ,
198202 "-m" ,
@@ -296,11 +300,17 @@ async def run_agent(manifest_path: str, debug_config: "DebugConfig | None" = Non
296300 manifest_dir = Path (manifest_path ).parent
297301 if debug_config and debug_config .should_debug_acp ():
298302 acp_process = await start_acp_server_debug (
299- file_paths ["acp" ], manifest .local_development .agent .port , agent_env , debug_config # type: ignore[union-attr]
303+ file_paths ["acp" ],
304+ manifest .local_development .agent .port ,
305+ agent_env ,
306+ debug_config , # type: ignore[union-attr]
300307 )
301308 else :
302309 acp_process = await start_acp_server (
303- file_paths ["acp" ], manifest .local_development .agent .port , agent_env , manifest_dir # type: ignore[union-attr]
310+ file_paths ["acp" ],
311+ manifest .local_development .agent .port ,
312+ agent_env ,
313+ manifest_dir , # type: ignore[union-attr]
304314 )
305315 process_manager .add_process (acp_process )
306316
@@ -313,14 +323,14 @@ async def run_agent(manifest_path: str, debug_config: "DebugConfig | None" = Non
313323 if is_temporal_agent (manifest ) and file_paths ["worker" ]:
314324 if debug_config and debug_config .should_debug_worker ():
315325 # In debug mode, start worker without auto-reload to prevent conflicts
316- worker_process = await start_temporal_worker_debug (
317- file_paths ["worker" ], agent_env , debug_config
318- )
326+ worker_process = await start_temporal_worker_debug (file_paths ["worker" ], agent_env , debug_config )
319327 process_manager .add_process (worker_process )
320328 worker_task = asyncio .create_task (stream_process_output (worker_process , "WORKER" ))
321329 else :
322330 # Normal mode with auto-reload
323- worker_task = await start_temporal_worker_with_reload (file_paths ["worker" ], agent_env , process_manager , manifest_dir )
331+ worker_task = await start_temporal_worker_with_reload (
332+ file_paths ["worker" ], agent_env , process_manager , manifest_dir
333+ )
324334 tasks .append (worker_task )
325335
326336 console .print (
@@ -333,7 +343,7 @@ async def run_agent(manifest_path: str, debug_config: "DebugConfig | None" = Non
333343 await process_manager .wait_for_shutdown ()
334344 except KeyboardInterrupt :
335345 console .print ("\n [yellow]Received shutdown signal...[/yellow]" )
336-
346+
337347 # Cancel output streaming tasks
338348 for task in tasks :
339349 task .cancel ()
@@ -351,9 +361,6 @@ async def run_agent(manifest_path: str, debug_config: "DebugConfig | None" = Non
351361 await process_manager .cleanup_processes ()
352362
353363
354-
355-
356-
357364def create_agent_environment (manifest : AgentManifest ) -> dict [str , str ]:
358365 """Create environment variables for agent processes without modifying os.environ"""
359366 # Start with current environment
@@ -364,8 +371,8 @@ def create_agent_environment(manifest: AgentManifest) -> dict[str, str]:
364371 # TODO: Combine this logic with the deploy_handlers so that we can reuse the env vars
365372 env_vars = {
366373 "ENVIRONMENT" : "development" ,
367- "TEMPORAL_ADDRESS" : "localhost:7233" ,
368- "REDIS_URL" : "redis://localhost:6379" ,
374+ "TEMPORAL_ADDRESS" : _DEFAULT_TEMPORAL_ADDRESS ,
375+ "REDIS_URL" : _DEFAULT_REDIS_URL ,
369376 "AGENT_NAME" : manifest .agent .name ,
370377 "ACP_TYPE" : manifest .agent .acp_type ,
371378 "ACP_URL" : f"http://{ manifest .local_development .agent .host_address } " , # type: ignore[union-attr]
@@ -377,6 +384,7 @@ def create_agent_environment(manifest: AgentManifest) -> dict[str, str]:
377384
378385 # Add authorization principal if set - for local development, auth is optional
379386 from agentex .lib .cli .utils .auth_utils import _encode_principal_context
387+
380388 encoded_principal = _encode_principal_context (manifest )
381389 if encoded_principal :
382390 env_vars [EnvVarKeys .AUTH_PRINCIPAL_B64 ] = encoded_principal
0 commit comments