MCPcopy Create free account
hub / github.com/AutoForgeAI/autoforge / run_agent

Function run_agent

start.py:372–419  ·  view source on GitHub ↗

Run the autonomous agent with the given project. Captures stderr to detect authentication errors and provide helpful guidance. Args: project_name: Name of the project project_dir: Absolute path to the project directory

(project_name: str, project_dir: Path)

Source from the content-addressed store, hash-verified

370
371
372def run_agent(project_name: str, project_dir: Path) -> None:
373 """Run the autonomous agent with the given project.
374
375 Captures stderr to detect authentication errors and provide helpful guidance.
376
377 Args:
378 project_name: Name of the project
379 project_dir: Absolute path to the project directory
380 """
381 # Final validation before running
382 if not has_project_prompts(project_dir):
383 print(f"\nWarning: No valid spec found for project '{project_name}'")
384 print("The agent may not work correctly.")
385 confirm = input("Continue anyway? [y/N]: ").strip().lower()
386 if confirm != 'y':
387 return
388
389 print(f"\nStarting agent for project: {project_name}")
390 print(f"Location: {project_dir}")
391 print("-" * 50)
392
393 # Build the command - pass absolute path
394 cmd = [sys.executable, "autonomous_agent_demo.py", "--project-dir", str(project_dir.resolve())]
395
396 # Run the agent with stderr capture to detect auth errors
397 # stdout goes directly to terminal for real-time output
398 try:
399 result = subprocess.run(
400 cmd,
401 check=False,
402 stderr=subprocess.PIPE,
403 text=True
404 )
405
406 # Check for authentication errors
407 stderr_output = result.stderr or ""
408 if result.returncode != 0:
409 if is_auth_error(stderr_output):
410 print_auth_error_help()
411 elif stderr_output.strip():
412 # Show any other errors
413 print(f"\nAgent error:\n{stderr_output.strip()}")
414 # Still hint about auth if exit was unexpected
415 if "error" in stderr_output.lower() or "exception" in stderr_output.lower():
416 print("\nIf this is an authentication issue, try running: claude login")
417
418 except KeyboardInterrupt:
419 print("\n\nAgent interrupted. Run again to resume.")
420
421
422def main() -> None:

Callers 1

mainFunction · 0.85

Calls 3

has_project_promptsFunction · 0.90
is_auth_errorFunction · 0.90
print_auth_error_helpFunction · 0.90

Tested by

no test coverage detected