flock-core 0.4.528__py3-none-any.whl → 0.5.0b0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of flock-core might be problematic. Click here for more details.
- flock/cli/execute_flock.py +1 -1
- flock/cli/manage_agents.py +6 -6
- flock/components/__init__.py +30 -0
- flock/components/evaluation/__init__.py +9 -0
- flock/components/evaluation/declarative_evaluation_component.py +222 -0
- flock/components/routing/__init__.py +15 -0
- flock/{routers/conditional/conditional_router.py → components/routing/conditional_routing_component.py} +61 -53
- flock/components/routing/default_routing_component.py +103 -0
- flock/components/routing/llm_routing_component.py +206 -0
- flock/components/utility/__init__.py +15 -0
- flock/{modules/enterprise_memory/enterprise_memory_module.py → components/utility/memory_utility_component.py} +195 -173
- flock/{modules/performance/metrics_module.py → components/utility/metrics_utility_component.py} +110 -95
- flock/{modules/output/output_module.py → components/utility/output_utility_component.py} +47 -45
- flock/core/__init__.py +26 -18
- flock/core/agent/__init__.py +16 -0
- flock/core/agent/flock_agent_components.py +104 -0
- flock/core/agent/flock_agent_execution.py +101 -0
- flock/core/agent/flock_agent_integration.py +206 -0
- flock/core/agent/flock_agent_lifecycle.py +177 -0
- flock/core/agent/flock_agent_serialization.py +381 -0
- flock/core/api/endpoints.py +2 -2
- flock/core/api/service.py +2 -2
- flock/core/component/__init__.py +15 -0
- flock/core/{flock_module.py → component/agent_component_base.py} +136 -34
- flock/core/component/evaluation_component.py +56 -0
- flock/core/component/routing_component.py +74 -0
- flock/core/component/utility_component.py +69 -0
- flock/core/config/flock_agent_config.py +49 -2
- flock/core/evaluation/utils.py +3 -2
- flock/core/execution/batch_executor.py +1 -1
- flock/core/execution/evaluation_executor.py +2 -2
- flock/core/execution/opik_executor.py +1 -1
- flock/core/flock.py +147 -493
- flock/core/flock_agent.py +195 -1032
- flock/core/flock_factory.py +114 -90
- flock/core/flock_scheduler.py +1 -1
- flock/core/flock_server_manager.py +8 -8
- flock/core/logging/logging.py +1 -0
- flock/core/mcp/flock_mcp_server.py +53 -48
- flock/core/mcp/{flock_mcp_tool_base.py → flock_mcp_tool.py} +2 -2
- flock/core/mcp/mcp_client.py +9 -9
- flock/core/mcp/mcp_client_manager.py +9 -9
- flock/core/mcp/mcp_config.py +24 -24
- flock/core/mixin/dspy_integration.py +5 -5
- flock/core/orchestration/__init__.py +18 -0
- flock/core/orchestration/flock_batch_processor.py +94 -0
- flock/core/orchestration/flock_evaluator.py +113 -0
- flock/core/orchestration/flock_execution.py +288 -0
- flock/core/orchestration/flock_initialization.py +125 -0
- flock/core/orchestration/flock_server_manager.py +67 -0
- flock/core/orchestration/flock_web_server.py +117 -0
- flock/core/registry/__init__.py +45 -0
- flock/core/registry/agent_registry.py +69 -0
- flock/core/registry/callable_registry.py +139 -0
- flock/core/registry/component_discovery.py +142 -0
- flock/core/registry/component_registry.py +64 -0
- flock/core/registry/config_mapping.py +64 -0
- flock/core/registry/decorators.py +137 -0
- flock/core/registry/registry_hub.py +205 -0
- flock/core/registry/server_registry.py +57 -0
- flock/core/registry/type_registry.py +86 -0
- flock/core/serialization/flock_serializer.py +36 -32
- flock/core/serialization/serialization_utils.py +28 -25
- flock/core/util/hydrator.py +1 -1
- flock/core/util/input_resolver.py +29 -2
- flock/mcp/servers/sse/flock_sse_server.py +10 -10
- flock/mcp/servers/stdio/flock_stdio_server.py +10 -10
- flock/mcp/servers/streamable_http/flock_streamable_http_server.py +10 -10
- flock/mcp/servers/websockets/flock_websocket_server.py +10 -10
- flock/platform/docker_tools.py +3 -3
- flock/webapp/app/chat.py +1 -1
- flock/webapp/app/main.py +9 -5
- flock/webapp/app/services/flock_service.py +1 -1
- flock/webapp/app/services/sharing_store.py +1 -0
- flock/workflow/activities.py +67 -92
- flock/workflow/agent_execution_activity.py +6 -6
- flock/workflow/flock_workflow.py +1 -1
- flock_core-0.5.0b0.dist-info/METADATA +272 -0
- {flock_core-0.4.528.dist-info → flock_core-0.5.0b0.dist-info}/RECORD +82 -95
- flock/core/flock_evaluator.py +0 -60
- flock/core/flock_registry.py +0 -702
- flock/core/flock_router.py +0 -83
- flock/evaluators/__init__.py +0 -1
- flock/evaluators/declarative/__init__.py +0 -1
- flock/evaluators/declarative/declarative_evaluator.py +0 -217
- flock/evaluators/memory/memory_evaluator.py +0 -90
- flock/evaluators/test/test_case_evaluator.py +0 -38
- flock/evaluators/zep/zep_evaluator.py +0 -59
- flock/modules/__init__.py +0 -1
- flock/modules/assertion/__init__.py +0 -1
- flock/modules/assertion/assertion_module.py +0 -286
- flock/modules/callback/__init__.py +0 -1
- flock/modules/callback/callback_module.py +0 -91
- flock/modules/enterprise_memory/README.md +0 -99
- flock/modules/mem0/__init__.py +0 -1
- flock/modules/mem0/mem0_module.py +0 -126
- flock/modules/mem0_async/__init__.py +0 -1
- flock/modules/mem0_async/async_mem0_module.py +0 -126
- flock/modules/memory/__init__.py +0 -1
- flock/modules/memory/memory_module.py +0 -429
- flock/modules/memory/memory_parser.py +0 -125
- flock/modules/memory/memory_storage.py +0 -736
- flock/modules/output/__init__.py +0 -1
- flock/modules/performance/__init__.py +0 -1
- flock/modules/zep/__init__.py +0 -1
- flock/modules/zep/zep_module.py +0 -192
- flock/routers/__init__.py +0 -1
- flock/routers/agent/__init__.py +0 -1
- flock/routers/agent/agent_router.py +0 -236
- flock/routers/agent/handoff_agent.py +0 -58
- flock/routers/default/__init__.py +0 -1
- flock/routers/default/default_router.py +0 -80
- flock/routers/feedback/feedback_router.py +0 -114
- flock/routers/list_generator/list_generator_router.py +0 -166
- flock/routers/llm/__init__.py +0 -1
- flock/routers/llm/llm_router.py +0 -365
- flock/tools/__init__.py +0 -0
- flock/tools/azure_tools.py +0 -781
- flock/tools/code_tools.py +0 -167
- flock/tools/file_tools.py +0 -149
- flock/tools/github_tools.py +0 -157
- flock/tools/markdown_tools.py +0 -205
- flock/tools/system_tools.py +0 -9
- flock/tools/text_tools.py +0 -810
- flock/tools/web_tools.py +0 -90
- flock/tools/zendesk_tools.py +0 -147
- flock_core-0.4.528.dist-info/METADATA +0 -675
- {flock_core-0.4.528.dist-info → flock_core-0.5.0b0.dist-info}/WHEEL +0 -0
- {flock_core-0.4.528.dist-info → flock_core-0.5.0b0.dist-info}/entry_points.txt +0 -0
- {flock_core-0.4.528.dist-info → flock_core-0.5.0b0.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# src/flock/core/registry/decorators.py
|
|
2
|
+
"""Registry decorators for component, tool, and type registration."""
|
|
3
|
+
|
|
4
|
+
import inspect
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from typing import Any, TypeVar, overload
|
|
7
|
+
|
|
8
|
+
from flock.core.registry.registry_hub import get_registry
|
|
9
|
+
|
|
10
|
+
ClassType = TypeVar("ClassType", bound=type)
|
|
11
|
+
FuncType = TypeVar("FuncType", bound=Callable)
|
|
12
|
+
ConfigType = TypeVar("ConfigType")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# --- Component Registration Decorator ---
|
|
16
|
+
|
|
17
|
+
@overload
|
|
18
|
+
def flock_component(cls: ClassType) -> ClassType: ... # Basic registration
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@overload
|
|
22
|
+
def flock_component(
|
|
23
|
+
*, name: str | None = None, config_class: type[ConfigType] | None = None
|
|
24
|
+
) -> Callable[[ClassType], ClassType]: ... # With options
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def flock_component(
|
|
28
|
+
cls: ClassType | None = None,
|
|
29
|
+
*,
|
|
30
|
+
name: str | None = None,
|
|
31
|
+
config_class: type[ConfigType] | None = None,
|
|
32
|
+
) -> Any:
|
|
33
|
+
"""Decorator to register a Flock Component class and optionally link its config class."""
|
|
34
|
+
registry = get_registry()
|
|
35
|
+
|
|
36
|
+
def decorator(inner_cls: ClassType) -> ClassType:
|
|
37
|
+
if not inspect.isclass(inner_cls):
|
|
38
|
+
raise TypeError("@flock_component can only decorate classes.")
|
|
39
|
+
|
|
40
|
+
component_name = name or inner_cls.__name__
|
|
41
|
+
registry.register_component(inner_cls, name=component_name)
|
|
42
|
+
|
|
43
|
+
# If config_class is provided, register the mapping
|
|
44
|
+
if config_class:
|
|
45
|
+
registry.register_config_component_pair(config_class, inner_cls)
|
|
46
|
+
|
|
47
|
+
return inner_cls
|
|
48
|
+
|
|
49
|
+
if cls is None:
|
|
50
|
+
# Called as @flock_component(name="...", config_class=...)
|
|
51
|
+
return decorator
|
|
52
|
+
else:
|
|
53
|
+
# Called as @flock_component
|
|
54
|
+
return decorator(cls)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# --- Tool/Callable Registration Decorator ---
|
|
58
|
+
|
|
59
|
+
@overload
|
|
60
|
+
def flock_tool(func: FuncType) -> FuncType: ...
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@overload
|
|
64
|
+
def flock_tool(
|
|
65
|
+
*, name: str | None = None
|
|
66
|
+
) -> Callable[[FuncType], FuncType]: ...
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def flock_tool(func: FuncType | None = None, *, name: str | None = None) -> Any:
|
|
70
|
+
"""Decorator to register a callable function/method as a Tool (or general callable).
|
|
71
|
+
|
|
72
|
+
Usage:
|
|
73
|
+
@flock_tool
|
|
74
|
+
def my_web_search(query: str): ...
|
|
75
|
+
|
|
76
|
+
@flock_tool(name="utils.calculate_pi")
|
|
77
|
+
def compute_pi(): ...
|
|
78
|
+
"""
|
|
79
|
+
registry = get_registry()
|
|
80
|
+
|
|
81
|
+
def decorator(inner_func: FuncType) -> FuncType:
|
|
82
|
+
if not callable(inner_func):
|
|
83
|
+
raise TypeError("@flock_tool can only decorate callables.")
|
|
84
|
+
# Let registry handle default name generation if None
|
|
85
|
+
registry.register_callable(inner_func, name=name)
|
|
86
|
+
return inner_func
|
|
87
|
+
|
|
88
|
+
if func is None:
|
|
89
|
+
# Called as @flock_tool(name="...")
|
|
90
|
+
return decorator
|
|
91
|
+
else:
|
|
92
|
+
# Called as @flock_tool
|
|
93
|
+
return decorator(func)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
# Alias for clarity
|
|
97
|
+
flock_callable = flock_tool
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
# --- Type Registration Decorator ---
|
|
101
|
+
|
|
102
|
+
@overload
|
|
103
|
+
def flock_type(cls: ClassType) -> ClassType: ...
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@overload
|
|
107
|
+
def flock_type(
|
|
108
|
+
*, name: str | None = None
|
|
109
|
+
) -> Callable[[ClassType], ClassType]: ...
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def flock_type(cls: ClassType | None = None, *, name: str | None = None) -> Any:
|
|
113
|
+
"""Decorator to register a Type (Pydantic Model, Dataclass) used in signatures.
|
|
114
|
+
|
|
115
|
+
Usage:
|
|
116
|
+
@flock_type
|
|
117
|
+
class MyDataModel(BaseModel): ...
|
|
118
|
+
|
|
119
|
+
@flock_type(name="UserInput")
|
|
120
|
+
@dataclass
|
|
121
|
+
class UserQuery: ...
|
|
122
|
+
"""
|
|
123
|
+
registry = get_registry()
|
|
124
|
+
|
|
125
|
+
def decorator(inner_cls: ClassType) -> ClassType:
|
|
126
|
+
if not inspect.isclass(inner_cls):
|
|
127
|
+
raise TypeError("@flock_type can only decorate classes.")
|
|
128
|
+
type_name = name or inner_cls.__name__
|
|
129
|
+
registry.register_type(inner_cls, name=type_name)
|
|
130
|
+
return inner_cls
|
|
131
|
+
|
|
132
|
+
if cls is None:
|
|
133
|
+
# Called as @flock_type(name="...")
|
|
134
|
+
return decorator
|
|
135
|
+
else:
|
|
136
|
+
# Called as @flock_type
|
|
137
|
+
return decorator(cls)
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# src/flock/core/registry/registry_hub.py
|
|
2
|
+
"""Main registry hub using composition pattern with thread safety."""
|
|
3
|
+
|
|
4
|
+
import threading
|
|
5
|
+
from typing import TYPE_CHECKING, Any, TypeVar
|
|
6
|
+
|
|
7
|
+
from flock.core.logging.logging import get_logger
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from collections.abc import Callable
|
|
11
|
+
|
|
12
|
+
from flock.core.flock_agent import FlockAgent
|
|
13
|
+
from flock.core.mcp.flock_mcp_server import FlockMCPServer
|
|
14
|
+
|
|
15
|
+
logger = get_logger("registry.hub")
|
|
16
|
+
|
|
17
|
+
T = TypeVar("T")
|
|
18
|
+
ConfigType = TypeVar("ConfigType")
|
|
19
|
+
ClassType = TypeVar("ClassType")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class RegistryHub:
|
|
23
|
+
"""Thread-safe registry hub using composition pattern.
|
|
24
|
+
|
|
25
|
+
Main coordinator for all registry types following the successful
|
|
26
|
+
pattern from Flock and FlockAgent refactoring.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__(self):
|
|
30
|
+
self._lock = threading.RLock()
|
|
31
|
+
logger.debug("RegistryHub initialized with thread safety")
|
|
32
|
+
|
|
33
|
+
# --- Lazy-loaded composition helpers (following Flock pattern) ---
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def components(self):
|
|
37
|
+
"""Component class registry helper."""
|
|
38
|
+
if not hasattr(self, '_components_helper'):
|
|
39
|
+
from flock.core.registry.component_registry import ComponentRegistry
|
|
40
|
+
self._components_helper = ComponentRegistry(self._lock)
|
|
41
|
+
return self._components_helper
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def callables(self):
|
|
45
|
+
"""Callable registry helper."""
|
|
46
|
+
if not hasattr(self, '_callables_helper'):
|
|
47
|
+
from flock.core.registry.callable_registry import CallableRegistry
|
|
48
|
+
self._callables_helper = CallableRegistry(self._lock)
|
|
49
|
+
return self._callables_helper
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def agents(self):
|
|
53
|
+
"""Agent registry helper."""
|
|
54
|
+
if not hasattr(self, '_agents_helper'):
|
|
55
|
+
from flock.core.registry.agent_registry import AgentRegistry
|
|
56
|
+
self._agents_helper = AgentRegistry(self._lock)
|
|
57
|
+
return self._agents_helper
|
|
58
|
+
|
|
59
|
+
@property
|
|
60
|
+
def servers(self):
|
|
61
|
+
"""Server registry helper."""
|
|
62
|
+
if not hasattr(self, '_servers_helper'):
|
|
63
|
+
from flock.core.registry.server_registry import ServerRegistry
|
|
64
|
+
self._servers_helper = ServerRegistry(self._lock)
|
|
65
|
+
return self._servers_helper
|
|
66
|
+
|
|
67
|
+
@property
|
|
68
|
+
def types(self):
|
|
69
|
+
"""Type registry helper."""
|
|
70
|
+
if not hasattr(self, '_types_helper'):
|
|
71
|
+
from flock.core.registry.type_registry import TypeRegistry
|
|
72
|
+
self._types_helper = TypeRegistry(self._lock)
|
|
73
|
+
return self._types_helper
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def config_mapping(self):
|
|
77
|
+
"""Config mapping helper."""
|
|
78
|
+
if not hasattr(self, '_config_mapping_helper'):
|
|
79
|
+
from flock.core.registry.config_mapping import ConfigMapping
|
|
80
|
+
self._config_mapping_helper = ConfigMapping(self._lock)
|
|
81
|
+
return self._config_mapping_helper
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def discovery(self):
|
|
85
|
+
"""Component discovery helper."""
|
|
86
|
+
if not hasattr(self, '_discovery_helper'):
|
|
87
|
+
from flock.core.registry.component_discovery import (
|
|
88
|
+
ComponentDiscovery,
|
|
89
|
+
)
|
|
90
|
+
self._discovery_helper = ComponentDiscovery(self)
|
|
91
|
+
return self._discovery_helper
|
|
92
|
+
|
|
93
|
+
# --- High-level registry operations (delegate to helpers) ---
|
|
94
|
+
|
|
95
|
+
def register_agent(self, agent: "FlockAgent", *, force: bool = False) -> None:
|
|
96
|
+
"""Register a FlockAgent instance."""
|
|
97
|
+
self.agents.register_agent(agent, force=force)
|
|
98
|
+
|
|
99
|
+
def get_agent(self, name: str) -> "FlockAgent | None":
|
|
100
|
+
"""Get a registered FlockAgent instance by name."""
|
|
101
|
+
return self.agents.get_agent(name)
|
|
102
|
+
|
|
103
|
+
def get_all_agent_names(self) -> list[str]:
|
|
104
|
+
"""Get all registered agent names."""
|
|
105
|
+
return self.agents.get_all_agent_names()
|
|
106
|
+
|
|
107
|
+
def register_server(self, server: "FlockMCPServer") -> None:
|
|
108
|
+
"""Register a FlockMCPServer instance."""
|
|
109
|
+
self.servers.register_server(server)
|
|
110
|
+
|
|
111
|
+
def get_server(self, name: str) -> "FlockMCPServer | None":
|
|
112
|
+
"""Get a registered FlockMCPServer instance by name."""
|
|
113
|
+
return self.servers.get_server(name)
|
|
114
|
+
|
|
115
|
+
def get_all_server_names(self) -> list[str]:
|
|
116
|
+
"""Get all registered server names."""
|
|
117
|
+
return self.servers.get_all_server_names()
|
|
118
|
+
|
|
119
|
+
def register_callable(self, func: "Callable", name: str | None = None) -> str | None:
|
|
120
|
+
"""Register a callable function/method."""
|
|
121
|
+
return self.callables.register_callable(func, name)
|
|
122
|
+
|
|
123
|
+
def get_callable(self, name_or_path: str) -> "Callable":
|
|
124
|
+
"""Get a registered callable by name or path."""
|
|
125
|
+
return self.callables.get_callable(name_or_path)
|
|
126
|
+
|
|
127
|
+
def get_callable_path_string(self, func: "Callable") -> str | None:
|
|
128
|
+
"""Get the path string for a callable."""
|
|
129
|
+
return self.callables.get_callable_path_string(func)
|
|
130
|
+
|
|
131
|
+
def register_type(self, type_obj: type, name: str | None = None) -> str | None:
|
|
132
|
+
"""Register a type (Pydantic Model, Dataclass, etc.)."""
|
|
133
|
+
return self.types.register_type(type_obj, name)
|
|
134
|
+
|
|
135
|
+
def get_type(self, type_name: str) -> type:
|
|
136
|
+
"""Get a registered type by name."""
|
|
137
|
+
return self.types.get_type(type_name)
|
|
138
|
+
|
|
139
|
+
def register_component(self, component_class: type, name: str | None = None) -> str | None:
|
|
140
|
+
"""Register a component class."""
|
|
141
|
+
return self.components.register_component(component_class, name)
|
|
142
|
+
|
|
143
|
+
def get_component(self, type_name: str) -> type:
|
|
144
|
+
"""Get a registered component class by name."""
|
|
145
|
+
return self.components.get_component(type_name)
|
|
146
|
+
|
|
147
|
+
def get_component_type_name(self, component_class: type) -> str | None:
|
|
148
|
+
"""Get the type name for a component class."""
|
|
149
|
+
return self.components.get_component_type_name(component_class)
|
|
150
|
+
|
|
151
|
+
def register_config_component_pair(self, config_cls: type[ConfigType], component_cls: type[ClassType]) -> None:
|
|
152
|
+
"""Register a config-to-component mapping."""
|
|
153
|
+
self.config_mapping.register_config_component_pair(config_cls, component_cls)
|
|
154
|
+
|
|
155
|
+
def get_component_class_for_config(self, config_cls: type[ConfigType]) -> type[ClassType] | None:
|
|
156
|
+
"""Get the component class for a config class."""
|
|
157
|
+
return self.config_mapping.get_component_class_for_config(config_cls)
|
|
158
|
+
|
|
159
|
+
def discover_and_register_components(self) -> None:
|
|
160
|
+
"""Auto-discover and register components from known packages."""
|
|
161
|
+
self.discovery.discover_and_register_components()
|
|
162
|
+
|
|
163
|
+
def register_module_components(self, module_or_path: Any) -> None:
|
|
164
|
+
"""Register components from a specific module."""
|
|
165
|
+
self.discovery.register_module_components(module_or_path)
|
|
166
|
+
|
|
167
|
+
# --- Utility methods ---
|
|
168
|
+
|
|
169
|
+
def clear_all(self) -> None:
|
|
170
|
+
"""Clear all registries (useful for testing)."""
|
|
171
|
+
with self._lock:
|
|
172
|
+
if hasattr(self, '_agents_helper'):
|
|
173
|
+
self.agents.clear()
|
|
174
|
+
if hasattr(self, '_servers_helper'):
|
|
175
|
+
self.servers.clear()
|
|
176
|
+
if hasattr(self, '_callables_helper'):
|
|
177
|
+
self.callables.clear()
|
|
178
|
+
if hasattr(self, '_types_helper'):
|
|
179
|
+
self.types.clear()
|
|
180
|
+
if hasattr(self, '_components_helper'):
|
|
181
|
+
self.components.clear()
|
|
182
|
+
if hasattr(self, '_config_mapping_helper'):
|
|
183
|
+
self.config_mapping.clear_config_mappings()
|
|
184
|
+
logger.debug("Cleared all registries")
|
|
185
|
+
|
|
186
|
+
def get_registry_summary(self) -> dict[str, int]:
|
|
187
|
+
"""Get a summary of all registries."""
|
|
188
|
+
with self._lock:
|
|
189
|
+
return {
|
|
190
|
+
"agents": len(self.agents.get_all_agents()),
|
|
191
|
+
"servers": len(self.servers.get_all_servers()),
|
|
192
|
+
"callables": len(self.callables.get_all_callables()),
|
|
193
|
+
"types": len(self.types.get_all_types()),
|
|
194
|
+
"components": len(self.components.get_all_components()),
|
|
195
|
+
"config_mappings": len(self.config_mapping.get_all_config_mappings()),
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
# --- Global singleton instance ---
|
|
200
|
+
_default_registry_hub = RegistryHub()
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def get_registry() -> RegistryHub:
|
|
204
|
+
"""Get the default thread-safe registry hub instance."""
|
|
205
|
+
return _default_registry_hub
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# src/flock/core/registry/server_registry.py
|
|
2
|
+
"""MCP Server registration and lookup functionality."""
|
|
3
|
+
|
|
4
|
+
import threading
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from flock.core.logging.logging import get_logger
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
from flock.core.mcp.flock_mcp_server import FlockMCPServer
|
|
11
|
+
|
|
12
|
+
logger = get_logger("registry.servers")
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ServerRegistry:
|
|
16
|
+
"""Manages FlockMCPServerBase registration and lookup with thread safety."""
|
|
17
|
+
|
|
18
|
+
def __init__(self, lock: threading.RLock):
|
|
19
|
+
self._lock = lock
|
|
20
|
+
self._servers: dict[str, FlockMCPServer] = {}
|
|
21
|
+
|
|
22
|
+
def register_server(self, server: "FlockMCPServer") -> None:
|
|
23
|
+
"""Register a flock mcp server by its name."""
|
|
24
|
+
if not hasattr(server.config, "name") or not server.config.name:
|
|
25
|
+
logger.error("Attempted to register a server without a valid 'name' attribute.")
|
|
26
|
+
return
|
|
27
|
+
|
|
28
|
+
with self._lock:
|
|
29
|
+
if server.config.name in self._servers and self._servers[server.config.name] != server:
|
|
30
|
+
logger.warning(f"Server '{server.config.name}' already registered. Overwriting.")
|
|
31
|
+
|
|
32
|
+
self._servers[server.config.name] = server
|
|
33
|
+
logger.debug(f"Registered server: {server.config.name}")
|
|
34
|
+
|
|
35
|
+
def get_server(self, name: str) -> "FlockMCPServer | None":
|
|
36
|
+
"""Retrieve a registered FlockMCPServer instance by name."""
|
|
37
|
+
with self._lock:
|
|
38
|
+
server = self._servers.get(name)
|
|
39
|
+
if not server:
|
|
40
|
+
logger.warning(f"Server '{name}' not found in registry.")
|
|
41
|
+
return server
|
|
42
|
+
|
|
43
|
+
def get_all_server_names(self) -> list[str]:
|
|
44
|
+
"""Return a list of names for all registered servers."""
|
|
45
|
+
with self._lock:
|
|
46
|
+
return list(self._servers.keys())
|
|
47
|
+
|
|
48
|
+
def get_all_servers(self) -> dict[str, "FlockMCPServer"]:
|
|
49
|
+
"""Get all registered servers."""
|
|
50
|
+
with self._lock:
|
|
51
|
+
return self._servers.copy()
|
|
52
|
+
|
|
53
|
+
def clear(self) -> None:
|
|
54
|
+
"""Clear all registered servers."""
|
|
55
|
+
with self._lock:
|
|
56
|
+
self._servers.clear()
|
|
57
|
+
logger.debug("Cleared all registered servers")
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# src/flock/core/registry/type_registry.py
|
|
2
|
+
"""Type registration and lookup functionality."""
|
|
3
|
+
|
|
4
|
+
import threading
|
|
5
|
+
from typing import Any, Literal, Mapping, Optional, Sequence, TypeVar, Union
|
|
6
|
+
|
|
7
|
+
from flock.core.logging.logging import get_logger
|
|
8
|
+
|
|
9
|
+
logger = get_logger("registry.types")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TypeRegistry:
|
|
13
|
+
"""Manages type registration and lookup with thread safety."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, lock: threading.RLock):
|
|
16
|
+
self._lock = lock
|
|
17
|
+
self._types: dict[str, type] = {}
|
|
18
|
+
self._register_core_types()
|
|
19
|
+
|
|
20
|
+
def register_type(self, type_obj: type, name: str | None = None) -> str | None:
|
|
21
|
+
"""Register a class/type (Pydantic, Dataclass, etc.) used in signatures."""
|
|
22
|
+
type_name = name or type_obj.__name__
|
|
23
|
+
if not type_name:
|
|
24
|
+
logger.error(f"Could not determine name for type: {type_obj}")
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
with self._lock:
|
|
28
|
+
if type_name in self._types and self._types[type_name] != type_obj:
|
|
29
|
+
logger.warning(f"Type '{type_name}' already registered. Overwriting.")
|
|
30
|
+
|
|
31
|
+
self._types[type_name] = type_obj
|
|
32
|
+
logger.debug(f"Registered type: {type_name}")
|
|
33
|
+
return type_name
|
|
34
|
+
|
|
35
|
+
def get_type(self, type_name: str) -> type:
|
|
36
|
+
"""Retrieve a registered type by its name."""
|
|
37
|
+
with self._lock:
|
|
38
|
+
if type_name in self._types:
|
|
39
|
+
return self._types[type_name]
|
|
40
|
+
|
|
41
|
+
# Consider adding dynamic import attempts for types if needed,
|
|
42
|
+
# but explicit registration is generally safer for types.
|
|
43
|
+
logger.warning(f"Type '{type_name}' not found in registry. Will attempt to build it from builtins.")
|
|
44
|
+
raise KeyError(f"Type '{type_name}' not found. Ensure it is registered.")
|
|
45
|
+
|
|
46
|
+
def get_all_types(self) -> dict[str, type]:
|
|
47
|
+
"""Get all registered types."""
|
|
48
|
+
with self._lock:
|
|
49
|
+
return self._types.copy()
|
|
50
|
+
|
|
51
|
+
def clear(self) -> None:
|
|
52
|
+
"""Clear all registered types (except core types)."""
|
|
53
|
+
with self._lock:
|
|
54
|
+
# Save core types
|
|
55
|
+
core_types = {
|
|
56
|
+
name: type_obj for name, type_obj in self._types.items()
|
|
57
|
+
if type_obj in [str, int, float, bool, list, dict, tuple, set, Any, Mapping, Sequence, TypeVar, Literal, Optional, Union]
|
|
58
|
+
}
|
|
59
|
+
self._types.clear()
|
|
60
|
+
self._types.update(core_types)
|
|
61
|
+
logger.debug("Cleared all registered types (keeping core types)")
|
|
62
|
+
|
|
63
|
+
def _register_core_types(self):
|
|
64
|
+
"""Register common built-in and typing types."""
|
|
65
|
+
core_types = [
|
|
66
|
+
str,
|
|
67
|
+
int,
|
|
68
|
+
float,
|
|
69
|
+
bool,
|
|
70
|
+
list,
|
|
71
|
+
dict,
|
|
72
|
+
tuple,
|
|
73
|
+
set,
|
|
74
|
+
Any,
|
|
75
|
+
Mapping,
|
|
76
|
+
Sequence,
|
|
77
|
+
TypeVar,
|
|
78
|
+
Literal,
|
|
79
|
+
Optional,
|
|
80
|
+
Union, # Common typing generics
|
|
81
|
+
]
|
|
82
|
+
for t in core_types:
|
|
83
|
+
try:
|
|
84
|
+
self.register_type(t)
|
|
85
|
+
except Exception as e:
|
|
86
|
+
logger.error(f"Failed to auto-register core type {t}: {e}")
|