Skip to content

refactor: Split routers/agents.py into focused routers (1777 lines) #113

Closed

Description

@vybe

Problem

src/backend/routers/agents.py is the largest backend file at 1777 lines. It contains logically distinct endpoint groups that should be separate routers:

Function CC Lines Group
rename_agent_endpoint 24 168 Agent rename
delete_agent_endpoint 21 ~60 Agent lifecycle
create_ssh_access 11 173 SSH access
get_agent_endpoint 13 ~60 Agent CRUD

Proposed Solution

Split into focused routers following the db/agents.py → mixins pattern (#102):

  1. routers/agent_ssh.py — SSH access endpoints (create_ssh_access, SSH key management) ~200 lines
  2. routers/agent_rename.py — Rename endpoint with container/DB/label updates ~200 lines
  3. routers/agent_config.py — Resource allocation, timeout, autonomy, read-only mode endpoints ~300 lines
  4. routers/agents.py — Core CRUD: create, get, list, delete, start/stop ~600 lines

All routers use the same /api/agents prefix — just organized into separate files.

Files to Change

  • src/backend/routers/agents.py — Slim from 1777 to ~600 lines
  • src/backend/routers/agent_ssh.py — NEW
  • src/backend/routers/agent_rename.py — NEW
  • src/backend/routers/agent_config.py — NEW
  • src/backend/main.py — Register new routers

Acceptance Criteria

  • routers/agents.py < 700 lines
  • Each new router < 300 lines
  • All API paths unchanged
  • All existing agent tests pass

Source

Refactor audit 2026-03-13

Metadata

Metadata

Assignees

No one assigned

    Labels

    complexity-mediumpriority-p1type-refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions