File size: 3,561 Bytes
cd7c282 e82d9c9 cd7c282 e82d9c9 cd7c282 e82d9c9 cd7c282 e82d9c9 cd7c282 e82d9c9 cd7c282 e82d9c9 cd7c282 e82d9c9 11888fc e82d9c9 cd7c282 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 113 |
"""Orchestrators package - Unified Architecture (SPEC-16).
This package implements the Strategy Pattern with a unified orchestration approach:
- Advanced: Multi-agent coordination using Microsoft Agent Framework (DEFAULT)
- Backend auto-selects: OpenAI (if key) β HuggingFace (free fallback)
- Hierarchical: Sub-iteration middleware with fine-grained control
Unified Architecture (SPEC-16):
All users get Advanced Mode. The chat client factory auto-selects the backend:
- With OpenAI key β OpenAIChatClient (GPT-5)
- Without key β HuggingFaceChatClient (Llama 3.1 70B, free tier)
Usage:
from src.orchestrators import create_orchestrator
# Creates AdvancedOrchestrator with auto-selected backend
orchestrator = create_orchestrator()
# Or with explicit API key
orchestrator = create_orchestrator(api_key="sk-...")
Protocols:
from src.orchestrators import SearchHandlerProtocol, JudgeHandlerProtocol, OrchestratorProtocol
Design Patterns Applied:
- Factory Pattern: create_orchestrator() creates appropriate orchestrator
- Adapter Pattern: HuggingFaceChatClient adapts HF API to BaseChatClient
- Strategy Pattern: Different backends (OpenAI, HuggingFace) via ChatClientFactory
- 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
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",
"OrchestratorProtocol",
"SearchHandlerProtocol",
"create_orchestrator",
"get_advanced_orchestrator",
"get_hierarchical_orchestrator",
"get_magentic_orchestrator",
]
|