saadpie commited on
Commit
209256a
·
verified ·
1 Parent(s): 868d895

Update server.py

Browse files
Files changed (1) hide show
  1. server.py +12 -4
server.py CHANGED
@@ -21,6 +21,12 @@ def execute_isolated_hermes(session_id: str, task: str):
21
  # Define paths to store execution logs inside the user's isolated folder
22
  log_file_path = os.path.join(session_workspace, "agent_execution.log")
23
 
 
 
 
 
 
 
24
  print(f"[Core] Spawning autonomous pipeline for Session: {session_id}")
25
 
26
  try:
@@ -31,6 +37,7 @@ def execute_isolated_hermes(session_id: str, task: str):
31
  cwd=session_workspace,
32
  stdout=log_file,
33
  stderr=log_file,
 
34
  text=True
35
  )
36
  process.wait() # Let the agent finish its execution chain safely
@@ -58,7 +65,7 @@ async def trigger_autonomous_agent(payload: AgentTask, background_tasks: Backgro
58
  "message": "Task queued. Background runner instance is up, pooling your 100 Gemini keys."
59
  }
60
 
61
- # NEW: Route to check if the agent is still running or finished
62
  @app.get("/agent/status/{session_id}")
63
  def get_agent_status(session_id: str):
64
  status = task_registry.get(session_id, "unknown/idle")
@@ -69,15 +76,16 @@ def get_agent_status(session_id: str):
69
  if os.path.exists(log_path):
70
  with open(log_path, "r") as f:
71
  # Grab the last 30 lines of execution steps so you can see what tool it's using
72
- recent_logs = f.readlines()[-30:]
 
73
 
74
  return {
75
  "session_id": session_id,
76
  "status": status,
77
- "recent_activity": "".join(recent_logs)
78
  }
79
 
80
- # NEW: Route to download any file (videos, txt, code) created by the agent
81
  @app.get("/agent/files/{session_id}/{filename}")
82
  def get_agent_file(session_id: str, filename: str):
83
  file_path = f"/workspace/sessions/{session_id}/{filename}"
 
21
  # Define paths to store execution logs inside the user's isolated folder
22
  log_file_path = os.path.join(session_workspace, "agent_execution.log")
23
 
24
+ # CRITICAL FIX: Pass environment variables to the subprocess
25
+ # This ensures Hermes knows where to find its config and credentials
26
+ worker_env = os.environ.copy()
27
+ worker_env["HOME"] = "/root"
28
+ worker_env["HERMES_HOME"] = "/root/.hermes"
29
+
30
  print(f"[Core] Spawning autonomous pipeline for Session: {session_id}")
31
 
32
  try:
 
37
  cwd=session_workspace,
38
  stdout=log_file,
39
  stderr=log_file,
40
+ env=worker_env, # Injects the config path
41
  text=True
42
  )
43
  process.wait() # Let the agent finish its execution chain safely
 
65
  "message": "Task queued. Background runner instance is up, pooling your 100 Gemini keys."
66
  }
67
 
68
+ # Route to check if the agent is still running or finished
69
  @app.get("/agent/status/{session_id}")
70
  def get_agent_status(session_id: str):
71
  status = task_registry.get(session_id, "unknown/idle")
 
76
  if os.path.exists(log_path):
77
  with open(log_path, "r") as f:
78
  # Grab the last 30 lines of execution steps so you can see what tool it's using
79
+ lines = f.readlines()
80
+ recent_logs = "".join(lines[-30:])
81
 
82
  return {
83
  "session_id": session_id,
84
  "status": status,
85
+ "recent_activity": recent_logs
86
  }
87
 
88
+ # Route to download any file (videos, txt, code) created by the agent
89
  @app.get("/agent/files/{session_id}/{filename}")
90
  def get_agent_file(session_id: str, filename: str):
91
  file_path = f"/workspace/sessions/{session_id}/{filename}"