flock-core 0.4.527__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.527.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.527.dist-info/METADATA +0 -674
- {flock_core-0.4.527.dist-info → flock_core-0.5.0b0.dist-info}/WHEEL +0 -0
- {flock_core-0.4.527.dist-info → flock_core-0.5.0b0.dist-info}/entry_points.txt +0 -0
- {flock_core-0.4.527.dist-info → flock_core-0.5.0b0.dist-info}/licenses/LICENSE +0 -0
flock/core/flock_router.py
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"""Base router class for the Flock framework."""
|
|
2
|
-
|
|
3
|
-
from abc import ABC, abstractmethod
|
|
4
|
-
from typing import Any, Literal
|
|
5
|
-
|
|
6
|
-
from pydantic import BaseModel, Field
|
|
7
|
-
|
|
8
|
-
from flock.core.context.context import FlockContext
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class HandOffRequest(BaseModel):
|
|
12
|
-
"""Base class for handoff returns."""
|
|
13
|
-
|
|
14
|
-
next_agent: str = Field(default="", description="Next agent to invoke")
|
|
15
|
-
# match = use the output fields of the current agent that also exists as input field of the next agent
|
|
16
|
-
# add = add the output of the current agent to the input of the next agent
|
|
17
|
-
output_to_input_merge_strategy: Literal["match", "add"] = Field(
|
|
18
|
-
default="match"
|
|
19
|
-
)
|
|
20
|
-
add_input_fields: list[str] | None = Field(
|
|
21
|
-
default=None,
|
|
22
|
-
description="List of input fields to add to the next agent",
|
|
23
|
-
)
|
|
24
|
-
add_output_fields: list[str] | None = Field(
|
|
25
|
-
default=None,
|
|
26
|
-
description="List of output fields to add to the next agent",
|
|
27
|
-
)
|
|
28
|
-
add_description: str | None = Field(
|
|
29
|
-
default=None, description="Add this description to the next agent"
|
|
30
|
-
)
|
|
31
|
-
override_next_agent: Any | None = Field(
|
|
32
|
-
default=None,
|
|
33
|
-
description="Override the next agent to hand off to",
|
|
34
|
-
)
|
|
35
|
-
override_context: FlockContext | None = Field(
|
|
36
|
-
default=None, description="Override context parameters"
|
|
37
|
-
)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
class FlockRouterConfig(BaseModel):
|
|
41
|
-
"""Configuration for a router.
|
|
42
|
-
|
|
43
|
-
This class defines the configuration parameters for a router.
|
|
44
|
-
Subclasses can extend this to add additional parameters.
|
|
45
|
-
"""
|
|
46
|
-
|
|
47
|
-
enabled: bool = Field(
|
|
48
|
-
default=True, description="Whether the router is enabled"
|
|
49
|
-
)
|
|
50
|
-
# agents: list[str] | None = Field(
|
|
51
|
-
# default=None,
|
|
52
|
-
# description="List of agents to choose from",
|
|
53
|
-
# )
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
class FlockRouter(BaseModel, ABC):
|
|
57
|
-
"""Base class for all routers.
|
|
58
|
-
|
|
59
|
-
A router is responsible for determining the next agent in a workflow
|
|
60
|
-
based on the current agent's output.
|
|
61
|
-
"""
|
|
62
|
-
|
|
63
|
-
name: str = Field(..., description="Name of the router")
|
|
64
|
-
config: FlockRouterConfig = Field(default_factory=FlockRouterConfig)
|
|
65
|
-
|
|
66
|
-
@abstractmethod
|
|
67
|
-
async def route(
|
|
68
|
-
self,
|
|
69
|
-
current_agent: Any,
|
|
70
|
-
result: dict[str, Any],
|
|
71
|
-
context: FlockContext,
|
|
72
|
-
) -> HandOffRequest:
|
|
73
|
-
"""Determine the next agent to hand off to based on the current agent's output.
|
|
74
|
-
|
|
75
|
-
Args:
|
|
76
|
-
current_agent: The agent that just completed execution
|
|
77
|
-
result: The output from the current agent
|
|
78
|
-
context: The global execution context
|
|
79
|
-
|
|
80
|
-
Returns:
|
|
81
|
-
A HandOff object containing the next agent and input data
|
|
82
|
-
"""
|
|
83
|
-
pass
|
flock/evaluators/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Package for modules
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Package for modules
|
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
from collections.abc import Generator
|
|
2
|
-
from typing import Any
|
|
3
|
-
|
|
4
|
-
from temporalio import workflow
|
|
5
|
-
|
|
6
|
-
with workflow.unsafe.imports_passed_through():
|
|
7
|
-
import dspy
|
|
8
|
-
|
|
9
|
-
from pydantic import Field, PrivateAttr
|
|
10
|
-
|
|
11
|
-
from flock.core.flock_agent import FlockAgent
|
|
12
|
-
from flock.core.flock_evaluator import FlockEvaluator, FlockEvaluatorConfig
|
|
13
|
-
from flock.core.flock_registry import flock_component
|
|
14
|
-
from flock.core.logging.logging import get_logger
|
|
15
|
-
from flock.core.mixin.dspy_integration import DSPyIntegrationMixin
|
|
16
|
-
from flock.core.mixin.prompt_parser import PromptParserMixin
|
|
17
|
-
|
|
18
|
-
logger = get_logger("evaluators.declarative")
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class DeclarativeEvaluatorConfig(FlockEvaluatorConfig):
|
|
22
|
-
"""Configuration for the DeclarativeEvaluator."""
|
|
23
|
-
|
|
24
|
-
override_evaluator_type: str | None = None
|
|
25
|
-
model: str | None = "openai/gpt-4o"
|
|
26
|
-
use_cache: bool = True
|
|
27
|
-
temperature: float = 0.0
|
|
28
|
-
max_tokens: int = 4096
|
|
29
|
-
max_retries: int = 3
|
|
30
|
-
max_tool_calls: int = 10
|
|
31
|
-
stream: bool = Field(
|
|
32
|
-
default=False,
|
|
33
|
-
description="Enable streaming output from the underlying DSPy program.",
|
|
34
|
-
)
|
|
35
|
-
include_thought_process: bool = Field(
|
|
36
|
-
default=False,
|
|
37
|
-
description="Include the thought process in the output.",
|
|
38
|
-
)
|
|
39
|
-
include_reasoning: bool = Field(
|
|
40
|
-
default=False,
|
|
41
|
-
description="Include the reasoning in the output.",
|
|
42
|
-
)
|
|
43
|
-
kwargs: dict[str, Any] = Field(default_factory=dict)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
@flock_component(config_class=DeclarativeEvaluatorConfig)
|
|
47
|
-
class DeclarativeEvaluator(
|
|
48
|
-
FlockEvaluator, DSPyIntegrationMixin, PromptParserMixin
|
|
49
|
-
):
|
|
50
|
-
"""Evaluator that uses DSPy for generation."""
|
|
51
|
-
|
|
52
|
-
config: DeclarativeEvaluatorConfig = Field(
|
|
53
|
-
default_factory=DeclarativeEvaluatorConfig,
|
|
54
|
-
description="Evaluator configuration",
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
_cost: float = PrivateAttr(default=0.0)
|
|
58
|
-
_lm_history: list = PrivateAttr(default_factory=list)
|
|
59
|
-
|
|
60
|
-
# def __init__(self, name: str, config: DeclarativeEvaluatorConfig) -> None:
|
|
61
|
-
# super().__init__(name=name, config=config)
|
|
62
|
-
# self._configure_language_model(
|
|
63
|
-
# model=config.model,
|
|
64
|
-
# use_cache=config.use_cache,
|
|
65
|
-
# temperature=config.temperature,
|
|
66
|
-
# max_tokens=config.max_tokens,
|
|
67
|
-
# )
|
|
68
|
-
|
|
69
|
-
async def evaluate(
|
|
70
|
-
self,
|
|
71
|
-
agent: FlockAgent,
|
|
72
|
-
inputs: dict[str, Any],
|
|
73
|
-
tools: list[Any],
|
|
74
|
-
mcp_tools: list[Any] | None = None,
|
|
75
|
-
) -> dict[str, Any]:
|
|
76
|
-
"""Evaluate using DSPy, with optional asynchronous streaming."""
|
|
77
|
-
# --- Setup Signature and LM ---
|
|
78
|
-
|
|
79
|
-
with dspy.context(
|
|
80
|
-
lm=dspy.LM(
|
|
81
|
-
model=self.config.model or agent.model,
|
|
82
|
-
cache=self.config.use_cache,
|
|
83
|
-
temperature=self.config.temperature,
|
|
84
|
-
max_tokens=self.config.max_tokens,
|
|
85
|
-
num_retries=self.config.max_retries,
|
|
86
|
-
)
|
|
87
|
-
):
|
|
88
|
-
try:
|
|
89
|
-
from rich.console import Console
|
|
90
|
-
|
|
91
|
-
console = Console()
|
|
92
|
-
_dspy_signature = self.create_dspy_signature_class(
|
|
93
|
-
agent.name,
|
|
94
|
-
agent.description,
|
|
95
|
-
f"{agent.input} -> {agent.output}",
|
|
96
|
-
)
|
|
97
|
-
# --- Get output field names ---
|
|
98
|
-
# dspy.Signature holds fields in .output_fields attribute
|
|
99
|
-
output_field_names = list(_dspy_signature.output_fields.keys())
|
|
100
|
-
if not output_field_names:
|
|
101
|
-
logger.warning(
|
|
102
|
-
f"DSPy signature for agent '{agent.name}' has no defined output fields. Streaming might not produce text."
|
|
103
|
-
)
|
|
104
|
-
# -----------------------------
|
|
105
|
-
|
|
106
|
-
agent_task = self._select_task(
|
|
107
|
-
_dspy_signature,
|
|
108
|
-
override_evaluator_type=self.config.override_evaluator_type,
|
|
109
|
-
tools=tools,
|
|
110
|
-
max_tool_calls=self.config.max_tool_calls,
|
|
111
|
-
mcp_tools=mcp_tools,
|
|
112
|
-
kwargs=self.config.kwargs,
|
|
113
|
-
)
|
|
114
|
-
except Exception as setup_error:
|
|
115
|
-
logger.error(
|
|
116
|
-
f"Error setting up DSPy task for agent '{agent.name}': {setup_error}",
|
|
117
|
-
exc_info=True,
|
|
118
|
-
)
|
|
119
|
-
raise RuntimeError(
|
|
120
|
-
f"DSPy task setup failed: {setup_error}"
|
|
121
|
-
) from setup_error
|
|
122
|
-
|
|
123
|
-
# --- Conditional Evaluation (Stream vs No Stream) ---
|
|
124
|
-
if self.config.stream:
|
|
125
|
-
logger.info(
|
|
126
|
-
f"Evaluating agent '{agent.name}' with async streaming."
|
|
127
|
-
)
|
|
128
|
-
if not callable(agent_task):
|
|
129
|
-
logger.error("agent_task is not callable, cannot stream.")
|
|
130
|
-
raise TypeError(
|
|
131
|
-
"DSPy task could not be created or is not callable."
|
|
132
|
-
)
|
|
133
|
-
|
|
134
|
-
streaming_task = dspy.streamify(
|
|
135
|
-
agent_task, is_async_program=True
|
|
136
|
-
)
|
|
137
|
-
stream_generator: Generator = streaming_task(**inputs)
|
|
138
|
-
delta_content = ""
|
|
139
|
-
|
|
140
|
-
console.print("\n")
|
|
141
|
-
async for chunk in stream_generator:
|
|
142
|
-
if (
|
|
143
|
-
hasattr(chunk, "choices")
|
|
144
|
-
and chunk.choices
|
|
145
|
-
and hasattr(chunk.choices[0], "delta")
|
|
146
|
-
and chunk.choices[0].delta
|
|
147
|
-
and hasattr(chunk.choices[0].delta, "content")
|
|
148
|
-
):
|
|
149
|
-
delta_content = chunk.choices[0].delta.content
|
|
150
|
-
|
|
151
|
-
if delta_content:
|
|
152
|
-
console.print(delta_content, end="")
|
|
153
|
-
|
|
154
|
-
result_dict, cost, lm_history = self._process_result(
|
|
155
|
-
chunk, inputs
|
|
156
|
-
)
|
|
157
|
-
self._cost = cost
|
|
158
|
-
self._lm_history = lm_history
|
|
159
|
-
|
|
160
|
-
console.print("\n")
|
|
161
|
-
result_dict = self.filter_reasoning(
|
|
162
|
-
result_dict, self.config.include_reasoning
|
|
163
|
-
)
|
|
164
|
-
return self.filter_thought_process(
|
|
165
|
-
result_dict, self.config.include_thought_process
|
|
166
|
-
)
|
|
167
|
-
|
|
168
|
-
else: # Non-streaming path
|
|
169
|
-
logger.info(
|
|
170
|
-
f"Evaluating agent '{agent.name}' without streaming."
|
|
171
|
-
)
|
|
172
|
-
try:
|
|
173
|
-
# Ensure the call is awaited if the underlying task is async
|
|
174
|
-
result_obj = await agent_task.acall(**inputs)
|
|
175
|
-
result_dict, cost, lm_history = self._process_result(
|
|
176
|
-
result_obj, inputs
|
|
177
|
-
)
|
|
178
|
-
self._cost = cost
|
|
179
|
-
self._lm_history = lm_history
|
|
180
|
-
result_dict = self.filter_reasoning(
|
|
181
|
-
result_dict, self.config.include_reasoning
|
|
182
|
-
)
|
|
183
|
-
return self.filter_thought_process(
|
|
184
|
-
result_dict, self.config.include_thought_process
|
|
185
|
-
)
|
|
186
|
-
except Exception as e:
|
|
187
|
-
logger.error(
|
|
188
|
-
f"Error during non-streaming evaluation for agent '{agent.name}': {e}",
|
|
189
|
-
exc_info=True,
|
|
190
|
-
)
|
|
191
|
-
raise RuntimeError(f"Evaluation failed: {e}") from e
|
|
192
|
-
|
|
193
|
-
def filter_thought_process(
|
|
194
|
-
self, result_dict: dict[str, Any], include_thought_process: bool
|
|
195
|
-
) -> dict[str, Any]:
|
|
196
|
-
"""Filter out thought process from the result dictionary."""
|
|
197
|
-
if include_thought_process:
|
|
198
|
-
return result_dict
|
|
199
|
-
else:
|
|
200
|
-
return {
|
|
201
|
-
k: v
|
|
202
|
-
for k, v in result_dict.items()
|
|
203
|
-
if not (k.startswith("trajectory"))
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
def filter_reasoning(
|
|
207
|
-
self, result_dict: dict[str, Any], include_reasoning: bool
|
|
208
|
-
) -> dict[str, Any]:
|
|
209
|
-
"""Filter out reasoning from the result dictionary."""
|
|
210
|
-
if include_reasoning:
|
|
211
|
-
return result_dict
|
|
212
|
-
else:
|
|
213
|
-
return {
|
|
214
|
-
k: v
|
|
215
|
-
for k, v in result_dict.items()
|
|
216
|
-
if not (k.startswith("reasoning"))
|
|
217
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
from typing import Any, Literal
|
|
2
|
-
|
|
3
|
-
from pydantic import Field
|
|
4
|
-
|
|
5
|
-
from flock.core.flock_agent import FlockAgent
|
|
6
|
-
from flock.core.flock_evaluator import FlockEvaluator, FlockEvaluatorConfig
|
|
7
|
-
from flock.core.flock_registry import flock_component
|
|
8
|
-
from flock.core.mixin.dspy_integration import DSPyIntegrationMixin
|
|
9
|
-
from flock.core.mixin.prompt_parser import PromptParserMixin
|
|
10
|
-
from flock.modules.memory.memory_module import MemoryModule, MemoryModuleConfig
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class MemoryEvaluatorConfig(FlockEvaluatorConfig):
|
|
14
|
-
folder_path: str = Field(
|
|
15
|
-
default="concept_memory/",
|
|
16
|
-
description="Directory where memory file and concept graph will be saved",
|
|
17
|
-
)
|
|
18
|
-
concept_graph_file: str = Field(
|
|
19
|
-
default="concept_graph.png",
|
|
20
|
-
description="Base filename for the concept graph image",
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
file_path: str | None = Field(
|
|
24
|
-
default="agent_memory.json", description="Path to save memory file"
|
|
25
|
-
)
|
|
26
|
-
memory_mapping: str | None = Field(
|
|
27
|
-
default=None, description="Memory mapping configuration"
|
|
28
|
-
)
|
|
29
|
-
similarity_threshold: float = Field(
|
|
30
|
-
default=0.5, description="Threshold for semantic similarity"
|
|
31
|
-
)
|
|
32
|
-
max_length: int = Field(
|
|
33
|
-
default=1000, description="Max length of memory entry before splitting"
|
|
34
|
-
)
|
|
35
|
-
save_after_update: bool = Field(
|
|
36
|
-
default=True, description="Whether to save memory after each update"
|
|
37
|
-
)
|
|
38
|
-
splitting_mode: Literal["summary", "semantic", "characters", "none"] = (
|
|
39
|
-
Field(default="none", description="Mode to split memory content")
|
|
40
|
-
)
|
|
41
|
-
enable_read_only_mode: bool = Field(
|
|
42
|
-
default=False, description="Whether to enable read only mode"
|
|
43
|
-
)
|
|
44
|
-
number_of_concepts_to_extract: int = Field(
|
|
45
|
-
default=3, description="Number of concepts to extract from the memory"
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
@flock_component(config_class=MemoryEvaluatorConfig)
|
|
50
|
-
class MemoryEvaluator(FlockEvaluator, DSPyIntegrationMixin, PromptParserMixin):
|
|
51
|
-
"""Evaluator that uses DSPy for generation."""
|
|
52
|
-
|
|
53
|
-
config: MemoryEvaluatorConfig = Field(
|
|
54
|
-
default_factory=MemoryEvaluatorConfig,
|
|
55
|
-
description="Evaluator configuration",
|
|
56
|
-
)
|
|
57
|
-
|
|
58
|
-
async def evaluate(
|
|
59
|
-
self, agent: FlockAgent, inputs: dict[str, Any], tools: list[Any]
|
|
60
|
-
) -> dict[str, Any]:
|
|
61
|
-
"""Simple evaluator that uses a memory concept graph.
|
|
62
|
-
|
|
63
|
-
if inputs contain "query", it searches memory for the query and returns the facts.
|
|
64
|
-
if inputs contain "data", it adds the data to memory
|
|
65
|
-
"""
|
|
66
|
-
result = {}
|
|
67
|
-
memory_module = MemoryModule(
|
|
68
|
-
name=self.name,
|
|
69
|
-
config=MemoryModuleConfig(
|
|
70
|
-
folder_path=self.config.folder_path,
|
|
71
|
-
concept_graph_file=self.config.concept_graph_file,
|
|
72
|
-
file_path=self.config.file_path,
|
|
73
|
-
memory_mapping=self.config.memory_mapping,
|
|
74
|
-
similarity_threshold=self.config.similarity_threshold,
|
|
75
|
-
max_length=self.config.max_length,
|
|
76
|
-
save_after_update=self.config.save_after_update,
|
|
77
|
-
splitting_mode=self.config.splitting_mode,
|
|
78
|
-
enable_read_only_mode=self.config.enable_read_only_mode,
|
|
79
|
-
number_of_concepts_to_extract=self.config.number_of_concepts_to_extract,
|
|
80
|
-
),
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
if "query" in inputs:
|
|
84
|
-
facts = await memory_module.search_memory(agent, inputs)
|
|
85
|
-
result = {"facts": facts}
|
|
86
|
-
|
|
87
|
-
if "data" in inputs:
|
|
88
|
-
await memory_module.add_to_memory(agent, inputs)
|
|
89
|
-
result = {"message": "Data added to memory"}
|
|
90
|
-
return result
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
|
-
from pydantic import Field
|
|
4
|
-
|
|
5
|
-
from flock.core.flock_agent import FlockAgent
|
|
6
|
-
from flock.core.flock_evaluator import FlockEvaluator, FlockEvaluatorConfig
|
|
7
|
-
from flock.core.flock_registry import flock_component
|
|
8
|
-
from flock.core.mixin.dspy_integration import DSPyIntegrationMixin
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
class TestCaseEvaluatorConfig(FlockEvaluatorConfig):
|
|
12
|
-
"""Configuration for the TestCaseEvaluator."""
|
|
13
|
-
|
|
14
|
-
pass
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@flock_component(config_class=TestCaseEvaluatorConfig)
|
|
18
|
-
class TestCaseEvaluator(FlockEvaluator, DSPyIntegrationMixin):
|
|
19
|
-
"""Evaluator for test cases."""
|
|
20
|
-
|
|
21
|
-
config: TestCaseEvaluatorConfig = Field(
|
|
22
|
-
default_factory=TestCaseEvaluatorConfig,
|
|
23
|
-
description="Evaluator configuration",
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
async def evaluate(
|
|
27
|
-
self, agent: FlockAgent, inputs: dict[str, Any], tools: list[Any]
|
|
28
|
-
) -> dict[str, Any]:
|
|
29
|
-
_dspy_signature = self.create_dspy_signature_class(
|
|
30
|
-
agent.name,
|
|
31
|
-
agent.description,
|
|
32
|
-
f"{agent.input} -> {agent.output}",
|
|
33
|
-
)
|
|
34
|
-
output_field_names = list(_dspy_signature.output_fields.keys())
|
|
35
|
-
result = {}
|
|
36
|
-
for output_field_name in output_field_names:
|
|
37
|
-
result[output_field_name] = "Test Result"
|
|
38
|
-
return result
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
from typing import Any
|
|
2
|
-
|
|
3
|
-
from pydantic import Field
|
|
4
|
-
|
|
5
|
-
from flock.core.flock_agent import FlockAgent
|
|
6
|
-
from flock.core.flock_evaluator import FlockEvaluator, FlockEvaluatorConfig
|
|
7
|
-
from flock.core.flock_registry import flock_component
|
|
8
|
-
from flock.core.mixin.dspy_integration import DSPyIntegrationMixin
|
|
9
|
-
from flock.core.mixin.prompt_parser import PromptParserMixin
|
|
10
|
-
from flock.modules.zep.zep_module import ZepModule, ZepModuleConfig
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
class ZepEvaluatorConfig(FlockEvaluatorConfig):
|
|
14
|
-
zep_url: str = "http://localhost:8000"
|
|
15
|
-
zep_api_key: str = "apikey"
|
|
16
|
-
min_fact_rating: float = Field(
|
|
17
|
-
default=0.7, description="Minimum rating for facts to be considered"
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@flock_component(config_class=ZepEvaluatorConfig)
|
|
22
|
-
class ZepEvaluator(FlockEvaluator, DSPyIntegrationMixin, PromptParserMixin):
|
|
23
|
-
"""Evaluator that uses DSPy for generation."""
|
|
24
|
-
|
|
25
|
-
config: ZepEvaluatorConfig = Field(
|
|
26
|
-
default_factory=ZepEvaluatorConfig,
|
|
27
|
-
description="Evaluator configuration",
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
async def evaluate(
|
|
31
|
-
self, agent: FlockAgent, inputs: dict[str, Any], tools: list[Any]
|
|
32
|
-
) -> dict[str, Any]:
|
|
33
|
-
"""Simple evaluator that uses Zep.
|
|
34
|
-
|
|
35
|
-
if inputs contain "query", it searches memory for the query and returns the facts.
|
|
36
|
-
if inputs contain "data", it adds the data to memory
|
|
37
|
-
"""
|
|
38
|
-
result = {}
|
|
39
|
-
zep = ZepModule(
|
|
40
|
-
name=self.name,
|
|
41
|
-
config=ZepModuleConfig(
|
|
42
|
-
zep_api_key=self.config.zep_api_key,
|
|
43
|
-
zep_url=self.config.zep_url,
|
|
44
|
-
min_fact_rating=self.config.min_fact_rating,
|
|
45
|
-
enable_read=True,
|
|
46
|
-
enable_write=True,
|
|
47
|
-
),
|
|
48
|
-
)
|
|
49
|
-
client = zep.get_client()
|
|
50
|
-
if "query" in inputs:
|
|
51
|
-
query = inputs["query"]
|
|
52
|
-
facts = zep.search_memory(query, client)
|
|
53
|
-
result = {"facts": facts}
|
|
54
|
-
|
|
55
|
-
if "data" in inputs:
|
|
56
|
-
data = inputs["data"]
|
|
57
|
-
zep.add_to_memory(data, client)
|
|
58
|
-
result = {"message": "Data added to memory"}
|
|
59
|
-
return result
|
flock/modules/__init__.py
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Package for modules
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Package for modules
|