Skip to content

Commit 1bf72ef

Browse files
committed
Adding changes to support temporal auto reload + fixing where you cant ctrl+c
1 parent a24a254 commit 1bf72ef

File tree

6 files changed

+1044
-902
lines changed

6 files changed

+1044
-902
lines changed

examples/tutorials/10_agentic/10_temporal/010_agent_chat/project/run_worker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ async def main():
2222
worker = AgentexWorker(
2323
task_queue=task_queue_name,
2424
)
25-
25+
2626
await worker.run(
2727
activities=get_all_activities(),
2828
workflow=At010AgentChatWorkflow,

examples/tutorials/10_agentic/10_temporal/010_agent_chat/project/workflow.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ async def on_task_event_send(self, params: SendEventParams) -> None:
7070

7171
if not params.event.content:
7272
return
73-
7473
if params.event.content.type != "text":
7574
raise ValueError(f"Expected text message, got {params.event.content.type}")
7675

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencies = [
1919
"rich>=13.9.2,<14",
2020
"fastapi>=0.115.0,<0.116",
2121
"uvicorn>=0.31.1",
22+
"watchfiles>=0.24.0,<1.0",
2223
"python-on-whales>=0.73.0,<0.74",
2324
"pyyaml>=6.0.2,<7",
2425
"jsonschema>=4.23.0,<5",

src/agentex/lib/cli/handlers/agent_handlers.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,32 @@ def build_agent(
129129
def run_agent(manifest_path: str):
130130
"""Run an agent locally from the given manifest"""
131131
import asyncio
132-
132+
import signal
133+
import sys
134+
135+
# Flag to track if we're shutting down
136+
shutting_down = False
137+
138+
def signal_handler(signum, frame):
139+
"""Handle signals by raising KeyboardInterrupt"""
140+
nonlocal shutting_down
141+
if shutting_down:
142+
# If we're already shutting down and get another signal, force exit
143+
print(f"\nForce exit on signal {signum}")
144+
sys.exit(1)
145+
146+
shutting_down = True
147+
print(f"\nReceived signal {signum}, shutting down...")
148+
raise KeyboardInterrupt()
149+
150+
# Set up signal handling for the main thread
151+
signal.signal(signal.SIGINT, signal_handler)
152+
signal.signal(signal.SIGTERM, signal_handler)
153+
133154
try:
134155
asyncio.run(_run_agent(manifest_path))
156+
except KeyboardInterrupt:
157+
print("Shutdown completed.")
158+
sys.exit(0)
135159
except RunError as e:
136160
raise RuntimeError(str(e)) from e

0 commit comments

Comments
 (0)