aigility 0.0.1__tar.gz

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.
Files changed (44) hide show
  1. aigility-0.0.1/LICENSE +0 -0
  2. aigility-0.0.1/PKG-INFO +449 -0
  3. aigility-0.0.1/README.md +398 -0
  4. aigility-0.0.1/adk/__init__.py +45 -0
  5. aigility-0.0.1/adk/chat/__init__.py +13 -0
  6. aigility-0.0.1/adk/chat/agent.py +60 -0
  7. aigility-0.0.1/adk/chatflow/__init__.py +13 -0
  8. aigility-0.0.1/adk/chatflow/flow.py +63 -0
  9. aigility-0.0.1/adk/client.py +167 -0
  10. aigility-0.0.1/adk/core/__init__.py +22 -0
  11. aigility-0.0.1/adk/core/base.py +85 -0
  12. aigility-0.0.1/adk/core/config.py +76 -0
  13. aigility-0.0.1/adk/core/types.py +90 -0
  14. aigility-0.0.1/adk/http/__init__.py +22 -0
  15. aigility-0.0.1/adk/http/circuit_breaker.py +89 -0
  16. aigility-0.0.1/adk/http/client.py +112 -0
  17. aigility-0.0.1/adk/http/pool.py +68 -0
  18. aigility-0.0.1/adk/http/retry.py +51 -0
  19. aigility-0.0.1/adk/knowledge/__init__.py +16 -0
  20. aigility-0.0.1/adk/knowledge/retriever.py +57 -0
  21. aigility-0.0.1/adk/knowledge/store.py +74 -0
  22. aigility-0.0.1/adk/memory/__init__.py +17 -0
  23. aigility-0.0.1/adk/memory/client.py +184 -0
  24. aigility-0.0.1/adk/memory/memory.py +162 -0
  25. aigility-0.0.1/adk/memory/types.py +30 -0
  26. aigility-0.0.1/adk/model/__init__.py +16 -0
  27. aigility-0.0.1/adk/model/embeddings.py +42 -0
  28. aigility-0.0.1/adk/model/llm.py +61 -0
  29. aigility-0.0.1/adk/utils/__init__.py +16 -0
  30. aigility-0.0.1/adk/utils/logger.py +49 -0
  31. aigility-0.0.1/adk/utils/workflow.py +69 -0
  32. aigility-0.0.1/adk/workflow/__init__.py +15 -0
  33. aigility-0.0.1/adk/workflow/builder.py +68 -0
  34. aigility-0.0.1/adk/workflow/engine.py +62 -0
  35. aigility-0.0.1/aigility.egg-info/PKG-INFO +449 -0
  36. aigility-0.0.1/aigility.egg-info/SOURCES.txt +42 -0
  37. aigility-0.0.1/aigility.egg-info/dependency_links.txt +1 -0
  38. aigility-0.0.1/aigility.egg-info/not-zip-safe +1 -0
  39. aigility-0.0.1/aigility.egg-info/requires.txt +22 -0
  40. aigility-0.0.1/aigility.egg-info/top_level.txt +1 -0
  41. aigility-0.0.1/pyproject.toml +105 -0
  42. aigility-0.0.1/setup.cfg +4 -0
  43. aigility-0.0.1/setup.py +58 -0
  44. aigility-0.0.1/tests/test_client.py +156 -0
aigility-0.0.1/LICENSE ADDED
File without changes
@@ -0,0 +1,449 @@
1
+ Metadata-Version: 2.1
2
+ Name: aigility
3
+ Version: 0.0.1
4
+ Summary: AIGility ADK - Agent Development Kit | 基于 LangGraph/LangChain 的智能体开发框架
5
+ Home-page: https://github.com/AIGility-Cloud-Innovation/timem-python
6
+ Author: AIGility Cloud Innovation
7
+ Author-email: AIGility Cloud Innovation <contact@aigility.com>
8
+ Maintainer-email: AIGility Cloud Innovation <contact@aigility.com>
9
+ License: MIT
10
+ Project-URL: Homepage, https://github.com/AIGility-Cloud-Innovation/aigility
11
+ Project-URL: Documentation, https://aigility.readthedocs.io
12
+ Project-URL: Repository, https://github.com/AIGility-Cloud-Innovation/aigility
13
+ Project-URL: Issues, https://github.com/AIGility-Cloud-Innovation/aigility/issues
14
+ Project-URL: Changelog, https://github.com/AIGility-Cloud-Innovation/aigility/blob/main/CHANGELOG.md
15
+ Keywords: adk,agent,langchain,langgraph,workflow,chat,rag,memory,ai,llm
16
+ Classifier: Development Status :: 3 - Alpha
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: License :: OSI Approved :: MIT License
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python :: 3
21
+ Classifier: Programming Language :: Python :: 3.8
22
+ Classifier: Programming Language :: Python :: 3.9
23
+ Classifier: Programming Language :: Python :: 3.10
24
+ Classifier: Programming Language :: Python :: 3.11
25
+ Classifier: Programming Language :: Python :: 3.12
26
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
27
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
28
+ Requires-Python: >=3.8
29
+ Description-Content-Type: text/markdown
30
+ License-File: LICENSE
31
+ Requires-Dist: httpx>=0.24.0
32
+ Requires-Dist: pydantic>=2.0.0
33
+ Requires-Dist: typing-extensions>=4.0.0
34
+ Requires-Dist: langchain>=0.1.0
35
+ Requires-Dist: langgraph>=0.0.20
36
+ Requires-Dist: langchain-openai>=0.0.5
37
+ Requires-Dist: langchain-anthropic>=0.1.0
38
+ Provides-Extra: dev
39
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
40
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
41
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
42
+ Requires-Dist: black>=22.0.0; extra == "dev"
43
+ Requires-Dist: isort>=5.0.0; extra == "dev"
44
+ Requires-Dist: flake8>=5.0.0; extra == "dev"
45
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
46
+ Requires-Dist: pre-commit>=2.20.0; extra == "dev"
47
+ Provides-Extra: docs
48
+ Requires-Dist: sphinx>=5.0.0; extra == "docs"
49
+ Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == "docs"
50
+ Requires-Dist: myst-parser>=0.18.0; extra == "docs"
51
+
52
+ # TiMEM Python SDK
53
+
54
+ **Time-based Memory Management and Experience Learning Toolkit**
55
+
56
+ TiMEM SDK 是一个强大的 Python 客户端库,用于与 TiMEM Engine API 交互,提供记忆管理、经验学习和用户画像计算等功能。
57
+
58
+ ## 特性
59
+
60
+ - ✅ **经验学习引擎**:从反馈数据中智能学习生成规则(直接使用 LLM,无需聚类)
61
+ - ✅ **规则召回**:基于上下文智能召回相关经验规则
62
+ - ✅ **记忆管理**:支持 L1-L5 分层记忆的增删改查
63
+ - ✅ **用户画像**:从 L5 级别记忆计算用户画像
64
+ - ✅ **同步/异步支持**:完整的同步和异步 API 封装
65
+ - ✅ **批量操作**:支持并发批量处理提升效率
66
+ - ✅ **自动重试**:内置请求重试机制保证可靠性
67
+
68
+ ## 安装
69
+
70
+ ```bash
71
+ pip install timem-python
72
+ ```
73
+
74
+ 或从源码安装:
75
+
76
+ ```bash
77
+ git clone https://github.com/aigility/timem-python.git
78
+ cd timem-python
79
+ pip install -e .
80
+ ```
81
+
82
+ ## 快速开始
83
+
84
+ ### 同步客户端
85
+
86
+ ```python
87
+ from timem import TiMEMClient
88
+
89
+ # 初始化客户端
90
+ client = TiMEMClient(
91
+ api_key="your-api-key",
92
+ base_url="http://localhost:8001"
93
+ )
94
+
95
+ # 1. 学习:从反馈生成经验规则(可选提供反馈案例)
96
+ result = client.learn(
97
+ domain="aicv",
98
+ feedback_cases=[ # 可选:提供新的反馈案例
99
+ {
100
+ "case_id": "case_001",
101
+ "user_id": 12345,
102
+ "domain": "aicv",
103
+ "suggestion_type": "项目经验优化",
104
+ "feedback_action": "adopt",
105
+ "feedback_score": 5.0
106
+ }
107
+ ],
108
+ min_case_count=3,
109
+ min_adoption_rate=0.6,
110
+ strategy="adaptive"
111
+ )
112
+ print(f"Generated {result['data']['generated_rule_count']} rules")
113
+
114
+ # 或者直接从系统中已有的反馈学习
115
+ result = client.learn(domain="aicv", strategy="adaptive")
116
+
117
+ # 2. 召回:根据上下文召回相关规则
118
+ rules = client.recall(
119
+ context={
120
+ "job_title": "Python开发工程师",
121
+ "issue_type": "项目经验",
122
+ "section": "工作经历"
123
+ },
124
+ domain="aicv",
125
+ top_k=5
126
+ )
127
+ print(f"Recalled {len(rules['data']['rules'])} rules")
128
+
129
+ # 3. 添加记忆
130
+ memory = client.add_memory(
131
+ user_id=12345,
132
+ domain="aicv",
133
+ content={
134
+ "type": "interaction",
135
+ "action": "resume_analysis",
136
+ "context": {"job": "软件工程师"}
137
+ },
138
+ layer_type="L1",
139
+ tags=["resume", "analysis"]
140
+ )
141
+
142
+ # 4. 搜索记忆
143
+ memories = client.search_memory(
144
+ user_id=12345,
145
+ domain="aicv",
146
+ tags=["resume"],
147
+ limit=10
148
+ )
149
+
150
+ # 5. 计算用户画像
151
+ profile = client.compute_profile(
152
+ user_id=12345,
153
+ domain="aicv"
154
+ )
155
+
156
+ # 关闭客户端
157
+ client.close()
158
+ ```
159
+
160
+ ### 异步客户端
161
+
162
+ ```python
163
+ import asyncio
164
+ from timem import AsyncTiMEMClient
165
+
166
+ async def main():
167
+ # 使用上下文管理器自动管理连接
168
+ async with AsyncTiMEMClient(
169
+ api_key="your-api-key",
170
+ base_url="http://localhost:8001"
171
+ ) as client:
172
+
173
+ # 1. 异步学习
174
+ result = await client.learn(
175
+ domain="aicv",
176
+ strategy="adaptive"
177
+ )
178
+
179
+ # 2. 异步召回
180
+ rules = await client.recall(
181
+ context={"job_title": "数据科学家"},
182
+ domain="aicv"
183
+ )
184
+
185
+ # 3. 批量学习(多个领域并发)
186
+ batch_results = await client.batch_learn(
187
+ domains=["aicv", "education", "consulting"]
188
+ )
189
+
190
+ # 4. 批量添加记忆(并发)
191
+ memories = [
192
+ {
193
+ "user_id": 12345,
194
+ "domain": "aicv",
195
+ "content": {"action": "view_job", "job_id": 1}
196
+ },
197
+ {
198
+ "user_id": 12345,
199
+ "domain": "aicv",
200
+ "content": {"action": "apply_job", "job_id": 1}
201
+ }
202
+ ]
203
+ results = await client.batch_add_memories(memories)
204
+
205
+ # 运行异步函数
206
+ asyncio.run(main())
207
+ ```
208
+
209
+ ### 便捷函数
210
+
211
+ ```python
212
+ import asyncio
213
+ from timem import learn_async, recall_async
214
+
215
+ # 快速异步学习
216
+ async def quick_learn():
217
+ result = await learn_async(
218
+ api_key="your-api-key",
219
+ domain="aicv",
220
+ strategy="adaptive"
221
+ )
222
+ return result
223
+
224
+ # 快速异步召回
225
+ async def quick_recall():
226
+ rules = await recall_async(
227
+ api_key="your-api-key",
228
+ context={"job_title": "产品经理"},
229
+ domain="aicv"
230
+ )
231
+ return rules
232
+
233
+ asyncio.run(quick_learn())
234
+ asyncio.run(quick_recall())
235
+ ```
236
+
237
+ ## API 文档
238
+
239
+ ### 经验学习引擎
240
+
241
+ #### learn()
242
+
243
+ 从反馈案例中学习生成经验规则(使用 LLM 直接分析,无需聚类)
244
+
245
+ **参数:**
246
+ - `domain` (str): 业务领域,默认 "general"
247
+ - `feedback_cases` (List[Dict], optional): 可选的反馈案例列表,如果提供则先收集再学习
248
+ - `min_case_count` (int): 最小案例数量,默认 3
249
+ - `min_adoption_rate` (float): 最小采纳率阈值,默认 0.6
250
+ - `min_confidence_score` (float): 最小置信度阈值,默认 0.5
251
+ - `strategy` (str): 总结策略,可选 "single", "cluster", "adaptive"(推荐)
252
+
253
+ **返回:** 学习结果包含生成的规则数量和规则ID列表
254
+
255
+ **使用场景:**
256
+ - 提供 feedback_cases:实时收集反馈并立即学习
257
+ - 不提供 feedback_cases:从系统中已有的未处理反馈学习
258
+
259
+ #### recall()
260
+
261
+ 根据上下文召回相关经验规则
262
+
263
+ **参数:**
264
+ - `context` (Dict): 上下文信息(如 job_title, issue_type, section)
265
+ - `domain` (str): 业务领域
266
+ - `top_k` (int): 返回前 K 条规则,默认 5
267
+ - `min_confidence` (float): 最小置信度,默认 0.5
268
+
269
+ **返回:** 召回的规则列表,包含相关性评分
270
+
271
+ ### 记忆管理
272
+
273
+ #### add_memory()
274
+
275
+ 添加记忆到 TiMEM 系统
276
+
277
+ **参数:**
278
+ - `user_id` (int): 用户ID
279
+ - `domain` (str): 业务领域
280
+ - `content` (Dict): 记忆内容
281
+ - `layer_type` (str): 记忆层级(L1-L5),默认 "L1"
282
+ - `tags` (List[str], optional): 标签
283
+ - `keywords` (List[str], optional): 关键词
284
+
285
+ **返回:** 创建的记忆信息
286
+
287
+ #### search_memory()
288
+
289
+ 搜索记忆
290
+
291
+ **参数:**
292
+ - `user_id` (int, optional): 用户ID过滤
293
+ - `domain` (str, optional): 领域过滤
294
+ - `layer_type` (str, optional): 层级过滤
295
+ - `tags` (List[str], optional): 标签过滤
296
+ - `keywords` (List[str], optional): 关键词过滤
297
+ - `limit` (int): 返回数量,默认 20
298
+ - `offset` (int): 分页偏移,默认 0
299
+
300
+ **返回:** 搜索结果和记忆列表
301
+
302
+ ### 用户画像
303
+
304
+ #### compute_profile()
305
+
306
+ 从 L5 级别记忆计算用户画像
307
+
308
+ **参数:**
309
+ - `user_id` (int): 用户ID
310
+ - `domain` (str): 业务领域
311
+ - `source_memory_ids` (List[str], optional): 指定记忆ID
312
+
313
+ **返回:** 计算的画像信息
314
+
315
+ #### get_profile()
316
+
317
+ 获取用户画像
318
+
319
+ **参数:**
320
+ - `user_id` (int): 用户ID
321
+ - `domain` (str): 业务领域
322
+
323
+ **返回:** 用户画像信息
324
+
325
+ #### search_users()
326
+
327
+ 根据画像特征搜索用户
328
+
329
+ **参数:**
330
+ - `criteria` (Dict): 搜索条件(如偏好、行为模式)
331
+ - `domain` (str, optional): 领域过滤
332
+ - `limit` (int): 返回数量,默认 20
333
+
334
+ **返回:** 匹配的用户列表
335
+
336
+ ## 异步批量操作
337
+
338
+ ### batch_learn()
339
+
340
+ 并发学习多个领域的反馈
341
+
342
+ ```python
343
+ async with AsyncTiMEMClient(api_key="your-key") as client:
344
+ results = await client.batch_learn(
345
+ domains=["aicv", "education", "consulting"],
346
+ strategy="adaptive"
347
+ )
348
+ ```
349
+
350
+ ### batch_add_memories()
351
+
352
+ 并发添加多条记忆
353
+
354
+ ```python
355
+ async with AsyncTiMEMClient(api_key="your-key") as client:
356
+ memories = [
357
+ {"user_id": 1, "domain": "aicv", "content": {...}},
358
+ {"user_id": 2, "domain": "aicv", "content": {...}}
359
+ ]
360
+ results = await client.batch_add_memories(memories)
361
+ ```
362
+
363
+ ## 异常处理
364
+
365
+ ```python
366
+ from timem import TiMEMClient, TiMEMError, AuthenticationError, APIError, ValidationError
367
+
368
+ try:
369
+ client = TiMEMClient(api_key="your-key")
370
+ result = client.learn(domain="aicv")
371
+ except ValidationError as e:
372
+ print(f"验证错误: {e}")
373
+ except AuthenticationError as e:
374
+ print(f"认证失败: {e}")
375
+ except APIError as e:
376
+ print(f"API错误 [{e.status_code}]: {e}")
377
+ except TiMEMError as e:
378
+ print(f"TiMEM错误: {e}")
379
+ ```
380
+
381
+ ## 配置选项
382
+
383
+ ```python
384
+ client = TiMEMClient(
385
+ api_key="your-api-key",
386
+ base_url="http://localhost:8001", # TiMEM Engine URL
387
+ timeout=60.0, # 请求超时(秒)
388
+ )
389
+
390
+ async_client = AsyncTiMEMClient(
391
+ api_key="your-api-key",
392
+ base_url="http://localhost:8001",
393
+ timeout=60.0,
394
+ max_retries=3, # 最大重试次数
395
+ retry_delay=1.0, # 重试延迟(秒)
396
+ )
397
+ ```
398
+
399
+ ## 开发指南
400
+
401
+ ### 安装开发依赖
402
+
403
+ ```bash
404
+ pip install -r requirements-dev.txt
405
+ ```
406
+
407
+ ### 运行测试
408
+
409
+ ```bash
410
+ pytest tests/
411
+ ```
412
+
413
+ ### 构建发布
414
+
415
+ ```bash
416
+ python -m build
417
+ python -m twine upload dist/*
418
+ ```
419
+
420
+ ## 架构说明
421
+
422
+ TiMEM SDK 遵循以下设计原则:
423
+
424
+ 1. **简洁接口**:Learn 算子直接使用 LLM,无需手动聚类
425
+ 2. **智能召回**:基于标签和上下文的相关性评分
426
+ 3. **分层记忆**:支持 L1-L5 五层记忆管理
427
+ 4. **异步优先**:充分利用异步编程提升性能
428
+ 5. **容错设计**:自动重试和异常处理
429
+
430
+ ## 许可证
431
+
432
+ MIT License
433
+
434
+ ## 联系我们
435
+
436
+ - Email: contact@aigility.com
437
+ - GitHub: https://github.com/aigility/timem-python
438
+ - Documentation: https://docs.timem.aigility.com
439
+
440
+ ## 更新日志
441
+
442
+ ### v0.1.0 (2025-10-18)
443
+
444
+ - ✨ 初始版本发布
445
+ - ✨ 支持经验学习引擎(Learn/Recall)
446
+ - ✨ 支持记忆管理(Add/Search/Update/Delete)
447
+ - ✨ 支持用户画像计算
448
+ - ✨ 完整的同步/异步 API
449
+ - ✨ 批量操作支持