mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-02-01 15:03:36 +00:00
Enable the orchestrator to assign 1-3 features per coding agent subprocess, selected via dependency chain extension + same-category fill. This reduces cold-start overhead and leverages shared context across related features. Orchestrator (parallel_orchestrator.py): - Add batch tracking: _batch_features and _feature_to_primary data structures - Add build_feature_batches() with dependency chain + category fill algorithm - Add start_feature_batch() and _spawn_coding_agent_batch() methods - Update _on_agent_complete() for batch cleanup across all features - Update stop_feature() with _feature_to_primary lookup - Update get_ready_features() to exclude all batch feature IDs - Update main loop to build batches then spawn per available slot CLI and agent layer: - Add --feature-ids (comma-separated) and --batch-size CLI args - Add feature_ids parameter to run_autonomous_agent() with batch prompt selection - Add get_batch_feature_prompt() with sequential workflow instructions WebSocket layer (server/websocket.py): - Add BATCH_CODING_AGENT_START_PATTERN and BATCH_FEATURES_COMPLETE_PATTERN - Add _handle_batch_agent_start() and _handle_batch_agent_complete() methods - Add featureIds field to all agent_update messages - Track current_feature_id updates as agent moves through batch Frontend (React UI): - Add featureIds to ActiveAgent and WSAgentUpdateMessage types - Update KanbanColumn and DependencyGraph agent-feature maps for batch - Update AgentCard to show "Batch: #X, #Y, #Z" with active feature highlight - Add "Features per Agent" segmented control (1-3) in SettingsModal Settings integration (full stack): - Add batch_size to schemas, settings router, agent router, process manager - Default batch_size=3, user-configurable 1-3 via settings UI - batch_size=1 is functionally identical to pre-batching behavior Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
178 lines
5.6 KiB
Python
178 lines
5.6 KiB
Python
"""
|
|
Agent Router
|
|
============
|
|
|
|
API endpoints for agent control (start/stop/pause/resume).
|
|
Uses project registry for path lookups.
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
|
|
from ..schemas import AgentActionResponse, AgentStartRequest, AgentStatus
|
|
from ..services.chat_constants import ROOT_DIR
|
|
from ..services.process_manager import get_manager
|
|
from ..utils.project_helpers import get_project_path as _get_project_path
|
|
from ..utils.validation import validate_project_name
|
|
|
|
|
|
def _get_settings_defaults() -> tuple[bool, str, int, bool, int]:
|
|
"""Get defaults from global settings.
|
|
|
|
Returns:
|
|
Tuple of (yolo_mode, model, testing_agent_ratio, playwright_headless, batch_size)
|
|
"""
|
|
import sys
|
|
root = Path(__file__).parent.parent.parent
|
|
if str(root) not in sys.path:
|
|
sys.path.insert(0, str(root))
|
|
|
|
from registry import DEFAULT_MODEL, get_all_settings
|
|
|
|
settings = get_all_settings()
|
|
yolo_mode = (settings.get("yolo_mode") or "false").lower() == "true"
|
|
model = settings.get("model", DEFAULT_MODEL)
|
|
|
|
# Parse testing agent settings with defaults
|
|
try:
|
|
testing_agent_ratio = int(settings.get("testing_agent_ratio", "1"))
|
|
except (ValueError, TypeError):
|
|
testing_agent_ratio = 1
|
|
|
|
playwright_headless = (settings.get("playwright_headless") or "true").lower() == "true"
|
|
|
|
try:
|
|
batch_size = int(settings.get("batch_size", "3"))
|
|
except (ValueError, TypeError):
|
|
batch_size = 3
|
|
|
|
return yolo_mode, model, testing_agent_ratio, playwright_headless, batch_size
|
|
|
|
|
|
router = APIRouter(prefix="/api/projects/{project_name}/agent", tags=["agent"])
|
|
|
|
|
|
def get_project_manager(project_name: str):
|
|
"""Get the process manager for a project."""
|
|
project_name = validate_project_name(project_name)
|
|
project_dir = _get_project_path(project_name)
|
|
|
|
if not project_dir:
|
|
raise HTTPException(status_code=404, detail=f"Project '{project_name}' not found in registry")
|
|
|
|
if not project_dir.exists():
|
|
raise HTTPException(status_code=404, detail=f"Project directory not found: {project_dir}")
|
|
|
|
return get_manager(project_name, project_dir, ROOT_DIR)
|
|
|
|
|
|
@router.get("/status", response_model=AgentStatus)
|
|
async def get_agent_status(project_name: str):
|
|
"""Get the current status of the agent for a project."""
|
|
manager = get_project_manager(project_name)
|
|
|
|
# Run healthcheck to detect crashed processes
|
|
await manager.healthcheck()
|
|
|
|
return AgentStatus(
|
|
status=manager.status,
|
|
pid=manager.pid,
|
|
started_at=manager.started_at.isoformat() if manager.started_at else None,
|
|
yolo_mode=manager.yolo_mode,
|
|
model=manager.model,
|
|
parallel_mode=manager.parallel_mode,
|
|
max_concurrency=manager.max_concurrency,
|
|
testing_agent_ratio=manager.testing_agent_ratio,
|
|
)
|
|
|
|
|
|
@router.post("/start", response_model=AgentActionResponse)
|
|
async def start_agent(
|
|
project_name: str,
|
|
request: AgentStartRequest = AgentStartRequest(),
|
|
):
|
|
"""Start the agent for a project."""
|
|
manager = get_project_manager(project_name)
|
|
|
|
# Get defaults from global settings if not provided in request
|
|
default_yolo, default_model, default_testing_ratio, playwright_headless, default_batch_size = _get_settings_defaults()
|
|
|
|
yolo_mode = request.yolo_mode if request.yolo_mode is not None else default_yolo
|
|
model = request.model if request.model else default_model
|
|
max_concurrency = request.max_concurrency or 1
|
|
testing_agent_ratio = request.testing_agent_ratio if request.testing_agent_ratio is not None else default_testing_ratio
|
|
|
|
batch_size = default_batch_size
|
|
|
|
success, message = await manager.start(
|
|
yolo_mode=yolo_mode,
|
|
model=model,
|
|
max_concurrency=max_concurrency,
|
|
testing_agent_ratio=testing_agent_ratio,
|
|
playwright_headless=playwright_headless,
|
|
batch_size=batch_size,
|
|
)
|
|
|
|
# Notify scheduler of manual start (to prevent auto-stop during scheduled window)
|
|
if success:
|
|
from ..services.scheduler_service import get_scheduler
|
|
project_dir = _get_project_path(project_name)
|
|
if project_dir:
|
|
get_scheduler().notify_manual_start(project_name, project_dir)
|
|
|
|
return AgentActionResponse(
|
|
success=success,
|
|
status=manager.status,
|
|
message=message,
|
|
)
|
|
|
|
|
|
@router.post("/stop", response_model=AgentActionResponse)
|
|
async def stop_agent(project_name: str):
|
|
"""Stop the agent for a project."""
|
|
manager = get_project_manager(project_name)
|
|
|
|
success, message = await manager.stop()
|
|
|
|
# Notify scheduler of manual stop (to prevent auto-start during scheduled window)
|
|
if success:
|
|
from ..services.scheduler_service import get_scheduler
|
|
project_dir = _get_project_path(project_name)
|
|
if project_dir:
|
|
get_scheduler().notify_manual_stop(project_name, project_dir)
|
|
|
|
return AgentActionResponse(
|
|
success=success,
|
|
status=manager.status,
|
|
message=message,
|
|
)
|
|
|
|
|
|
@router.post("/pause", response_model=AgentActionResponse)
|
|
async def pause_agent(project_name: str):
|
|
"""Pause the agent for a project."""
|
|
manager = get_project_manager(project_name)
|
|
|
|
success, message = await manager.pause()
|
|
|
|
return AgentActionResponse(
|
|
success=success,
|
|
status=manager.status,
|
|
message=message,
|
|
)
|
|
|
|
|
|
@router.post("/resume", response_model=AgentActionResponse)
|
|
async def resume_agent(project_name: str):
|
|
"""Resume a paused agent."""
|
|
manager = get_project_manager(project_name)
|
|
|
|
success, message = await manager.resume()
|
|
|
|
return AgentActionResponse(
|
|
success=success,
|
|
status=manager.status,
|
|
message=message,
|
|
)
|