refactor: Fix code quality issues identified in analysis
1. Rename factory.py's EvoAgent data class to AgentConfig - Avoids naming conflict with base/evo_agent.py's EvoAgent 2. Export pipeline_runner functions in backend/core/__init__.py - Add create_agents, create_long_term_memory, stop_gateway 3. Consolidate PromptLoader to singleton pattern - Add get_prompt_loader() singleton function - Update all usages to use singleton Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Agent Factory - Dynamic creation and management of EvoAgents."""
|
||||
"""Agent Factory - Dynamic creation and management of AgentConfigs."""
|
||||
|
||||
import logging
|
||||
import shutil
|
||||
@@ -37,8 +37,8 @@ class RoleConfig:
|
||||
self.constraints = []
|
||||
|
||||
|
||||
class EvoAgent:
|
||||
"""Represents a configured agent instance."""
|
||||
class AgentConfig:
|
||||
"""Represents a configured agent instance (data class)."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -185,7 +185,7 @@ class AgentFactory:
|
||||
model_config: Optional[ModelConfig] = None,
|
||||
role_config: Optional[RoleConfig] = None,
|
||||
clone_from: Optional[str] = None,
|
||||
) -> EvoAgent:
|
||||
) -> AgentConfig:
|
||||
"""Create a new agent.
|
||||
|
||||
Args:
|
||||
@@ -197,7 +197,7 @@ class AgentFactory:
|
||||
clone_from: Path to existing agent to clone from (optional)
|
||||
|
||||
Returns:
|
||||
EvoAgent instance
|
||||
AgentConfig instance
|
||||
|
||||
Raises:
|
||||
ValueError: If agent already exists or workspace doesn't exist
|
||||
@@ -234,7 +234,7 @@ class AgentFactory:
|
||||
config_path = agent_dir / "agent.yaml"
|
||||
self._write_agent_yaml(config_path, agent_id, agent_type, model_config)
|
||||
|
||||
return EvoAgent(
|
||||
return AgentConfig(
|
||||
agent_id=agent_id,
|
||||
agent_type=agent_type,
|
||||
workspace_id=workspace_id,
|
||||
@@ -267,7 +267,7 @@ class AgentFactory:
|
||||
new_agent_id: str,
|
||||
target_workspace_id: Optional[str] = None,
|
||||
model_config: Optional[ModelConfig] = None,
|
||||
) -> EvoAgent:
|
||||
) -> AgentConfig:
|
||||
"""Clone an existing agent.
|
||||
|
||||
Args:
|
||||
@@ -278,7 +278,7 @@ class AgentFactory:
|
||||
model_config: Optional new model configuration
|
||||
|
||||
Returns:
|
||||
EvoAgent instance for the cloned agent
|
||||
AgentConfig instance for the cloned agent
|
||||
"""
|
||||
target_workspace_id = target_workspace_id or source_workspace_id
|
||||
source_dir = self.workspaces_root / source_workspace_id / "agents" / source_agent_id
|
||||
|
||||
@@ -6,10 +6,10 @@ from typing import Any, Optional
|
||||
|
||||
from .agent_workspace import load_agent_workspace_config
|
||||
from backend.config.bootstrap_config import get_bootstrap_config_for_run
|
||||
from .prompt_loader import PromptLoader
|
||||
from .prompt_loader import get_prompt_loader
|
||||
from .skills_manager import SkillsManager
|
||||
|
||||
_prompt_loader = PromptLoader()
|
||||
_prompt_loader = get_prompt_loader()
|
||||
|
||||
|
||||
def _read_file_if_exists(path: Path) -> str:
|
||||
|
||||
@@ -10,6 +10,17 @@ from typing import Any, Dict, Optional
|
||||
|
||||
import yaml
|
||||
|
||||
# Singleton instance
|
||||
_prompt_loader_instance: Optional["PromptLoader"] = None
|
||||
|
||||
|
||||
def get_prompt_loader() -> "PromptLoader":
|
||||
"""Get the singleton PromptLoader instance."""
|
||||
global _prompt_loader_instance
|
||||
if _prompt_loader_instance is None:
|
||||
_prompt_loader_instance = PromptLoader()
|
||||
return _prompt_loader_instance
|
||||
|
||||
|
||||
class PromptLoader:
|
||||
"""Unified Prompt loader"""
|
||||
|
||||
Reference in New Issue
Block a user