Files
deer-flow/backend/src/subagents/registry.py

53 lines
1.6 KiB
Python
Raw Normal View History

2026-02-05 19:59:25 +08:00
"""Subagent registry for managing available subagents."""
import logging
from dataclasses import replace
2026-02-05 19:59:25 +08:00
from src.subagents.builtins import BUILTIN_SUBAGENTS
from src.subagents.config import SubagentConfig
logger = logging.getLogger(__name__)
2026-02-05 19:59:25 +08:00
def get_subagent_config(name: str) -> SubagentConfig | None:
"""Get a subagent configuration by name, with config.yaml overrides applied.
2026-02-05 19:59:25 +08:00
Args:
name: The name of the subagent.
Returns:
SubagentConfig if found (with any config.yaml overrides applied), None otherwise.
2026-02-05 19:59:25 +08:00
"""
config = BUILTIN_SUBAGENTS.get(name)
if config is None:
return None
# Apply timeout override from config.yaml (lazy import to avoid circular deps)
from src.config.subagents_config import get_subagents_app_config
app_config = get_subagents_app_config()
effective_timeout = app_config.get_timeout_for(name)
if effective_timeout != config.timeout_seconds:
logger.debug(f"Subagent '{name}': timeout overridden by config.yaml ({config.timeout_seconds}s -> {effective_timeout}s)")
config = replace(config, timeout_seconds=effective_timeout)
return config
2026-02-05 19:59:25 +08:00
def list_subagents() -> list[SubagentConfig]:
"""List all available subagent configurations (with config.yaml overrides applied).
2026-02-05 19:59:25 +08:00
Returns:
List of all registered SubagentConfig instances.
"""
return [get_subagent_config(name) for name in BUILTIN_SUBAGENTS]
2026-02-05 19:59:25 +08:00
def get_subagent_names() -> list[str]:
"""Get all available subagent names.
Returns:
List of subagent names.
"""
return list(BUILTIN_SUBAGENTS.keys())