flock-core 0.4.0b46__py3-none-any.whl → 0.4.0b49__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/__init__.py +45 -3
- flock/core/flock.py +105 -61
- flock/core/flock_registry.py +45 -38
- flock/core/util/spliter.py +4 -0
- flock/evaluators/__init__.py +1 -0
- flock/evaluators/declarative/__init__.py +1 -0
- flock/modules/__init__.py +1 -0
- flock/modules/assertion/__init__.py +1 -0
- flock/modules/callback/__init__.py +1 -0
- flock/modules/mem0/__init__.py +1 -0
- flock/modules/mem0/mem0_module.py +63 -0
- flock/modules/mem0graph/__init__.py +1 -0
- flock/modules/mem0graph/mem0_graph_module.py +63 -0
- flock/modules/memory/__init__.py +1 -0
- flock/modules/output/__init__.py +1 -0
- flock/modules/performance/__init__.py +1 -0
- flock/tools/__init__.py +188 -0
- flock/{core/tools → tools}/azure_tools.py +284 -0
- flock/tools/code_tools.py +56 -0
- flock/tools/file_tools.py +140 -0
- flock/{core/tools/dev_tools/github.py → tools/github_tools.py} +3 -3
- flock/{core/tools → tools}/markdown_tools.py +14 -4
- flock/tools/system_tools.py +9 -0
- flock/{core/tools/llm_tools.py → tools/text_tools.py} +47 -25
- flock/tools/web_tools.py +90 -0
- flock/{core/tools → tools}/zendesk_tools.py +6 -6
- flock/webapp/app/api/execution.py +130 -30
- flock/webapp/app/chat.py +303 -16
- flock/webapp/app/config.py +15 -1
- flock/webapp/app/dependencies.py +22 -0
- flock/webapp/app/main.py +509 -18
- flock/webapp/app/services/flock_service.py +38 -13
- flock/webapp/app/services/sharing_models.py +43 -0
- flock/webapp/app/services/sharing_store.py +156 -0
- flock/webapp/static/css/chat.css +57 -0
- flock/webapp/templates/chat.html +29 -4
- flock/webapp/templates/partials/_chat_messages.html +1 -1
- flock/webapp/templates/partials/_chat_settings_form.html +22 -0
- flock/webapp/templates/partials/_execution_form.html +28 -1
- flock/webapp/templates/partials/_share_chat_link_snippet.html +11 -0
- flock/webapp/templates/partials/_share_link_snippet.html +35 -0
- flock/webapp/templates/shared_run_page.html +116 -0
- flock/workflow/activities.py +1 -0
- {flock_core-0.4.0b46.dist-info → flock_core-0.4.0b49.dist-info}/METADATA +27 -14
- {flock_core-0.4.0b46.dist-info → flock_core-0.4.0b49.dist-info}/RECORD +48 -28
- flock/core/tools/basic_tools.py +0 -317
- flock/modules/zep/zep_module.py +0 -187
- {flock_core-0.4.0b46.dist-info → flock_core-0.4.0b49.dist-info}/WHEEL +0 -0
- {flock_core-0.4.0b46.dist-info → flock_core-0.4.0b49.dist-info}/entry_points.txt +0 -0
- {flock_core-0.4.0b46.dist-info → flock_core-0.4.0b49.dist-info}/licenses/LICENSE +0 -0
flock/modules/zep/zep_module.py
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import uuid
|
|
2
|
-
from typing import Any
|
|
3
|
-
|
|
4
|
-
from pydantic import Field
|
|
5
|
-
from zep_python.client import Zep
|
|
6
|
-
from zep_python.types import Message as ZepMessage, SessionSearchResult
|
|
7
|
-
|
|
8
|
-
from flock.core.context.context import FlockContext
|
|
9
|
-
from flock.core.flock_agent import FlockAgent
|
|
10
|
-
from flock.core.flock_module import FlockModule, FlockModuleConfig
|
|
11
|
-
from flock.core.flock_registry import flock_component
|
|
12
|
-
from flock.core.logging.logging import get_logger
|
|
13
|
-
|
|
14
|
-
logger = get_logger("module.zep")
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class ZepModuleConfig(FlockModuleConfig):
|
|
18
|
-
"""Configuration for the Zep module."""
|
|
19
|
-
|
|
20
|
-
zep_url: str = "http://localhost:8000"
|
|
21
|
-
zep_api_key: str = "apikey"
|
|
22
|
-
min_fact_rating: float = Field(
|
|
23
|
-
default=0.7, description="Minimum rating for facts to be considered"
|
|
24
|
-
)
|
|
25
|
-
enable_read: bool = True
|
|
26
|
-
enable_write: bool = False
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
@flock_component(config_class=ZepModuleConfig)
|
|
30
|
-
class ZepModule(FlockModule):
|
|
31
|
-
"""Module that adds Zep capabilities to a Flock agent."""
|
|
32
|
-
|
|
33
|
-
name: str = "zep"
|
|
34
|
-
config: ZepModuleConfig = ZepModuleConfig()
|
|
35
|
-
session_id: str | None = None
|
|
36
|
-
user_id: str | None = None
|
|
37
|
-
|
|
38
|
-
def __init__(self, name, config: ZepModuleConfig) -> None:
|
|
39
|
-
"""Initialize Zep module."""
|
|
40
|
-
super().__init__(name=name, config=config)
|
|
41
|
-
logger.debug("Initializing Zep module")
|
|
42
|
-
zep_client = Zep(
|
|
43
|
-
base_url=self.config.zep_url, api_key=self.config.zep_api_key
|
|
44
|
-
)
|
|
45
|
-
self.user_id = self.name
|
|
46
|
-
self._setup_user(zep_client)
|
|
47
|
-
self.session_id = str(uuid.uuid4())
|
|
48
|
-
self._setup_session(zep_client)
|
|
49
|
-
|
|
50
|
-
def _setup_user(self, zep_client: Zep) -> None:
|
|
51
|
-
"""Set up user in Zep."""
|
|
52
|
-
if not zep_client or not self.user_id:
|
|
53
|
-
raise ValueError("Zep service or user_id not initialized")
|
|
54
|
-
|
|
55
|
-
try:
|
|
56
|
-
user = zep_client.user.get(user_id=self.user_id)
|
|
57
|
-
if not user:
|
|
58
|
-
zep_client.user.add(user_id=self.user_id)
|
|
59
|
-
except Exception:
|
|
60
|
-
zep_client.user.add(user_id=self.user_id)
|
|
61
|
-
|
|
62
|
-
def _setup_session(self, zep_client: Zep) -> None:
|
|
63
|
-
"""Set up new session."""
|
|
64
|
-
if not zep_client or not self.user_id or not self.session_id:
|
|
65
|
-
raise ValueError(
|
|
66
|
-
"Zep service, user_id, or session_id not initialized"
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
zep_client.memory.add_session(
|
|
70
|
-
user_id=self.user_id,
|
|
71
|
-
session_id=self.session_id,
|
|
72
|
-
)
|
|
73
|
-
|
|
74
|
-
def get_client(self) -> Zep:
|
|
75
|
-
"""Get Zep client."""
|
|
76
|
-
return Zep(
|
|
77
|
-
base_url=self.config.zep_url, api_key=self.config.zep_api_key
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
def get_memory(self, zep_client: Zep) -> str | None:
|
|
81
|
-
"""Get memory for the current session."""
|
|
82
|
-
if not zep_client or not self.session_id:
|
|
83
|
-
logger.error("Zep service or session_id not initialized")
|
|
84
|
-
return None
|
|
85
|
-
|
|
86
|
-
try:
|
|
87
|
-
memory = zep_client.memory.get(
|
|
88
|
-
self.session_id, min_rating=self.config.min_fact_rating
|
|
89
|
-
)
|
|
90
|
-
if memory:
|
|
91
|
-
return f"{memory.relevant_facts}"
|
|
92
|
-
except Exception as e:
|
|
93
|
-
logger.error(f"Error fetching memory: {e}")
|
|
94
|
-
return None
|
|
95
|
-
|
|
96
|
-
return None
|
|
97
|
-
|
|
98
|
-
def split_text(
|
|
99
|
-
self, text: str | None, max_length: int = 1000
|
|
100
|
-
) -> list[ZepMessage]:
|
|
101
|
-
"""Split text into smaller chunks."""
|
|
102
|
-
result: list[ZepMessage] = []
|
|
103
|
-
if not text:
|
|
104
|
-
return result
|
|
105
|
-
if len(text) <= max_length:
|
|
106
|
-
return [ZepMessage(role="user", content=text, role_type="user")]
|
|
107
|
-
for i in range(0, len(text), max_length):
|
|
108
|
-
result.append(
|
|
109
|
-
ZepMessage(
|
|
110
|
-
role="user",
|
|
111
|
-
content=text[i : i + max_length],
|
|
112
|
-
role_type="user",
|
|
113
|
-
)
|
|
114
|
-
)
|
|
115
|
-
return result
|
|
116
|
-
|
|
117
|
-
def add_to_memory(self, text: str, zep_client: Zep) -> None:
|
|
118
|
-
"""Add text to memory."""
|
|
119
|
-
if not zep_client or not self.session_id:
|
|
120
|
-
logger.error("Zep service or session_id not initialized")
|
|
121
|
-
return
|
|
122
|
-
|
|
123
|
-
messages = self.split_text(text)
|
|
124
|
-
zep_client.memory.add(session_id=self.session_id, messages=messages)
|
|
125
|
-
|
|
126
|
-
def search_memory(
|
|
127
|
-
self, query: str, zep_client: Zep
|
|
128
|
-
) -> list[SessionSearchResult]:
|
|
129
|
-
"""Search memory for a query."""
|
|
130
|
-
if not zep_client or not self.user_id:
|
|
131
|
-
logger.error("Zep service or user_id not initialized")
|
|
132
|
-
return []
|
|
133
|
-
|
|
134
|
-
response = zep_client.memory.search_sessions(
|
|
135
|
-
text=query,
|
|
136
|
-
user_id=self.user_id,
|
|
137
|
-
search_scope="facts",
|
|
138
|
-
min_fact_rating=self.config.min_fact_rating,
|
|
139
|
-
)
|
|
140
|
-
if not response.results:
|
|
141
|
-
return []
|
|
142
|
-
return response.results
|
|
143
|
-
|
|
144
|
-
async def on_post_evaluate(
|
|
145
|
-
self,
|
|
146
|
-
agent: FlockAgent,
|
|
147
|
-
inputs: dict[str, Any],
|
|
148
|
-
context: FlockContext | None = None,
|
|
149
|
-
result: dict[str, Any] | None = None,
|
|
150
|
-
) -> dict[str, Any]:
|
|
151
|
-
"""Format and display the output."""
|
|
152
|
-
if not self.config.enable_write:
|
|
153
|
-
return result
|
|
154
|
-
logger.debug("Saving data to memory")
|
|
155
|
-
zep_client = Zep(
|
|
156
|
-
base_url=self.config.zep_url, api_key=self.config.zep_api_key
|
|
157
|
-
)
|
|
158
|
-
self.add_to_memory(str(result), zep_client)
|
|
159
|
-
return result
|
|
160
|
-
|
|
161
|
-
async def on_pre_evaluate(
|
|
162
|
-
self,
|
|
163
|
-
agent: FlockAgent,
|
|
164
|
-
inputs: dict[str, Any],
|
|
165
|
-
context: FlockContext | None = None,
|
|
166
|
-
) -> dict[str, Any]:
|
|
167
|
-
"""Format and display the output."""
|
|
168
|
-
if not self.config.enable_read:
|
|
169
|
-
return inputs
|
|
170
|
-
|
|
171
|
-
zep_client = Zep(
|
|
172
|
-
base_url=self.config.zep_url, api_key=self.config.zep_api_key
|
|
173
|
-
)
|
|
174
|
-
|
|
175
|
-
logger.debug("Searching memory")
|
|
176
|
-
facts = self.search_memory(str(inputs), zep_client)
|
|
177
|
-
|
|
178
|
-
# Add memory to inputs
|
|
179
|
-
facts_str = ""
|
|
180
|
-
if facts:
|
|
181
|
-
for fact in facts:
|
|
182
|
-
facts_str += fact.fact.fact + "\n"
|
|
183
|
-
logger.debug("Found facts in memory: {}", facts_str)
|
|
184
|
-
agent.input = agent.input + ", memory"
|
|
185
|
-
inputs["memory"] = facts_str
|
|
186
|
-
|
|
187
|
-
return inputs
|
|
File without changes
|
|
File without changes
|
|
File without changes
|