mirror of
https://github.com/furyhawk/agent_alpha.git
synced 2026-07-21 10:35:34 +00:00
2.5 KiB
2.5 KiB
name, description, metadata
| name | description | metadata | ||
|---|---|---|---|---|
| agent-refactor-plan | Plan to refactor backend/core/agent.py to follow Repository+Service pattern and agents.md guidelines. |
|
Context
The current implementation of /backend/core/agent.py violates the "Repository + Service" architecture described in docs/architecture.md. It contains heavy configuration logic, mixed business logic (RAG tool building), and direct filesystem persistence logic. The goal is to refactor this into a clean, layered architecture as specified in the new agents.md.
Proposed Approach
I will refactor the agent system by extracting concerns into their respective layers:
- Factory Layer: Extract initialization logic (Logfire, model providers) from
AgentServiceinto a newAgentFactoryinbackend/services/. - Repository Layer: Create a
MemoryRepositoryto handle local filesystem persistence for the agent's memory. - RAG Service: Move RAG tool construction out of the core agent logic and into a dedicated
RAGService. - Thin Core: Refactor
AgentServicein/backend/core/agent.pyto act as a thin orchestrator that receives pre-configured agents and dependencies via injection.
Implementation Steps
Phase 1: Infrastructure Setup
- Create
backend/repositories/memory_repository.pyto encapsulateLocalBackendlogic. - Create
backend/services/agent_factory.pyto house the complex initialization logic currently inAgentService.initialize. - Create
backend/services/rag_service.pyto handle RAG tool construction.
Phase 2: Core Refactoring
- Modify
backend/core/agent.py:- Remove
LocalBackendand path resolution (Move toMemoryRepository). - Remove initialization logic (Move to
AgentFactory). - Remove
_build_rag_tools(Move toRAGService). - Update
AgentServiceto accept a pre-constructed agent and dependencies.
- Remove
Phase 3: Dependency Injection & Integration
- Update FastAPI routes or the main entry point to use the new
AgentFactoryandRAGService. - Ensure all tools in the
Skillsystem are correctly registered via the new services.
Critical Files
backend/core/agent.pybackend/services/agent_factory.pybackend/repositories/memory_repository.pybackend/services/rag_service.py
Verification
- Run
make runto ensure the backend starts. - Test the
askendpoint to verify that the agent still responds with correct RAG results and memory persistence. - Verify that the new
AgentFactorycorrectly initializes all subagents and skills as before.