File size: 3,466 Bytes
e82d9c9 11888fc e82d9c9 11888fc e82d9c9 11888fc e82d9c9 11888fc e82d9c9 11888fc e82d9c9 11888fc e82d9c9 11888fc e82d9c9 11888fc e82d9c9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
"""Orchestrators package - provides different orchestration strategies.
This package implements the Strategy Pattern, allowing the application
to switch between different orchestration approaches:
- Simple: Basic search-judge loop using pydantic-ai (free tier compatible)
- Advanced: Multi-agent coordination using Microsoft Agent Framework
- Hierarchical: Sub-iteration middleware with fine-grained control
Usage:
from src.orchestrators import create_orchestrator, Orchestrator
# Auto-detect mode based on available API keys
orchestrator = create_orchestrator(search_handler, judge_handler)
# Or explicitly specify mode
orchestrator = create_orchestrator(mode="advanced", api_key="sk-...")
Protocols:
from src.orchestrators import SearchHandlerProtocol, JudgeHandlerProtocol, OrchestratorProtocol
Design Patterns Applied:
- Factory Pattern: create_orchestrator() creates appropriate orchestrator
- Strategy Pattern: Different orchestrators implement different strategies
- Facade Pattern: This __init__.py provides a clean public API
"""
from __future__ import annotations
import warnings
from typing import TYPE_CHECKING
# Protocols (Interface Segregation Principle)
from src.orchestrators.base import (
JudgeHandlerProtocol,
OrchestratorProtocol,
SearchHandlerProtocol,
)
# Factory (creational pattern)
from src.orchestrators.factory import create_orchestrator
# Orchestrators (Strategy Pattern implementations)
from src.orchestrators.simple import Orchestrator
if TYPE_CHECKING:
from src.orchestrators.advanced import AdvancedOrchestrator
from src.orchestrators.hierarchical import HierarchicalOrchestrator
# Lazy imports for optional dependencies
# These are not imported at module level to avoid breaking simple mode
# when agent-framework-core is not installed
def get_advanced_orchestrator() -> type[AdvancedOrchestrator]:
"""Get the AdvancedOrchestrator class (requires agent-framework-core).
Returns:
The AdvancedOrchestrator class
Raises:
ImportError: If agent-framework-core is not installed
"""
from src.orchestrators.advanced import AdvancedOrchestrator
return AdvancedOrchestrator
def get_hierarchical_orchestrator() -> type[HierarchicalOrchestrator]:
"""Get the HierarchicalOrchestrator class (requires agent-framework-core).
Returns:
The HierarchicalOrchestrator class
Raises:
ImportError: If agent-framework-core is not installed
"""
from src.orchestrators.hierarchical import HierarchicalOrchestrator
return HierarchicalOrchestrator
def get_magentic_orchestrator() -> type[AdvancedOrchestrator]:
"""Get the AdvancedOrchestrator class.
.. deprecated:: 0.1.0
Use :func:`get_advanced_orchestrator` instead.
The name 'magentic' was confusing with the 'magentic' PyPI package.
Returns:
The AdvancedOrchestrator class
"""
warnings.warn(
"get_magentic_orchestrator() is deprecated, use get_advanced_orchestrator() instead. "
"The name 'magentic' was confusing with the 'magentic' PyPI package.",
DeprecationWarning,
stacklevel=2,
)
return get_advanced_orchestrator()
__all__ = [
"JudgeHandlerProtocol",
"Orchestrator",
"OrchestratorProtocol",
"SearchHandlerProtocol",
"create_orchestrator",
"get_advanced_orchestrator",
"get_hierarchical_orchestrator",
"get_magentic_orchestrator",
]
|