flock-core 0.4.0b26__py3-none-any.whl → 0.4.0b28__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/core/context/context.py +10 -1
- flock/core/execution/temporal_executor.py +129 -20
- flock/core/flock.py +46 -2
- flock/core/flock_agent.py +151 -146
- flock/core/flock_factory.py +3 -0
- flock/core/flock_module.py +7 -7
- flock/modules/assertion/assertion_module.py +1 -1
- flock/modules/callback/callback_module.py +1 -1
- flock/modules/memory/memory_module.py +4 -4
- flock/modules/output/output_module.py +1 -1
- flock/modules/performance/metrics_module.py +4 -4
- flock/modules/zep/zep_module.py +2 -2
- flock/workflow/agent_execution_activity.py +228 -0
- flock/workflow/flock_workflow.py +195 -28
- flock/workflow/temporal_config.py +96 -0
- flock/workflow/temporal_setup.py +23 -26
- {flock_core-0.4.0b26.dist-info → flock_core-0.4.0b28.dist-info}/METADATA +115 -8
- {flock_core-0.4.0b26.dist-info → flock_core-0.4.0b28.dist-info}/RECORD +21 -19
- {flock_core-0.4.0b26.dist-info → flock_core-0.4.0b28.dist-info}/WHEEL +0 -0
- {flock_core-0.4.0b26.dist-info → flock_core-0.4.0b28.dist-info}/entry_points.txt +0 -0
- {flock_core-0.4.0b26.dist-info → flock_core-0.4.0b28.dist-info}/licenses/LICENSE +0 -0
flock/core/flock_agent.py
CHANGED
|
@@ -10,6 +10,7 @@ from datetime import datetime
|
|
|
10
10
|
from typing import TYPE_CHECKING, Any, TypeVar
|
|
11
11
|
|
|
12
12
|
from flock.core.serialization.json_encoder import FlockJSONEncoder
|
|
13
|
+
from flock.workflow.temporal_config import TemporalActivityConfig
|
|
13
14
|
|
|
14
15
|
if TYPE_CHECKING:
|
|
15
16
|
from flock.core.context.context import FlockContext
|
|
@@ -110,6 +111,12 @@ class FlockAgent(BaseModel, Serializable, DSPyIntegrationMixin, ABC):
|
|
|
110
111
|
description="Dictionary of FlockModules attached to this agent.",
|
|
111
112
|
)
|
|
112
113
|
|
|
114
|
+
# --- Temporal Configuration (Optional) ---
|
|
115
|
+
temporal_activity_config: TemporalActivityConfig | None = Field(
|
|
116
|
+
default=None,
|
|
117
|
+
description="Optional Temporal settings specific to this agent's activity execution.",
|
|
118
|
+
)
|
|
119
|
+
|
|
113
120
|
# --- Runtime State (Excluded from Serialization) ---
|
|
114
121
|
context: FlockContext | None = Field(
|
|
115
122
|
default=None,
|
|
@@ -130,6 +137,7 @@ class FlockAgent(BaseModel, Serializable, DSPyIntegrationMixin, ABC):
|
|
|
130
137
|
modules: dict[str, "FlockModule"] | None = None, # Use dict for modules
|
|
131
138
|
write_to_file: bool = False,
|
|
132
139
|
wait_for_input: bool = False,
|
|
140
|
+
temporal_activity_config: TemporalActivityConfig | None = None,
|
|
133
141
|
**kwargs,
|
|
134
142
|
):
|
|
135
143
|
super().__init__(
|
|
@@ -146,6 +154,7 @@ class FlockAgent(BaseModel, Serializable, DSPyIntegrationMixin, ABC):
|
|
|
146
154
|
modules=modules
|
|
147
155
|
if modules is not None
|
|
148
156
|
else {}, # Ensure modules is a dict
|
|
157
|
+
temporal_activity_config=temporal_activity_config,
|
|
149
158
|
**kwargs,
|
|
150
159
|
)
|
|
151
160
|
|
|
@@ -199,7 +208,7 @@ class FlockAgent(BaseModel, Serializable, DSPyIntegrationMixin, ABC):
|
|
|
199
208
|
)
|
|
200
209
|
try:
|
|
201
210
|
for module in self.get_enabled_modules():
|
|
202
|
-
await module.
|
|
211
|
+
await module.on_initialize(self, inputs, self.context)
|
|
203
212
|
except Exception as module_error:
|
|
204
213
|
logger.error(
|
|
205
214
|
"Error during initialize",
|
|
@@ -223,7 +232,9 @@ class FlockAgent(BaseModel, Serializable, DSPyIntegrationMixin, ABC):
|
|
|
223
232
|
)
|
|
224
233
|
try:
|
|
225
234
|
for module in self.get_enabled_modules():
|
|
226
|
-
await module.
|
|
235
|
+
await module.on_terminate(
|
|
236
|
+
self, inputs, result, self.context
|
|
237
|
+
)
|
|
227
238
|
|
|
228
239
|
if self.write_to_file:
|
|
229
240
|
self._save_output(self.name, result)
|
|
@@ -272,7 +283,7 @@ class FlockAgent(BaseModel, Serializable, DSPyIntegrationMixin, ABC):
|
|
|
272
283
|
|
|
273
284
|
# Pre-evaluate hooks
|
|
274
285
|
for module in self.get_enabled_modules():
|
|
275
|
-
current_inputs = await module.
|
|
286
|
+
current_inputs = await module.on_pre_evaluate(
|
|
276
287
|
self, current_inputs, self.context
|
|
277
288
|
)
|
|
278
289
|
|
|
@@ -303,7 +314,7 @@ class FlockAgent(BaseModel, Serializable, DSPyIntegrationMixin, ABC):
|
|
|
303
314
|
# Post-evaluate hooks
|
|
304
315
|
current_result = result
|
|
305
316
|
for module in self.get_enabled_modules():
|
|
306
|
-
current_result = await module.
|
|
317
|
+
current_result = await module.on_post_evaluate(
|
|
307
318
|
self, current_inputs, current_result, self.context
|
|
308
319
|
)
|
|
309
320
|
|
|
@@ -723,202 +734,196 @@ class FlockAgent(BaseModel, Serializable, DSPyIntegrationMixin, ABC):
|
|
|
723
734
|
|
|
724
735
|
@classmethod
|
|
725
736
|
def from_dict(cls: type[T], data: dict[str, Any]) -> T:
|
|
726
|
-
"""
|
|
727
|
-
from flock.core.flock_registry import
|
|
728
|
-
|
|
729
|
-
logger.debug(
|
|
730
|
-
f"Deserializing agent from dict. Provided keys: {list(data.keys())}"
|
|
737
|
+
"""Deserialize the agent from a dictionary, including components, tools, and callables."""
|
|
738
|
+
from flock.core.flock_registry import (
|
|
739
|
+
get_registry, # Import registry locally
|
|
731
740
|
)
|
|
732
|
-
if "name" not in data:
|
|
733
|
-
raise ValueError("Agent data must include a 'name' field.")
|
|
734
|
-
FlockRegistry = get_registry()
|
|
735
|
-
agent_name = data["name"] # For logging context
|
|
736
|
-
logger.info(f"Deserializing agent '{agent_name}'")
|
|
737
|
-
|
|
738
|
-
# Pop complex components to handle them after basic agent instantiation
|
|
739
|
-
evaluator_data = data.pop("evaluator", None)
|
|
740
|
-
router_data = data.pop("handoff_router", None)
|
|
741
|
-
modules_data = data.pop("modules", {})
|
|
742
|
-
tools_data = data.pop("tools", [])
|
|
743
|
-
description_callable = data.pop("description_callable", None)
|
|
744
|
-
input_callable = data.pop("input_callable", None)
|
|
745
|
-
output_callable = data.pop("output_callable", None)
|
|
746
741
|
|
|
742
|
+
registry = get_registry()
|
|
747
743
|
logger.debug(
|
|
748
|
-
f"
|
|
744
|
+
f"Deserializing agent from dict. Keys: {list(data.keys())}"
|
|
749
745
|
)
|
|
750
746
|
|
|
751
|
-
#
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
747
|
+
# --- Separate Data ---
|
|
748
|
+
component_configs = {}
|
|
749
|
+
callable_configs = {}
|
|
750
|
+
tool_config = []
|
|
751
|
+
agent_data = {}
|
|
752
|
+
|
|
753
|
+
component_keys = [
|
|
754
|
+
"evaluator",
|
|
755
|
+
"handoff_router",
|
|
756
|
+
"modules",
|
|
757
|
+
"temporal_activity_config",
|
|
758
|
+
]
|
|
759
|
+
callable_keys = [
|
|
760
|
+
"description_callable",
|
|
761
|
+
"input_callable",
|
|
762
|
+
"output_callable",
|
|
763
|
+
]
|
|
764
|
+
tool_key = "tools"
|
|
765
|
+
|
|
766
|
+
for key, value in data.items():
|
|
767
|
+
if key in component_keys and value is not None:
|
|
768
|
+
component_configs[key] = value
|
|
769
|
+
elif key in callable_keys and value is not None:
|
|
770
|
+
callable_configs[key] = value
|
|
771
|
+
elif key == tool_key and value is not None:
|
|
772
|
+
tool_config = value # Expecting a list of names
|
|
773
|
+
elif key not in component_keys + callable_keys + [
|
|
774
|
+
tool_key
|
|
775
|
+
]: # Avoid double adding
|
|
776
|
+
agent_data[key] = value
|
|
777
|
+
# else: ignore keys that are None or already handled
|
|
778
|
+
|
|
779
|
+
# --- Deserialize Base Agent ---
|
|
780
|
+
# Ensure required fields like 'name' are present if needed by __init__
|
|
781
|
+
if "name" not in agent_data:
|
|
768
782
|
raise ValueError(
|
|
769
|
-
|
|
770
|
-
)
|
|
783
|
+
"Agent data must include a 'name' field for deserialization."
|
|
784
|
+
)
|
|
785
|
+
agent_name_log = agent_data["name"] # For logging
|
|
786
|
+
logger.info(f"Deserializing base agent data for '{agent_name_log}'")
|
|
771
787
|
|
|
772
|
-
#
|
|
788
|
+
# Pydantic should handle base fields based on type hints in __init__
|
|
789
|
+
agent = cls(**agent_data)
|
|
790
|
+
logger.debug(f"Base agent '{agent.name}' instantiated.")
|
|
791
|
+
|
|
792
|
+
# --- Deserialize Components ---
|
|
793
|
+
logger.debug(f"Deserializing components for '{agent.name}'")
|
|
773
794
|
# Evaluator
|
|
774
|
-
if
|
|
795
|
+
if "evaluator" in component_configs:
|
|
775
796
|
try:
|
|
776
|
-
logger.debug(
|
|
777
|
-
f"Deserializing evaluator for agent '{agent_name}'"
|
|
778
|
-
)
|
|
779
797
|
agent.evaluator = deserialize_component(
|
|
780
|
-
|
|
781
|
-
)
|
|
782
|
-
if agent.evaluator is None:
|
|
783
|
-
raise ValueError("deserialize_component returned None")
|
|
784
|
-
logger.debug(
|
|
785
|
-
f"Deserialized evaluator '{agent.evaluator.name}' of type '{evaluator_data.get('type')}' for agent '{agent_name}'"
|
|
798
|
+
component_configs["evaluator"], FlockEvaluator
|
|
786
799
|
)
|
|
800
|
+
logger.debug(f"Deserialized evaluator for '{agent.name}'")
|
|
787
801
|
except Exception as e:
|
|
788
802
|
logger.error(
|
|
789
|
-
f"Failed to deserialize evaluator for
|
|
803
|
+
f"Failed to deserialize evaluator for '{agent.name}': {e}",
|
|
790
804
|
exc_info=True,
|
|
791
805
|
)
|
|
792
|
-
# Decide: raise error or continue without evaluator?
|
|
793
|
-
# raise ValueError(f"Failed to deserialize evaluator for agent '{agent_name}': {e}") from e
|
|
794
806
|
|
|
795
|
-
# Router
|
|
796
|
-
if
|
|
807
|
+
# Handoff Router
|
|
808
|
+
if "handoff_router" in component_configs:
|
|
797
809
|
try:
|
|
798
|
-
logger.debug(f"Deserializing router for agent '{agent_name}'")
|
|
799
810
|
agent.handoff_router = deserialize_component(
|
|
800
|
-
|
|
801
|
-
)
|
|
802
|
-
if agent.handoff_router is None:
|
|
803
|
-
raise ValueError("deserialize_component returned None")
|
|
804
|
-
logger.debug(
|
|
805
|
-
f"Deserialized router '{agent.handoff_router.name}' of type '{router_data.get('type')}' for agent '{agent_name}'"
|
|
811
|
+
component_configs["handoff_router"], FlockRouter
|
|
806
812
|
)
|
|
813
|
+
logger.debug(f"Deserialized handoff_router for '{agent.name}'")
|
|
807
814
|
except Exception as e:
|
|
808
815
|
logger.error(
|
|
809
|
-
f"Failed to deserialize
|
|
816
|
+
f"Failed to deserialize handoff_router for '{agent.name}': {e}",
|
|
810
817
|
exc_info=True,
|
|
811
818
|
)
|
|
812
|
-
# Decide: raise error or continue without router?
|
|
813
819
|
|
|
814
820
|
# Modules
|
|
815
|
-
if
|
|
816
|
-
agent.modules = {} #
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
)
|
|
820
|
-
for name, module_data in modules_data.items():
|
|
821
|
+
if "modules" in component_configs:
|
|
822
|
+
agent.modules = {} # Initialize
|
|
823
|
+
for module_name, module_data in component_configs[
|
|
824
|
+
"modules"
|
|
825
|
+
].items():
|
|
821
826
|
try:
|
|
822
|
-
logger.debug(
|
|
823
|
-
f"Deserializing module '{name}' of type '{module_data.get('type')}' for agent '{agent_name}'"
|
|
824
|
-
)
|
|
825
827
|
module_instance = deserialize_component(
|
|
826
828
|
module_data, FlockModule
|
|
827
829
|
)
|
|
828
830
|
if module_instance:
|
|
829
|
-
#
|
|
830
|
-
|
|
831
|
-
agent.add_module(
|
|
832
|
-
module_instance
|
|
833
|
-
) # Use add_module for consistency
|
|
831
|
+
# Use add_module for potential logic within it
|
|
832
|
+
agent.add_module(module_instance)
|
|
834
833
|
logger.debug(
|
|
835
|
-
f"
|
|
834
|
+
f"Deserialized and added module '{module_name}' for '{agent.name}'"
|
|
836
835
|
)
|
|
837
|
-
else:
|
|
838
|
-
raise ValueError("deserialize_component returned None")
|
|
839
836
|
except Exception as e:
|
|
840
837
|
logger.error(
|
|
841
|
-
f"Failed to deserialize module '{
|
|
838
|
+
f"Failed to deserialize module '{module_name}' for '{agent.name}': {e}",
|
|
842
839
|
exc_info=True,
|
|
843
840
|
)
|
|
844
|
-
|
|
841
|
+
|
|
842
|
+
# Temporal Activity Config
|
|
843
|
+
if "temporal_activity_config" in component_configs:
|
|
844
|
+
try:
|
|
845
|
+
agent.temporal_activity_config = TemporalActivityConfig(
|
|
846
|
+
**component_configs["temporal_activity_config"]
|
|
847
|
+
)
|
|
848
|
+
logger.debug(
|
|
849
|
+
f"Deserialized temporal_activity_config for '{agent.name}'"
|
|
850
|
+
)
|
|
851
|
+
except Exception as e:
|
|
852
|
+
logger.error(
|
|
853
|
+
f"Failed to deserialize temporal_activity_config for '{agent.name}': {e}",
|
|
854
|
+
exc_info=True,
|
|
855
|
+
)
|
|
856
|
+
agent.temporal_activity_config = None
|
|
845
857
|
|
|
846
858
|
# --- Deserialize Tools ---
|
|
847
859
|
agent.tools = [] # Initialize tools list
|
|
848
|
-
if
|
|
849
|
-
# Get component registry to look up function imports
|
|
850
|
-
registry = get_registry()
|
|
851
|
-
components = getattr(registry, "_callables", {})
|
|
852
|
-
logger.debug(
|
|
853
|
-
f"Deserializing {len(tools_data)} tools for agent '{agent_name}'"
|
|
854
|
-
)
|
|
860
|
+
if tool_config:
|
|
855
861
|
logger.debug(
|
|
856
|
-
f"
|
|
862
|
+
f"Deserializing {len(tool_config)} tools for '{agent.name}'"
|
|
857
863
|
)
|
|
858
|
-
|
|
859
|
-
for
|
|
864
|
+
# Use get_callable to find each tool
|
|
865
|
+
for tool_name_or_path in tool_config:
|
|
860
866
|
try:
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
for path_str, func in components.items():
|
|
865
|
-
if (
|
|
866
|
-
path_str.endswith("." + tool_name)
|
|
867
|
-
or path_str == tool_name
|
|
868
|
-
):
|
|
869
|
-
agent.tools.append(func)
|
|
870
|
-
found = True
|
|
871
|
-
logger.info(
|
|
872
|
-
f"Found tool '{tool_name}' via path '{path_str}' for agent '{agent_name}'"
|
|
873
|
-
)
|
|
874
|
-
break
|
|
875
|
-
|
|
876
|
-
# If not found by simple name, try manual import
|
|
877
|
-
if not found:
|
|
867
|
+
found_tool = registry.get_callable(tool_name_or_path)
|
|
868
|
+
if found_tool and callable(found_tool):
|
|
869
|
+
agent.tools.append(found_tool)
|
|
878
870
|
logger.debug(
|
|
879
|
-
f"
|
|
871
|
+
f"Resolved and added tool '{tool_name_or_path}' for agent '{agent.name}'"
|
|
880
872
|
)
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
if hasattr(__main__, tool_name):
|
|
885
|
-
agent.tools.append(getattr(__main__, tool_name))
|
|
886
|
-
found = True
|
|
887
|
-
logger.info(
|
|
888
|
-
f"Found tool '{tool_name}' in __main__ module for agent '{agent_name}'"
|
|
889
|
-
)
|
|
890
|
-
|
|
891
|
-
if not found:
|
|
873
|
+
else:
|
|
874
|
+
# Should not happen if get_callable returns successfully but just in case
|
|
892
875
|
logger.warning(
|
|
893
|
-
f"
|
|
876
|
+
f"Registry returned non-callable for tool '{tool_name_or_path}' for agent '{agent.name}'. Skipping."
|
|
894
877
|
)
|
|
878
|
+
except (
|
|
879
|
+
ValueError
|
|
880
|
+
) as e: # get_callable raises ValueError if not found/ambiguous
|
|
881
|
+
logger.warning(
|
|
882
|
+
f"Could not resolve tool '{tool_name_or_path}' for agent '{agent.name}': {e}. Skipping."
|
|
883
|
+
)
|
|
895
884
|
except Exception as e:
|
|
896
885
|
logger.error(
|
|
897
|
-
f"
|
|
886
|
+
f"Unexpected error resolving tool '{tool_name_or_path}' for agent '{agent.name}': {e}. Skipping.",
|
|
898
887
|
exc_info=True,
|
|
899
888
|
)
|
|
900
889
|
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
)
|
|
905
|
-
agent.description = components[description_callable]
|
|
890
|
+
# --- Deserialize Callables ---
|
|
891
|
+
logger.debug(f"Deserializing callable fields for '{agent.name}'")
|
|
892
|
+
# available_callables = registry.get_all_callables() # Incorrect
|
|
906
893
|
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
894
|
+
def resolve_and_assign(field_name: str, callable_key: str):
|
|
895
|
+
if callable_key in callable_configs:
|
|
896
|
+
callable_name = callable_configs[callable_key]
|
|
897
|
+
try:
|
|
898
|
+
# Use get_callable to find the signature function
|
|
899
|
+
found_callable = registry.get_callable(callable_name)
|
|
900
|
+
if found_callable and callable(found_callable):
|
|
901
|
+
setattr(agent, field_name, found_callable)
|
|
902
|
+
logger.debug(
|
|
903
|
+
f"Resolved callable '{callable_name}' for field '{field_name}' on agent '{agent.name}'"
|
|
904
|
+
)
|
|
905
|
+
else:
|
|
906
|
+
logger.warning(
|
|
907
|
+
f"Registry returned non-callable for name '{callable_name}' for field '{field_name}' on agent '{agent.name}'. Field remains default."
|
|
908
|
+
)
|
|
909
|
+
except (
|
|
910
|
+
ValueError
|
|
911
|
+
) as e: # get_callable raises ValueError if not found/ambiguous
|
|
912
|
+
logger.warning(
|
|
913
|
+
f"Could not resolve callable '{callable_name}' in registry for field '{field_name}' on agent '{agent.name}': {e}. Field remains default."
|
|
914
|
+
)
|
|
915
|
+
except Exception as e:
|
|
916
|
+
logger.error(
|
|
917
|
+
f"Unexpected error resolving callable '{callable_name}' for field '{field_name}' on agent '{agent.name}': {e}. Field remains default.",
|
|
918
|
+
exc_info=True,
|
|
919
|
+
)
|
|
920
|
+
# Else: key not present, field retains its default value from __init__
|
|
912
921
|
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
)
|
|
917
|
-
agent.output = components[output_callable]
|
|
922
|
+
resolve_and_assign("description", "description_callable")
|
|
923
|
+
resolve_and_assign("input", "input_callable")
|
|
924
|
+
resolve_and_assign("output", "output_callable")
|
|
918
925
|
|
|
919
|
-
logger.info(
|
|
920
|
-
f"Successfully deserialized agent '{agent_name}' with {len(agent.modules)} modules and {len(agent.tools)} tools"
|
|
921
|
-
)
|
|
926
|
+
logger.info(f"Successfully deserialized agent '{agent.name}'.")
|
|
922
927
|
return agent
|
|
923
928
|
|
|
924
929
|
# --- Pydantic v2 Configuration ---
|
flock/core/flock_factory.py
CHANGED
|
@@ -14,6 +14,7 @@ from flock.modules.performance.metrics_module import (
|
|
|
14
14
|
MetricsModule,
|
|
15
15
|
MetricsModuleConfig,
|
|
16
16
|
)
|
|
17
|
+
from flock.workflow.temporal_config import TemporalActivityConfig
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
class FlockFactory:
|
|
@@ -39,6 +40,7 @@ class FlockFactory:
|
|
|
39
40
|
write_to_file: bool = False,
|
|
40
41
|
stream: bool = False,
|
|
41
42
|
include_thought_process: bool = False,
|
|
43
|
+
temporal_activity_config: TemporalActivityConfig | None = None,
|
|
42
44
|
) -> FlockAgent:
|
|
43
45
|
"""Creates a default FlockAgent.
|
|
44
46
|
|
|
@@ -69,6 +71,7 @@ class FlockFactory:
|
|
|
69
71
|
evaluator=evaluator,
|
|
70
72
|
write_to_file=write_to_file,
|
|
71
73
|
wait_for_input=wait_for_input,
|
|
74
|
+
temporal_activity_config=temporal_activity_config,
|
|
72
75
|
)
|
|
73
76
|
output_config = OutputModuleConfig(
|
|
74
77
|
render_table=enable_rich_tables,
|
flock/core/flock_module.py
CHANGED
|
@@ -52,7 +52,7 @@ class FlockModule(BaseModel, ABC):
|
|
|
52
52
|
default_factory=FlockModuleConfig, description="Module configuration"
|
|
53
53
|
)
|
|
54
54
|
|
|
55
|
-
async def
|
|
55
|
+
async def on_initialize(
|
|
56
56
|
self,
|
|
57
57
|
agent: Any,
|
|
58
58
|
inputs: dict[str, Any],
|
|
@@ -61,7 +61,7 @@ class FlockModule(BaseModel, ABC):
|
|
|
61
61
|
"""Called when the agent starts running."""
|
|
62
62
|
pass
|
|
63
63
|
|
|
64
|
-
async def
|
|
64
|
+
async def on_pre_evaluate(
|
|
65
65
|
self,
|
|
66
66
|
agent: Any,
|
|
67
67
|
inputs: dict[str, Any],
|
|
@@ -70,22 +70,22 @@ class FlockModule(BaseModel, ABC):
|
|
|
70
70
|
"""Called before agent evaluation, can modify inputs."""
|
|
71
71
|
return inputs
|
|
72
72
|
|
|
73
|
-
async def
|
|
73
|
+
async def on_post_evaluate(
|
|
74
74
|
self,
|
|
75
75
|
agent: Any,
|
|
76
76
|
inputs: dict[str, Any],
|
|
77
|
-
result: dict[str, Any],
|
|
78
77
|
context: FlockContext | None = None,
|
|
78
|
+
result: dict[str, Any] | None = None,
|
|
79
79
|
) -> dict[str, Any]:
|
|
80
80
|
"""Called after agent evaluation, can modify results."""
|
|
81
81
|
return result
|
|
82
82
|
|
|
83
|
-
async def
|
|
83
|
+
async def on_terminate(
|
|
84
84
|
self,
|
|
85
85
|
agent: Any,
|
|
86
86
|
inputs: dict[str, Any],
|
|
87
|
-
result: dict[str, Any],
|
|
88
87
|
context: FlockContext | None = None,
|
|
88
|
+
result: dict[str, Any] | None = None,
|
|
89
89
|
) -> None:
|
|
90
90
|
"""Called when the agent finishes running."""
|
|
91
91
|
pass
|
|
@@ -93,9 +93,9 @@ class FlockModule(BaseModel, ABC):
|
|
|
93
93
|
async def on_error(
|
|
94
94
|
self,
|
|
95
95
|
agent: Any,
|
|
96
|
-
error: Exception,
|
|
97
96
|
inputs: dict[str, Any],
|
|
98
97
|
context: FlockContext | None = None,
|
|
98
|
+
error: Exception | None = None,
|
|
99
99
|
) -> None:
|
|
100
100
|
"""Called when an error occurs during agent execution."""
|
|
101
101
|
pass
|
|
@@ -83,7 +83,7 @@ class MemoryModule(FlockModule):
|
|
|
83
83
|
else [{"type": "semantic"}]
|
|
84
84
|
)
|
|
85
85
|
|
|
86
|
-
async def
|
|
86
|
+
async def on_initialize(
|
|
87
87
|
self,
|
|
88
88
|
agent: FlockAgent,
|
|
89
89
|
inputs: dict[str, Any],
|
|
@@ -101,7 +101,7 @@ class MemoryModule(FlockModule):
|
|
|
101
101
|
)
|
|
102
102
|
logger.debug(f"Initialized memory module for agent {agent.name}")
|
|
103
103
|
|
|
104
|
-
async def
|
|
104
|
+
async def on_pre_evaluate(
|
|
105
105
|
self,
|
|
106
106
|
agent: FlockAgent,
|
|
107
107
|
inputs: dict[str, Any],
|
|
@@ -226,7 +226,7 @@ class MemoryModule(FlockModule):
|
|
|
226
226
|
except Exception as e:
|
|
227
227
|
logger.warning(f"Memory storage failed: {e}", agent=agent.name)
|
|
228
228
|
|
|
229
|
-
async def
|
|
229
|
+
async def on_post_evaluate(
|
|
230
230
|
self,
|
|
231
231
|
agent: FlockAgent,
|
|
232
232
|
inputs: dict[str, Any],
|
|
@@ -245,7 +245,7 @@ class MemoryModule(FlockModule):
|
|
|
245
245
|
|
|
246
246
|
return result
|
|
247
247
|
|
|
248
|
-
async def
|
|
248
|
+
async def on_terminate(
|
|
249
249
|
self,
|
|
250
250
|
agent: Any,
|
|
251
251
|
inputs: dict[str, Any],
|
|
@@ -227,7 +227,7 @@ class MetricsModule(FlockModule):
|
|
|
227
227
|
|
|
228
228
|
return stats
|
|
229
229
|
|
|
230
|
-
async def
|
|
230
|
+
async def on_terminate(
|
|
231
231
|
self,
|
|
232
232
|
agent: FlockAgent,
|
|
233
233
|
inputs: dict[str, Any],
|
|
@@ -340,7 +340,7 @@ class MetricsModule(FlockModule):
|
|
|
340
340
|
return value * 1000 > self.config.latency_threshold_ms
|
|
341
341
|
return False
|
|
342
342
|
|
|
343
|
-
async def
|
|
343
|
+
async def on_initialize(
|
|
344
344
|
self,
|
|
345
345
|
agent: FlockAgent,
|
|
346
346
|
inputs: dict[str, Any],
|
|
@@ -382,7 +382,7 @@ class MetricsModule(FlockModule):
|
|
|
382
382
|
total_cost = 0.0
|
|
383
383
|
return token_count, total_cost
|
|
384
384
|
|
|
385
|
-
async def
|
|
385
|
+
async def on_pre_evaluate(
|
|
386
386
|
self,
|
|
387
387
|
agent: FlockAgent,
|
|
388
388
|
inputs: dict[str, Any],
|
|
@@ -423,7 +423,7 @@ class MetricsModule(FlockModule):
|
|
|
423
423
|
|
|
424
424
|
return inputs
|
|
425
425
|
|
|
426
|
-
async def
|
|
426
|
+
async def on_post_evaluate(
|
|
427
427
|
self,
|
|
428
428
|
agent: FlockAgent,
|
|
429
429
|
inputs: dict[str, Any],
|
flock/modules/zep/zep_module.py
CHANGED
|
@@ -141,7 +141,7 @@ class ZepModule(FlockModule):
|
|
|
141
141
|
return []
|
|
142
142
|
return response.results
|
|
143
143
|
|
|
144
|
-
async def
|
|
144
|
+
async def on_post_evaluate(
|
|
145
145
|
self,
|
|
146
146
|
agent: FlockAgent,
|
|
147
147
|
inputs: dict[str, Any],
|
|
@@ -158,7 +158,7 @@ class ZepModule(FlockModule):
|
|
|
158
158
|
self.add_to_memory(str(result), zep_client)
|
|
159
159
|
return result
|
|
160
160
|
|
|
161
|
-
async def
|
|
161
|
+
async def on_pre_evaluate(
|
|
162
162
|
self,
|
|
163
163
|
agent: FlockAgent,
|
|
164
164
|
inputs: dict[str, Any],
|