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.

Files changed (130) hide show
  1. flock/cli/execute_flock.py +1 -1
  2. flock/cli/manage_agents.py +6 -6
  3. flock/components/__init__.py +30 -0
  4. flock/components/evaluation/__init__.py +9 -0
  5. flock/components/evaluation/declarative_evaluation_component.py +222 -0
  6. flock/components/routing/__init__.py +15 -0
  7. flock/{routers/conditional/conditional_router.py → components/routing/conditional_routing_component.py} +61 -53
  8. flock/components/routing/default_routing_component.py +103 -0
  9. flock/components/routing/llm_routing_component.py +206 -0
  10. flock/components/utility/__init__.py +15 -0
  11. flock/{modules/enterprise_memory/enterprise_memory_module.py → components/utility/memory_utility_component.py} +195 -173
  12. flock/{modules/performance/metrics_module.py → components/utility/metrics_utility_component.py} +110 -95
  13. flock/{modules/output/output_module.py → components/utility/output_utility_component.py} +47 -45
  14. flock/core/__init__.py +26 -18
  15. flock/core/agent/__init__.py +16 -0
  16. flock/core/agent/flock_agent_components.py +104 -0
  17. flock/core/agent/flock_agent_execution.py +101 -0
  18. flock/core/agent/flock_agent_integration.py +206 -0
  19. flock/core/agent/flock_agent_lifecycle.py +177 -0
  20. flock/core/agent/flock_agent_serialization.py +381 -0
  21. flock/core/api/endpoints.py +2 -2
  22. flock/core/api/service.py +2 -2
  23. flock/core/component/__init__.py +15 -0
  24. flock/core/{flock_module.py → component/agent_component_base.py} +136 -34
  25. flock/core/component/evaluation_component.py +56 -0
  26. flock/core/component/routing_component.py +74 -0
  27. flock/core/component/utility_component.py +69 -0
  28. flock/core/config/flock_agent_config.py +49 -2
  29. flock/core/evaluation/utils.py +3 -2
  30. flock/core/execution/batch_executor.py +1 -1
  31. flock/core/execution/evaluation_executor.py +2 -2
  32. flock/core/execution/opik_executor.py +1 -1
  33. flock/core/flock.py +147 -493
  34. flock/core/flock_agent.py +195 -1032
  35. flock/core/flock_factory.py +114 -90
  36. flock/core/flock_scheduler.py +1 -1
  37. flock/core/flock_server_manager.py +8 -8
  38. flock/core/logging/logging.py +1 -0
  39. flock/core/mcp/flock_mcp_server.py +53 -48
  40. flock/core/mcp/{flock_mcp_tool_base.py → flock_mcp_tool.py} +2 -2
  41. flock/core/mcp/mcp_client.py +9 -9
  42. flock/core/mcp/mcp_client_manager.py +9 -9
  43. flock/core/mcp/mcp_config.py +24 -24
  44. flock/core/mixin/dspy_integration.py +5 -5
  45. flock/core/orchestration/__init__.py +18 -0
  46. flock/core/orchestration/flock_batch_processor.py +94 -0
  47. flock/core/orchestration/flock_evaluator.py +113 -0
  48. flock/core/orchestration/flock_execution.py +288 -0
  49. flock/core/orchestration/flock_initialization.py +125 -0
  50. flock/core/orchestration/flock_server_manager.py +67 -0
  51. flock/core/orchestration/flock_web_server.py +117 -0
  52. flock/core/registry/__init__.py +45 -0
  53. flock/core/registry/agent_registry.py +69 -0
  54. flock/core/registry/callable_registry.py +139 -0
  55. flock/core/registry/component_discovery.py +142 -0
  56. flock/core/registry/component_registry.py +64 -0
  57. flock/core/registry/config_mapping.py +64 -0
  58. flock/core/registry/decorators.py +137 -0
  59. flock/core/registry/registry_hub.py +205 -0
  60. flock/core/registry/server_registry.py +57 -0
  61. flock/core/registry/type_registry.py +86 -0
  62. flock/core/serialization/flock_serializer.py +36 -32
  63. flock/core/serialization/serialization_utils.py +28 -25
  64. flock/core/util/hydrator.py +1 -1
  65. flock/core/util/input_resolver.py +29 -2
  66. flock/mcp/servers/sse/flock_sse_server.py +10 -10
  67. flock/mcp/servers/stdio/flock_stdio_server.py +10 -10
  68. flock/mcp/servers/streamable_http/flock_streamable_http_server.py +10 -10
  69. flock/mcp/servers/websockets/flock_websocket_server.py +10 -10
  70. flock/platform/docker_tools.py +3 -3
  71. flock/webapp/app/chat.py +1 -1
  72. flock/webapp/app/main.py +9 -5
  73. flock/webapp/app/services/flock_service.py +1 -1
  74. flock/webapp/app/services/sharing_store.py +1 -0
  75. flock/workflow/activities.py +67 -92
  76. flock/workflow/agent_execution_activity.py +6 -6
  77. flock/workflow/flock_workflow.py +1 -1
  78. flock_core-0.5.0b0.dist-info/METADATA +272 -0
  79. {flock_core-0.4.528.dist-info → flock_core-0.5.0b0.dist-info}/RECORD +82 -95
  80. flock/core/flock_evaluator.py +0 -60
  81. flock/core/flock_registry.py +0 -702
  82. flock/core/flock_router.py +0 -83
  83. flock/evaluators/__init__.py +0 -1
  84. flock/evaluators/declarative/__init__.py +0 -1
  85. flock/evaluators/declarative/declarative_evaluator.py +0 -217
  86. flock/evaluators/memory/memory_evaluator.py +0 -90
  87. flock/evaluators/test/test_case_evaluator.py +0 -38
  88. flock/evaluators/zep/zep_evaluator.py +0 -59
  89. flock/modules/__init__.py +0 -1
  90. flock/modules/assertion/__init__.py +0 -1
  91. flock/modules/assertion/assertion_module.py +0 -286
  92. flock/modules/callback/__init__.py +0 -1
  93. flock/modules/callback/callback_module.py +0 -91
  94. flock/modules/enterprise_memory/README.md +0 -99
  95. flock/modules/mem0/__init__.py +0 -1
  96. flock/modules/mem0/mem0_module.py +0 -126
  97. flock/modules/mem0_async/__init__.py +0 -1
  98. flock/modules/mem0_async/async_mem0_module.py +0 -126
  99. flock/modules/memory/__init__.py +0 -1
  100. flock/modules/memory/memory_module.py +0 -429
  101. flock/modules/memory/memory_parser.py +0 -125
  102. flock/modules/memory/memory_storage.py +0 -736
  103. flock/modules/output/__init__.py +0 -1
  104. flock/modules/performance/__init__.py +0 -1
  105. flock/modules/zep/__init__.py +0 -1
  106. flock/modules/zep/zep_module.py +0 -192
  107. flock/routers/__init__.py +0 -1
  108. flock/routers/agent/__init__.py +0 -1
  109. flock/routers/agent/agent_router.py +0 -236
  110. flock/routers/agent/handoff_agent.py +0 -58
  111. flock/routers/default/__init__.py +0 -1
  112. flock/routers/default/default_router.py +0 -80
  113. flock/routers/feedback/feedback_router.py +0 -114
  114. flock/routers/list_generator/list_generator_router.py +0 -166
  115. flock/routers/llm/__init__.py +0 -1
  116. flock/routers/llm/llm_router.py +0 -365
  117. flock/tools/__init__.py +0 -0
  118. flock/tools/azure_tools.py +0 -781
  119. flock/tools/code_tools.py +0 -167
  120. flock/tools/file_tools.py +0 -149
  121. flock/tools/github_tools.py +0 -157
  122. flock/tools/markdown_tools.py +0 -205
  123. flock/tools/system_tools.py +0 -9
  124. flock/tools/text_tools.py +0 -810
  125. flock/tools/web_tools.py +0 -90
  126. flock/tools/zendesk_tools.py +0 -147
  127. flock_core-0.4.528.dist-info/METADATA +0 -675
  128. {flock_core-0.4.528.dist-info → flock_core-0.5.0b0.dist-info}/WHEEL +0 -0
  129. {flock_core-0.4.528.dist-info → flock_core-0.5.0b0.dist-info}/entry_points.txt +0 -0
  130. {flock_core-0.4.528.dist-info → flock_core-0.5.0b0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,381 @@
1
+ # src/flock/core/agent/flock_agent_serialization.py
2
+ """Serialization functionality for FlockAgent."""
3
+
4
+ import json
5
+ import os
6
+ from datetime import datetime
7
+ from typing import TYPE_CHECKING, Any, TypeVar
8
+
9
+ # Legacy component imports removed
10
+ from flock.core.logging.logging import get_logger
11
+ from flock.core.mcp.flock_mcp_server import FlockMCPServer
12
+ from flock.core.serialization.json_encoder import FlockJSONEncoder
13
+ from flock.core.serialization.serialization_utils import (
14
+ deserialize_component,
15
+ serialize_item,
16
+ )
17
+
18
+ if TYPE_CHECKING:
19
+ from flock.core.flock_agent import FlockAgent
20
+
21
+ logger = get_logger("agent.serialization")
22
+ T = TypeVar("T", bound="FlockAgent")
23
+
24
+
25
+ class FlockAgentSerialization:
26
+ """Handles serialization and deserialization for FlockAgent."""
27
+
28
+ def __init__(self, agent: "FlockAgent"):
29
+ self.agent = agent
30
+
31
+ def _save_output(self, agent_name: str, result: dict[str, Any]) -> None:
32
+ """Save output to file if configured."""
33
+ if not self.agent.config.write_to_file:
34
+ return
35
+
36
+ timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
37
+ filename = f"{agent_name}_output_{timestamp}.json"
38
+ filepath = os.path.join(".flock/output/", filename)
39
+ os.makedirs(".flock/output/", exist_ok=True)
40
+
41
+ output_data = {
42
+ "agent": agent_name,
43
+ "timestamp": timestamp,
44
+ "output": result,
45
+ }
46
+
47
+ try:
48
+ with open(filepath, "w") as f:
49
+ json.dump(output_data, f, indent=2, cls=FlockJSONEncoder)
50
+ except Exception as e:
51
+ logger.warning(f"Failed to save output to file: {e}")
52
+
53
+ def to_dict(self) -> dict[str, Any]:
54
+ """Convert instance to dictionary representation suitable for serialization."""
55
+ from flock.core.registry import get_registry
56
+
57
+ registry = get_registry()
58
+
59
+ exclude = [
60
+ "context",
61
+ "components",
62
+ "tools",
63
+ "servers",
64
+ ]
65
+
66
+ is_description_callable = False
67
+ is_input_callable = False
68
+ is_output_callable = False
69
+ is_next_agent_callable = False
70
+ # if self.agent.description is a callable, exclude it
71
+ if callable(self.agent.description_spec):
72
+ is_description_callable = True
73
+ exclude.append("description_spec")
74
+ # if self.agent.input is a callable, exclude it
75
+ if callable(self.agent.input_spec):
76
+ is_input_callable = True
77
+ exclude.append("input_spec")
78
+ # if self.agent.output is a callable, exclude it
79
+ if callable(self.agent.output_spec):
80
+ is_output_callable = True
81
+ exclude.append("output_spec")
82
+ if callable(self.agent.next_agent_spec):
83
+ is_next_agent_callable = True
84
+ exclude.append("next_agent_spec")
85
+
86
+ logger.debug(f"Serializing agent '{self.agent.name}' to dict.")
87
+ # Use Pydantic's dump, exclude manually handled fields and runtime context
88
+ data = self.agent.model_dump(
89
+ exclude=exclude,
90
+ mode="json", # Use json mode for better handling of standard types by Pydantic
91
+ exclude_none=True, # Exclude None values for cleaner output
92
+ )
93
+ logger.debug(f"Base agent data for '{self.agent.name}': {list(data.keys())}")
94
+
95
+ # Serialize components list using unified architecture
96
+ if self.agent.components:
97
+ serialized_components = []
98
+ for component in self.agent.components:
99
+ try:
100
+ comp_type = type(component)
101
+ type_name = registry.get_component_type_name(comp_type)
102
+ if type_name:
103
+ component_data = serialize_item(component)
104
+ if isinstance(component_data, dict):
105
+ component_data["type"] = type_name
106
+ serialized_components.append(component_data)
107
+ else:
108
+ logger.warning(f"Component {component.name} serialization failed")
109
+ else:
110
+ logger.warning(f"Component {component.name} type not registered")
111
+ except Exception as e:
112
+ logger.error(f"Failed to serialize component {component.name}: {e}")
113
+
114
+ if serialized_components:
115
+ data["components"] = serialized_components
116
+ logger.debug(f"Added {len(serialized_components)} components to agent '{self.agent.name}'")
117
+
118
+ # --- Serialize Servers ---
119
+ if self.agent.servers:
120
+ logger.debug(
121
+ f"Serializing {len(self.agent.servers)} servers for agent '{self.agent.name}'"
122
+ )
123
+ serialized_servers = []
124
+ for server in self.agent.servers:
125
+ if isinstance(server, FlockMCPServer):
126
+ serialized_servers.append(server.config.name)
127
+ else:
128
+ # Write it down as a list of server names.
129
+ serialized_servers.append(server)
130
+
131
+ if serialized_servers:
132
+ data["mcp_servers"] = serialized_servers
133
+ logger.debug(
134
+ f"Added {len(serialized_servers)} servers to agent '{self.agent.name}'"
135
+ )
136
+
137
+ # --- Serialize Tools (Callables) ---
138
+ if self.agent.tools:
139
+ logger.debug(
140
+ f"Serializing {len(self.agent.tools)} tools for agent '{self.agent.name}'"
141
+ )
142
+ serialized_tools = []
143
+ for tool in self.agent.tools:
144
+ if callable(tool) and not isinstance(tool, type):
145
+ path_str = registry.get_callable_path_string(tool)
146
+ if path_str:
147
+ # Get just the function name from the path string
148
+ # If it's a namespaced path like module.submodule.function_name
149
+ # Just use the function_name part
150
+ func_name = path_str.split(".")[-1]
151
+ serialized_tools.append(func_name)
152
+ logger.debug(
153
+ f"Added tool '{func_name}' (from path '{path_str}') to agent '{self.agent.name}'"
154
+ )
155
+ else:
156
+ logger.warning(
157
+ f"Could not get path string for tool {tool} in agent '{self.agent.name}'. Skipping."
158
+ )
159
+ else:
160
+ logger.warning(
161
+ f"Non-callable item found in tools list for agent '{self.agent.name}': {tool}. Skipping."
162
+ )
163
+ if serialized_tools:
164
+ data["tools"] = serialized_tools
165
+ logger.debug(
166
+ f"Added {len(serialized_tools)} tools to agent '{self.agent.name}'"
167
+ )
168
+
169
+ if is_description_callable:
170
+ path_str = registry.get_callable_path_string(self.agent.description_spec)
171
+ if path_str:
172
+ func_name = path_str.split(".")[-1]
173
+ data["description_callable"] = func_name
174
+ logger.debug(
175
+ f"Added description '{func_name}' (from path '{path_str}') to agent '{self.agent.name}'"
176
+ )
177
+ else:
178
+ logger.warning(
179
+ f"Could not get path string for description {self.agent.description_spec} in agent '{self.agent.name}'. Skipping."
180
+ )
181
+
182
+ if is_input_callable:
183
+ path_str = registry.get_callable_path_string(self.agent.input_spec)
184
+ if path_str:
185
+ func_name = path_str.split(".")[-1]
186
+ data["input_callable"] = func_name
187
+ logger.debug(
188
+ f"Added input '{func_name}' (from path '{path_str}') to agent '{self.agent.name}'"
189
+ )
190
+ else:
191
+ logger.warning(
192
+ f"Could not get path string for input {self.agent.input_spec} in agent '{self.agent.name}'. Skipping."
193
+ )
194
+
195
+ if is_output_callable:
196
+ path_str = registry.get_callable_path_string(self.agent.output_spec)
197
+ if path_str:
198
+ func_name = path_str.split(".")[-1]
199
+ data["output_callable"] = func_name
200
+ logger.debug(
201
+ f"Added output '{func_name}' (from path '{path_str}') to agent '{self.agent.name}'"
202
+ )
203
+ else:
204
+ logger.warning(
205
+ f"Could not get path string for output {self.agent.output_spec} in agent '{self.agent.name}'. Skipping."
206
+ )
207
+
208
+ if is_next_agent_callable:
209
+ path_str = registry.get_callable_path_string(self.agent.next_agent_spec)
210
+ if path_str:
211
+ func_name = path_str.split(".")[-1]
212
+ data["next_agent_callable"] = func_name
213
+ logger.debug(
214
+ f"Added next_agent '{func_name}' (from path '{path_str}') to agent '{self.agent.name}'"
215
+ )
216
+ else:
217
+ logger.warning(
218
+ f"Could not get path string for next_agent {self.agent.next_agent_spec} in agent '{self.agent.name}'. Skipping."
219
+ )
220
+
221
+
222
+ logger.info(
223
+ f"Serialization of agent '{self.agent.name}' complete with {len(data)} fields"
224
+ )
225
+ return data
226
+
227
+ @classmethod
228
+ def from_dict(cls, agent_class: type[T], data: dict[str, Any]) -> T:
229
+ """Deserialize the agent from a dictionary, including components, tools, and callables."""
230
+ from flock.core.component.agent_component_base import AgentComponent
231
+ from flock.core.registry import get_registry
232
+
233
+ registry = get_registry()
234
+ logger.debug(
235
+ f"Deserializing agent from dict. Keys: {list(data.keys())}"
236
+ )
237
+
238
+ # --- Separate Data ---
239
+ components_data = data.pop("components", [])
240
+ callable_configs = {}
241
+ tool_config = data.pop("tools", [])
242
+ servers_config = data.pop("mcp_servers", [])
243
+
244
+ callable_keys = [
245
+ "description_callable",
246
+ "input_callable",
247
+ "output_callable",
248
+ "next_agent_callable",
249
+ ]
250
+
251
+ for key in callable_keys:
252
+ if key in data and data[key] is not None:
253
+ callable_configs[key] = data.pop(key)
254
+
255
+ # --- Deserialize Base Agent ---
256
+ # Ensure required fields like 'name' are present if needed by __init__
257
+ if "name" not in data:
258
+ raise ValueError(
259
+ "Agent data must include a 'name' field for deserialization."
260
+ )
261
+ agent_name_log = data["name"] # For logging
262
+ logger.info(f"Deserializing base agent data for '{agent_name_log}'")
263
+
264
+ # Pydantic should handle base fields based on type hints in __init__
265
+ agent = agent_class(**data)
266
+ logger.debug(f"Base agent '{agent.name}' instantiated.")
267
+
268
+ # --- Deserialize Components ---
269
+ logger.debug(f"Deserializing components for '{agent.name}'")
270
+ if components_data:
271
+ for component_data in components_data:
272
+ try:
273
+ # Use the existing deserialize_component function
274
+ component = deserialize_component(component_data, AgentComponent)
275
+ if component:
276
+ agent.add_component(component)
277
+ logger.debug(f"Deserialized and added component '{component.name}' for '{agent.name}'")
278
+ except Exception as e:
279
+ logger.error(f"Failed to deserialize component: {e}")
280
+
281
+ # --- Deserialize Tools ---
282
+ agent.tools = [] # Initialize tools list
283
+ if tool_config:
284
+ logger.debug(
285
+ f"Deserializing {len(tool_config)} tools for '{agent.name}'"
286
+ )
287
+ # Use get_callable to find each tool
288
+ for tool_name_or_path in tool_config:
289
+ try:
290
+ found_tool = registry.get_callable(tool_name_or_path)
291
+ if found_tool and callable(found_tool):
292
+ agent.tools.append(found_tool)
293
+ logger.debug(
294
+ f"Resolved and added tool '{tool_name_or_path}' for agent '{agent.name}'"
295
+ )
296
+ else:
297
+ # Should not happen if get_callable returns successfully but just in case
298
+ logger.warning(
299
+ f"Registry returned non-callable for tool '{tool_name_or_path}' for agent '{agent.name}'. Skipping."
300
+ )
301
+ except (
302
+ ValueError
303
+ ) as e: # get_callable raises ValueError if not found/ambiguous
304
+ logger.warning(
305
+ f"Could not resolve tool '{tool_name_or_path}' for agent '{agent.name}': {e}. Skipping."
306
+ )
307
+ except Exception as e:
308
+ logger.error(
309
+ f"Unexpected error resolving tool '{tool_name_or_path}' for agent '{agent.name}': {e}. Skipping.",
310
+ exc_info=True,
311
+ )
312
+
313
+ # --- Deserialize Servers ---
314
+ agent.servers = [] # Initialize Servers list.
315
+ if servers_config:
316
+ logger.debug(
317
+ f"Deserializing {len(servers_config)} servers for '{agent.name}'"
318
+ )
319
+ # Agents keep track of server by getting a list of server names.
320
+ # The server instances will be retrieved during runtime from the registry. (default behavior)
321
+
322
+ for server_name in servers_config:
323
+ if isinstance(server_name, str):
324
+ # Case 1 (default behavior): A server name is passed.
325
+ agent.servers.append(server_name)
326
+ elif isinstance(server_name, FlockMCPServer):
327
+ # Case 2 (highly unlikely): If someone somehow manages to pass
328
+ # an instance of a server during the deserialization step (however that might be achieved)
329
+ # check the registry, if the server is already registered, if not, register it
330
+ # and store the name in the servers list
331
+ server_exists = (
332
+ registry.get_server(server_name.config.name)
333
+ is not None
334
+ )
335
+ if server_exists:
336
+ agent.servers.append(server_name.config.name)
337
+ else:
338
+ registry.register_server(
339
+ server=server_name
340
+ ) # register it.
341
+ agent.servers.append(server_name.config.name)
342
+
343
+ # --- Deserialize Callables ---
344
+ logger.debug(f"Deserializing callable fields for '{agent.name}'")
345
+
346
+ def resolve_and_assign(field_name: str, callable_key: str):
347
+ if callable_key in callable_configs:
348
+ callable_name = callable_configs[callable_key]
349
+ try:
350
+ # Use get_callable to find the signature function
351
+ found_callable = registry.get_callable(callable_name)
352
+ if found_callable and callable(found_callable):
353
+ setattr(agent, field_name, found_callable)
354
+ logger.debug(
355
+ f"Resolved callable '{callable_name}' for field '{field_name}' on agent '{agent.name}'"
356
+ )
357
+ else:
358
+ logger.warning(
359
+ f"Registry returned non-callable for name '{callable_name}' for field '{field_name}' on agent '{agent.name}'. Field remains default."
360
+ )
361
+ except (
362
+ ValueError
363
+ ) as e: # get_callable raises ValueError if not found/ambiguous
364
+ logger.warning(
365
+ f"Could not resolve callable '{callable_name}' in registry for field '{field_name}' on agent '{agent.name}': {e}. Field remains default."
366
+ )
367
+ except Exception as e:
368
+ logger.error(
369
+ f"Unexpected error resolving callable '{callable_name}' for field '{field_name}' on agent '{agent.name}': {e}. Field remains default.",
370
+ exc_info=True,
371
+ )
372
+ # Else: key not present, field retains its default value from __init__
373
+
374
+ resolve_and_assign("description", "description_callable")
375
+ resolve_and_assign("input", "input_callable")
376
+ resolve_and_assign("output", "output_callable")
377
+ resolve_and_assign("next_agent", "next_agent_callable")
378
+ # --- Finalize ---
379
+
380
+ logger.info(f"Successfully deserialized agent '{agent.name}'.")
381
+ return agent
@@ -89,7 +89,7 @@ def create_api_router() -> APIRouter:
89
89
  typed_inputs = inputs_task # Simplified for now
90
90
 
91
91
  result = await flock_instance.run_async(
92
- start_agent=agent_name_task, input=typed_inputs
92
+ agent=agent_name_task, input=typed_inputs
93
93
  )
94
94
  run_store.update_run_result(run_id_task, result)
95
95
  except Exception as e_task:
@@ -246,7 +246,7 @@ def create_api_router() -> APIRouter:
246
246
  """List all available agents in the currently loaded Flock."""
247
247
  logger.debug("API request: list agents")
248
248
  agents_list = [
249
- {"name": agent.name, "description": agent.resolved_description or agent.name}
249
+ agent.to_dict()
250
250
  for agent in flock_instance.agents.values()
251
251
  ]
252
252
  return {"agents": agents_list}
flock/core/api/service.py CHANGED
@@ -33,7 +33,7 @@ class FlockApiService:
33
33
  )
34
34
  # Flock.run_async now handles context creation and execution
35
35
  result = await self.flock.run_async(
36
- start_agent=agent_name, input=typed_inputs
36
+ agent=agent_name, input=typed_inputs
37
37
  )
38
38
  self.run_store.update_run_result(run_id, result)
39
39
 
@@ -100,7 +100,7 @@ class FlockApiService:
100
100
  try:
101
101
  # Call Flock's run_async for a single item
102
102
  item_result = await self.flock.run_async(
103
- start_agent=request.agent_name,
103
+ agent=request.agent_name,
104
104
  input=item_inputs,
105
105
  box_result=request.box_results,
106
106
  )
@@ -0,0 +1,15 @@
1
+ # src/flock/core/component/__init__.py
2
+ """Unified component system for Flock agents."""
3
+
4
+ from .agent_component_base import AgentComponent, AgentComponentConfig
5
+ from .evaluation_component import EvaluationComponent
6
+ from .routing_component import RoutingComponent
7
+ from .utility_component import UtilityComponent
8
+
9
+ __all__ = [
10
+ "AgentComponent",
11
+ "AgentComponentConfig",
12
+ "EvaluationComponent",
13
+ "RoutingComponent",
14
+ "UtilityComponent",
15
+ ]
@@ -1,4 +1,5 @@
1
- """Base classes and implementations for the Flock module system."""
1
+ # src/flock/core/component/agent_component_base.py
2
+ """Base classes for the unified Flock component system."""
2
3
 
3
4
  from abc import ABC
4
5
  from typing import Any, TypeVar
@@ -7,63 +8,86 @@ from pydantic import BaseModel, Field, create_model
7
8
 
8
9
  from flock.core.context.context import FlockContext
9
10
 
10
- T = TypeVar("T", bound="FlockModuleConfig")
11
+ # HandOffRequest removed - using agent.next_agent directly
11
12
 
13
+ T = TypeVar("T", bound="AgentComponentConfig")
12
14
 
13
- class FlockModuleConfig(BaseModel):
14
- """Base configuration class for Flock modules.
15
15
 
16
- This class serves as the base for all module-specific configurations.
17
- Each module should define its own config class inheriting from this one.
18
-
19
- Example:
20
- class MemoryModuleConfig(FlockModuleConfig):
21
- file_path: str = Field(default="memory.json")
22
- save_after_update: bool = Field(default=True)
16
+ class AgentComponentConfig(BaseModel):
17
+ """Base configuration class for all Flock agent components.
18
+
19
+ This unified config class replaces FlockModuleConfig, FlockEvaluatorConfig,
20
+ and FlockRouterConfig, providing common functionality for all component types.
23
21
  """
24
22
 
25
23
  enabled: bool = Field(
26
- default=True, description="Whether the module is currently enabled"
24
+ default=True,
25
+ description="Whether this component is currently enabled"
26
+ )
27
+
28
+ model: str | None = Field(
29
+ default=None,
30
+ description="Model to use for this component (if applicable)"
27
31
  )
28
32
 
29
33
  @classmethod
30
34
  def with_fields(cls: type[T], **field_definitions) -> type[T]:
31
- """Create a new config class with additional fields."""
35
+ """Create a new config class with additional fields.
36
+
37
+ This allows dynamic config creation for components with custom configuration needs.
38
+
39
+ Example:
40
+ CustomConfig = AgentComponentConfig.with_fields(
41
+ temperature=Field(default=0.7, description="LLM temperature"),
42
+ max_tokens=Field(default=1000, description="Max tokens to generate")
43
+ )
44
+ """
32
45
  return create_model(
33
- f"Dynamic{cls.__name__}", __base__=cls, **field_definitions
46
+ f"Dynamic{cls.__name__}",
47
+ __base__=cls,
48
+ **field_definitions
34
49
  )
35
50
 
36
51
 
37
- class FlockModule(BaseModel, ABC):
38
- """Base class for all Flock modules.
39
-
40
- Modules can hook into agent lifecycle events and modify or enhance agent behavior.
41
- They are initialized when added to an agent and can maintain their own state.
42
-
43
- Each module should define its configuration requirements either by:
44
- 1. Creating a subclass of FlockModuleConfig
45
- 2. Using FlockModuleConfig.with_fields() to create a config class
52
+ class AgentComponent(BaseModel, ABC):
53
+ """Base class for all Flock agent components.
54
+
55
+ This unified base class replaces the separate FlockModule, FlockEvaluator,
56
+ and FlockRouter base classes. All agent extensions now inherit from this
57
+ single base class and use the unified lifecycle hooks.
58
+
59
+ Components can specialize by:
60
+ - EvaluationComponentBase: Implements evaluate_core() for agent intelligence
61
+ - RoutingComponentBase: Implements determine_next_step() for workflow routing
62
+ - UtilityComponentBase: Uses standard lifecycle hooks for cross-cutting concerns
46
63
  """
47
64
 
48
65
  name: str = Field(
49
- default="", description="Unique identifier for the module"
50
- )
51
- config: FlockModuleConfig = Field(
52
- default_factory=FlockModuleConfig, description="Module configuration"
66
+ ...,
67
+ description="Unique identifier for this component"
53
68
  )
54
69
 
55
- # (Historic) global-module registry removed – prefer DI container instead.
70
+ config: AgentComponentConfig = Field(
71
+ default_factory=AgentComponentConfig,
72
+ description="Component configuration"
73
+ )
56
74
 
57
75
  def __init__(self, **data):
58
76
  super().__init__(**data)
59
77
 
78
+ # --- Standard Lifecycle Hooks ---
79
+ # These are called for ALL components during agent execution
80
+
60
81
  async def on_initialize(
61
82
  self,
62
83
  agent: Any,
63
84
  inputs: dict[str, Any],
64
85
  context: FlockContext | None = None,
65
86
  ) -> None:
66
- """Called when the agent starts running."""
87
+ """Called when the agent starts running.
88
+
89
+ Use this for component initialization, resource setup, etc.
90
+ """
67
91
  pass
68
92
 
69
93
  async def on_pre_evaluate(
@@ -72,7 +96,16 @@ class FlockModule(BaseModel, ABC):
72
96
  inputs: dict[str, Any],
73
97
  context: FlockContext | None = None,
74
98
  ) -> dict[str, Any]:
75
- """Called before agent evaluation, can modify inputs."""
99
+ """Called before agent evaluation, can modify inputs.
100
+
101
+ Args:
102
+ agent: The agent being executed
103
+ inputs: Current input data
104
+ context: Execution context
105
+
106
+ Returns:
107
+ Modified input data (or original if no changes)
108
+ """
76
109
  return inputs
77
110
 
78
111
  async def on_post_evaluate(
@@ -82,7 +115,17 @@ class FlockModule(BaseModel, ABC):
82
115
  context: FlockContext | None = None,
83
116
  result: dict[str, Any] | None = None,
84
117
  ) -> dict[str, Any] | None:
85
- """Called after agent evaluation, can modify results."""
118
+ """Called after agent evaluation, can modify results.
119
+
120
+ Args:
121
+ agent: The agent that was executed
122
+ inputs: Original input data
123
+ context: Execution context
124
+ result: Evaluation result
125
+
126
+ Returns:
127
+ Modified result data (or original if no changes)
128
+ """
86
129
  return result
87
130
 
88
131
  async def on_terminate(
@@ -92,7 +135,10 @@ class FlockModule(BaseModel, ABC):
92
135
  context: FlockContext | None = None,
93
136
  result: dict[str, Any] | None = None,
94
137
  ) -> dict[str, Any] | None:
95
- """Called when the agent finishes running."""
138
+ """Called when the agent finishes running.
139
+
140
+ Use this for cleanup, final result processing, etc.
141
+ """
96
142
  return result
97
143
 
98
144
  async def on_error(
@@ -102,15 +148,71 @@ class FlockModule(BaseModel, ABC):
102
148
  context: FlockContext | None = None,
103
149
  error: Exception | None = None,
104
150
  ) -> None:
105
- """Called when an error occurs during agent execution."""
151
+ """Called when an error occurs during agent execution.
152
+
153
+ Use this for error handling, logging, recovery, etc.
154
+ """
106
155
  pass
107
156
 
157
+ # --- Specialized Hooks ---
158
+ # These are overridden by specialized component types
159
+
160
+ async def evaluate_core(
161
+ self,
162
+ agent: Any,
163
+ inputs: dict[str, Any],
164
+ context: FlockContext | None = None,
165
+ tools: list[Any] | None = None,
166
+ mcp_tools: list[Any] | None = None,
167
+ ) -> dict[str, Any]:
168
+ """Core evaluation logic - override in EvaluationComponentBase.
169
+
170
+ This is where the main "intelligence" of the agent happens.
171
+ Only one component per agent should implement this meaningfully.
172
+
173
+ Args:
174
+ agent: The agent being executed
175
+ inputs: Input data for evaluation
176
+ context: Execution context
177
+ tools: Available tools for the agent
178
+ mcp_tools: Available MCP tools
179
+
180
+ Returns:
181
+ Evaluation result
182
+ """
183
+ # Default implementation is pass-through
184
+ return inputs
185
+
186
+ async def determine_next_step(
187
+ self,
188
+ agent: Any,
189
+ result: dict[str, Any],
190
+ context: FlockContext | None = None,
191
+ ) -> None:
192
+ """Determine the next step in the workflow - override in RoutingComponentBase.
193
+
194
+ This is where routing decisions are made. Sets agent.next_agent directly.
195
+
196
+ Args:
197
+ agent: The agent that just completed
198
+ result: Result from the agent's evaluation
199
+ context: Execution context
200
+
201
+ Returns:
202
+ None - routing components set agent.next_agent directly
203
+ """
204
+ # Default implementation provides no routing
205
+ pass
206
+
207
+ # --- MCP Server Lifecycle Hooks ---
208
+ # For components that interact directly with MCP servers
209
+
108
210
  async def on_pre_server_init(self, server: Any) -> None:
109
211
  """Called before a server initializes."""
110
212
  pass
111
213
 
112
214
  async def on_post_server_init(self, server: Any) -> None:
113
- """Called after a server initialized."""
215
+ """Called after a server initializes."""
114
216
  pass
115
217
 
116
218
  async def on_pre_server_terminate(self, server: Any) -> None: