-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathontology.py
More file actions
261 lines (205 loc) · 8.71 KB
/
Copy pathontology.py
File metadata and controls
261 lines (205 loc) · 8.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
"""
Zep Custom Ontology for Coding Agents
This ontology is optimized for capturing developer workflows and technical conventions.
Design principles:
- Search-optimized: entity names contain specific technology/convention values
- Technology-focused: captures tech stacks, frameworks, tools, and standards
- Convention-aware: tracks coding styles, naming conventions, and best practices
- Project-organized: groups context by project and component type
Entity types:
- Technology: Programming languages, frameworks, libraries, tools (e.g., "Python", "FastAPI", "React")
- Convention: Coding standards, naming rules, formatting rules (e.g., "2-space indentation", "camelCase functions")
- Project: Codebases and software projects (e.g., "taskflow-frontend", "taskflow-api")
- Schedule: Meeting times, deployment windows, recurring events
- Person: Team members and their roles
Edge types:
- Uses: Developer/Project uses a Technology
- Follows: Code follows a Convention
- HasConvention: Project has an associated Convention
- ScheduledFor: Events scheduled at specific times/days
- ResponsibleFor: Team member responsible for a domain
"""
from pydantic import Field
from zep_cloud.external_clients.ontology import EntityModel, EdgeModel, EntityText
# ============================================================================
# Entity Types (5 entities optimized for coding agents)
# ============================================================================
EMPTY_STRING = "Empty string if not available or applicable."
MAX_LENGTH = 100
class Technology(EntityModel):
"""Programming languages, frameworks, libraries, tools, or technologies.
Entity names should be the technology name (e.g., "React", "PostgreSQL", "FastAPI").
Descriptions should include version, purpose, or usage context.
"""
category: EntityText = Field(
default=None,
description="language, framework, library, database, tool, platform, other. "
+ EMPTY_STRING,
max_length=MAX_LENGTH,
)
class Convention(EntityModel):
"""Coding standards, naming rules, formatting rules, or architectural patterns.
Entity names should describe the convention clearly (e.g., "2-space indentation", "snake_case_functions").
Descriptions should explain rationale or scope (e.g., "TypeScript convention", "Database tables").
"""
scope: EntityText = Field(
default=None,
description="python, typescript, javascript, database, api, git, general, other. "
+ EMPTY_STRING,
max_length=MAX_LENGTH,
)
class Project(EntityModel):
"""A software project, codebase, or service.
Entity names should be the project name (e.g., "taskflow-frontend", "taskflow-api").
Descriptions should include type, purpose, and tech stack summary.
"""
project_type: EntityText = Field(
default=None,
description="frontend, backend, fullstack, service, library, infrastructure, other. "
+ EMPTY_STRING,
max_length=MAX_LENGTH,
)
class Schedule(EntityModel):
"""Meeting times, deployment windows, or recurring events.
Entity names should describe the event clearly (e.g., "Daily standup", "Tuesday Thursday deployments").
Descriptions should include frequency, time, and attendees.
"""
frequency: EntityText = Field(
default=None,
description="daily, weekly, biweekly, monthly, fixed_day, flexible, once, other. "
+ EMPTY_STRING,
max_length=MAX_LENGTH,
)
class Person(EntityModel):
"""Team members, developers, or roles.
Entity names should be the person's name or role.
Descriptions should include team affiliation, responsibilities, and expertise.
"""
role: EntityText = Field(
default=None,
description="frontend_engineer, backend_engineer, devops_engineer, lead, manager, other. "
+ EMPTY_STRING,
max_length=MAX_LENGTH,
)
# ============================================================================
# Edge Types (5 relationships, no attributes)
# ============================================================================
class Uses(EdgeModel):
"""Project or Person uses a Technology.
Description should explain how/why the technology is used."""
...
class Follows(EdgeModel):
"""Code or Project follows a Convention.
Description should specify which parts/contexts follow the convention."""
...
class HasConvention(EdgeModel):
"""Project explicitly has an associated Convention as a standard.
Description should explain scope and when to apply."""
...
class ScheduledFor(EdgeModel):
"""An event or meeting is scheduled at specific times/days.
Description should include frequency, time windows, and purpose."""
...
class ResponsibleFor(EdgeModel):
"""Person is responsible for reviewing, maintaining, or owning a domain/project/technology.
Description should include scope and responsibilities."""
...
# ============================================================================
# Ontology Constants - Single Source of Truth
# ============================================================================
# Entity type names
ENTITY_TYPES = ["Technology", "Convention", "Project", "Schedule", "Person"]
# Edge type names
EDGE_TYPES = [
"USES",
"FOLLOWS",
"HAS_CONVENTION",
"SCHEDULED_FOR",
"RESPONSIBLE_FOR",
]
# ============================================================================
# Ontology Setup Function
# ============================================================================
async def set_custom_ontology(zep_client, user_ids=None):
"""
Set a custom ontology optimized for coding agents and developer workflows.
This ontology captures:
- Technology: Languages, frameworks, libraries, tools
- Convention: Coding standards, naming rules, formatting
- Project: Software projects and codebases
- Schedule: Meetings, deployments, recurring events
- Person: Team members and their roles
Relationships track how technologies are used, conventions are followed,
responsibilities are assigned, and schedules are maintained.
Args:
zep_client: AsyncZep client instance
user_ids: Optional list of user IDs to apply ontology to.
If None, applies to entire project.
Returns:
Response from set_ontology call
Example usage:
```python
from zep_cloud import AsyncZep
client = AsyncZep(api_key="your-key")
await set_custom_ontology(client)
```
"""
from zep_cloud import EntityEdgeSourceTarget
kwargs = {
"entities": {
"Technology": Technology,
"Convention": Convention,
"Project": Project,
"Schedule": Schedule,
"Person": Person,
},
"edges": {
# Project or Person uses a Technology
"USES": (
Uses,
[
EntityEdgeSourceTarget(source="User", target="Technology"),
EntityEdgeSourceTarget(source="Project", target="Technology"),
EntityEdgeSourceTarget(source="Person", target="Technology"),
],
),
# Code/Project follows a Convention
"FOLLOWS": (
Follows,
[
EntityEdgeSourceTarget(source="User", target="Convention"),
EntityEdgeSourceTarget(source="Project", target="Convention"),
],
),
# Project has an explicit Convention as a standard
"HAS_CONVENTION": (
HasConvention,
[
EntityEdgeSourceTarget(source="Project", target="Convention"),
EntityEdgeSourceTarget(source="Technology", target="Convention"),
],
),
# Event/Meeting scheduled at specific times
"SCHEDULED_FOR": (
ScheduledFor,
[
EntityEdgeSourceTarget(source="Schedule", target="Person"),
EntityEdgeSourceTarget(source="User", target="Schedule"),
],
),
# Person responsible for domain/project/technology
"RESPONSIBLE_FOR": (
ResponsibleFor,
[
EntityEdgeSourceTarget(source="Person", target="Project"),
EntityEdgeSourceTarget(source="Person", target="Technology"),
EntityEdgeSourceTarget(source="Person", target="Convention"),
],
),
},
}
# Apply to specific users if provided
if user_ids:
kwargs["user_ids"] = user_ids
response = await zep_client.graph.set_ontology(**kwargs)
return response