@@ -104,80 +104,80 @@ def generate_report(analysis: str) -> str:
104104)
105105
106106
107- # -- Phase 1: Deploy, start, serve briefly, then crash --------------------
108-
109- print ("=" * 60 )
110- print ("Phase 1: Deploy + start, then simulate crash" )
111- print ("=" * 60 )
112-
113- with AgentRuntime () as runtime :
114- # Deploy the workflow definition (in production, do this once in CI/CD)
115- runtime .deploy (graph )
116- print ("Agent deployed to server." )
117-
118- # Start an execution by name — the agent is already deployed on the server,
119- # so we only need to send the name and prompt (not the full graph object).
120- handle = runtime .start (
121- "sales_analyst" ,
122- "Fetch the Q4 2025 sales data, run a full trend analysis on it, "
123- "then generate an executive summary report. "
124- "Call each tool in sequence — do not skip any step." ,
125- )
126- print (f"Execution started: { handle .execution_id } " )
127-
128- # Save execution_id so we can check status later
129- with open (SESSION_FILE , "w" ) as f :
130- f .write (handle .execution_id )
131-
132- # Serve workers just long enough for the first tool to start
133- print ("\n Serving workers briefly..." )
134- runtime .serve (graph , blocking = False )
135- time .sleep (8 )
136-
137- print ("\n Runtime closed — workers are dead, workflow persists on server." )
138- print ()
139-
140- with open (SESSION_FILE ) as f :
141- saved_execution_id = f .read ().strip ()
142-
143- # -- Pause: let the user see the stalled execution in the UI --------------
144-
145- ui_link = f"{ UI_BASE } /execution/{ saved_execution_id } "
146- print ("-" * 60 )
147- print ("Open the Conductor UI to see the execution in RUNNING state:" )
148- print (f" { ui_link } " )
149- print ()
150- print ("The workflow is alive on the server but stalled — no workers are" )
151- print ("polling to pick up the next task. The completed steps are" )
152- print ("preserved; only the remaining steps need to run." )
153- print ("-" * 60 )
154- input ("\n Press Enter to resume (restart workers)..." )
155- print ()
156-
157-
158- # -- Phase 2: Restart serve — workers pick up stalled tasks ----------------
159-
160- print ("=" * 60 )
161- print ("Phase 2: Restart serve() — workers reconnect automatically" )
162- print ("=" * 60 )
163-
164- with AgentRuntime () as runtime :
165- # serve() re-registers the same workers. The server dispatches
166- # stalled tasks to them — no resume() call needed.
167- print ("\n Serving workers (non-blocking for demo)..." )
168- runtime .serve (graph , blocking = False )
169-
170- # Poll until the execution completes
171- print (f"Polling execution: { saved_execution_id } " )
172- status = runtime .get_status (saved_execution_id )
173- while not status .is_complete :
174- time .sleep (2 )
107+ if __name__ == "__main__" :
108+ # -- Phase 1: Deploy, start, serve briefly, then crash --------------------
109+
110+ print ("=" * 60 )
111+ print ("Phase 1: Deploy + start, then simulate crash" )
112+ print ("=" * 60 )
113+
114+ with AgentRuntime () as runtime :
115+ # Deploy the workflow definition (in production, do this once in CI/CD)
116+ runtime .deploy (graph )
117+ print ("Agent deployed to server." )
118+
119+ # Start an execution by name — the agent is already deployed on the server,
120+ # so we only need to send the name and prompt (not the full graph object).
121+ handle = runtime .start (
122+ "sales_analyst" ,
123+ "Fetch the Q4 2025 sales data, run a full trend analysis on it, "
124+ "then generate an executive summary report. "
125+ "Call each tool in sequence — do not skip any step." ,
126+ )
127+ print (f"Execution started: { handle .execution_id } " )
128+
129+ # Save execution_id so we can check status later
130+ with open (SESSION_FILE , "w" ) as f :
131+ f .write (handle .execution_id )
132+
133+ # Serve workers just long enough for the first tool to start
134+ print ("\n Serving workers briefly..." )
135+ runtime .serve (graph , blocking = False )
136+ time .sleep (8 )
137+
138+ print ("\n Runtime closed — workers are dead, workflow persists on server." )
139+ print ()
140+
141+ with open (SESSION_FILE ) as f :
142+ saved_execution_id = f .read ().strip ()
143+
144+ # -- Pause: let the user see the stalled execution in the UI --------------
145+
146+ ui_link = f"{ UI_BASE } /execution/{ saved_execution_id } "
147+ print ("-" * 60 )
148+ print ("Open the Conductor UI to see the execution in RUNNING state:" )
149+ print (f" { ui_link } " )
150+ print ()
151+ print ("The workflow is alive on the server but stalled — no workers are" )
152+ print ("polling to pick up the next task. The completed steps are" )
153+ print ("preserved; only the remaining steps need to run." )
154+ print ("-" * 60 )
155+ input ("\n Press Enter to resume (restart workers)..." )
156+ print ()
157+
158+ # -- Phase 2: Restart serve — workers pick up stalled tasks ----------------
159+
160+ print ("=" * 60 )
161+ print ("Phase 2: Restart serve() — workers reconnect automatically" )
162+ print ("=" * 60 )
163+
164+ with AgentRuntime () as runtime :
165+ # serve() re-registers the same workers. The server dispatches
166+ # stalled tasks to them — no resume() call needed.
167+ print ("\n Serving workers (non-blocking for demo)..." )
168+ runtime .serve (graph , blocking = False )
169+
170+ # Poll until the execution completes
171+ print (f"Polling execution: { saved_execution_id } " )
175172 status = runtime .get_status (saved_execution_id )
176- print (f" status: { status .status } " )
173+ while not status .is_complete :
174+ time .sleep (2 )
175+ status = runtime .get_status (saved_execution_id )
176+ print (f" status: { status .status } " )
177177
178- print (f"\n Status: { status .status } " )
179- print (f"Output: { status .output } " )
180- print ("\n Check the completed execution in the UI:" )
181- print (f" { ui_link } " )
178+ print (f"\n Status: { status .status } " )
179+ print (f"Output: { status .output } " )
180+ print ("\n Check the completed execution in the UI:" )
181+ print (f" { ui_link } " )
182182
183- print ("\n Done — same workflow, seamless resume after simulated crash." )
183+ print ("\n Done — same workflow, seamless resume after simulated crash." )
0 commit comments