ni.agentkit 0.7.2__tar.gz → 0.7.4__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.
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/PKG-INFO +11 -6
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/README.md +7 -5
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/__init__.py +3 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/agents/agent.py +6 -2
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/docs/Architecture.md +11 -2
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/docs/QuickStart.md +46 -1
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/docs/README.md +4 -2
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/docs/Reference.md +78 -1
- ni_agentkit-0.7.4/docs/TestReport.md +64 -0
- ni_agentkit-0.7.4/examples/ollama/20_simple_rag_agent.py +34 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/README.md +1 -0
- ni_agentkit-0.7.4/examples/standard/05_human_in_the_loop.py +42 -0
- ni_agentkit-0.7.4/examples/standard/19_hitl_deterministic.py +56 -0
- ni_agentkit-0.7.4/examples/standard/20_simple_rag_agent.py +37 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/README.md +3 -0
- ni_agentkit-0.7.4/examples/test_standard.py +60 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/llm/cache.py +19 -3
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/llm/registry.py +16 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/ni.agentkit.egg-info/PKG-INFO +11 -6
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/ni.agentkit.egg-info/SOURCES.txt +28 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/ni.agentkit.egg-info/requires.txt +4 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/pyproject.toml +4 -1
- ni_agentkit-0.7.4/rag/__init__.py +6 -0
- ni_agentkit-0.7.4/rag/document_store.py +170 -0
- ni_agentkit-0.7.4/rag/file_memory_provider.py +133 -0
- ni_agentkit-0.7.4/rag/loaders.py +64 -0
- ni_agentkit-0.7.4/rag/retrievers.py +217 -0
- ni_agentkit-0.7.4/rag/simple_rag_agent.py +207 -0
- ni_agentkit-0.7.4/rag/sqlite_store.py +67 -0
- ni_agentkit-0.7.4/rag/types.py +59 -0
- ni_agentkit-0.7.4/tests/test_default_model_env.py +15 -0
- ni_agentkit-0.7.4/tests/test_simple_rag.py +115 -0
- ni_agentkit-0.7.4/utils/env.py +72 -0
- ni_agentkit-0.7.2/docs/TestReport.md +0 -61
- ni_agentkit-0.7.2/examples/test_standard.py +0 -50
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/LICENSE +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/_cli.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/agents/__init__.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/agents/base_agent.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/agents/orchestrators.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/Skill.md +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/__init__.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/01_basic_chat.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/02_tool_calling.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/03_skill_usage.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/03b_skill_tools_entry.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/04_multi_agent.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/05_guardrail.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/05_human_in_the_loop.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/06_orchestration.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/07_sync_async_stream.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/08_memory.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/08a_memory_simple_provider.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/08b_memory_mem0_provider.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/08c_memory_file_provider.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/09a_structured_data_sql.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/09b_structured_data_graph.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/09c_nebula_graph_tool.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/10_skill_lifecycle.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/11_orchestration_enhancement.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/12_run_context_serialization.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/13_human_in_the_loop.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/14_event_standardization.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/15_multi_tenant_isolation.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/16_lifecycle_hooks.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/17_checkpoint_handoff_resume.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/18_model_cosplay.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/19_hitl_deterministic.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/__init__.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/ollama/model_config.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/quickstart.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/skills/weather-tools-entry/SKILL.md +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/skills/weather-tools-entry/tools/weather_tools.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/01_basic_chat.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/02_tool_calling.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/03_skill_usage.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/03b_skill_tools_entry.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/04_multi_agent.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/05_guardrail.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/06_orchestration.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/07_sync_async_stream.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/08_memory.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/08a_memory_simple_provider.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/08b_memory_mem0_provider.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/08c_memory_file_provider.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/09a_structured_data_sql.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/09b_structured_data_graph.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/09c_nebula_graph_tool.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/10_skill_lifecycle.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/11_orchestration_enhancement.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/12_run_context_serialization.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/13_human_in_the_loop.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/14_event_standardization.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/15_multi_tenant_isolation.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/16_lifecycle_hooks.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/17_checkpoint_handoff_resume.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/18_model_cosplay.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/__init__.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/standard/model_config.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/examples/test_ollama.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/llm/__init__.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/llm/adapters/__init__.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/llm/adapters/anthropic_adapter.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/llm/adapters/google_adapter.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/llm/adapters/ollama_adapter.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/llm/adapters/openai_adapter.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/llm/adapters/openai_compatible.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/llm/base.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/llm/middleware.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/llm/types.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/memory/__init__.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/memory/base.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/memory/mem0_provider.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/ni.agentkit.egg-info/dependency_links.txt +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/ni.agentkit.egg-info/entry_points.txt +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/ni.agentkit.egg-info/top_level.txt +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/runner/__init__.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/runner/context.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/runner/context_store.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/runner/events.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/runner/runner.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/safety/__init__.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/safety/guardrails.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/safety/permissions.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/setup.cfg +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/skills/__init__.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/skills/loader.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/skills/models.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/skills/registry.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/tests/test_after_callback.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/tests/test_graph_repository.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/tests/test_quickstart_core.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/tests/test_runner_checkpoint_resume.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/tests/test_skill_frontmatter.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/tools/__init__.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/tools/base_tool.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/tools/function_tool.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/tools/nebula_tool.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/tools/skill_toolset.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/tools/sqlite_tool.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/tools/structured_data.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/utils/__init__.py +0 -0
- {ni_agentkit-0.7.2 → ni_agentkit-0.7.4}/utils/schema.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ni.agentkit
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.4
|
|
4
4
|
Summary: A Python-native Agent framework with first-class Skill support and multi-LLM adapter
|
|
5
5
|
Author-email: Krix Tam <krix.tam@qq.com>
|
|
6
6
|
License: MIT
|
|
@@ -31,11 +31,14 @@ Provides-Extra: google
|
|
|
31
31
|
Requires-Dist: google-genai>=1.0.0; extra == "google"
|
|
32
32
|
Provides-Extra: memory
|
|
33
33
|
Requires-Dist: mem0ai>=0.1.0; extra == "memory"
|
|
34
|
+
Provides-Extra: pdf
|
|
35
|
+
Requires-Dist: pypdf>=5.0.0; extra == "pdf"
|
|
34
36
|
Provides-Extra: all
|
|
35
37
|
Requires-Dist: openai>=1.0.0; extra == "all"
|
|
36
38
|
Requires-Dist: anthropic>=0.30.0; extra == "all"
|
|
37
39
|
Requires-Dist: google-genai>=1.0.0; extra == "all"
|
|
38
40
|
Requires-Dist: mem0ai>=0.1.0; extra == "all"
|
|
41
|
+
Requires-Dist: pypdf>=5.0.0; extra == "all"
|
|
39
42
|
Dynamic: license-file
|
|
40
43
|
|
|
41
44
|
# AgentKit
|
|
@@ -53,7 +56,8 @@ Dynamic: license-file
|
|
|
53
56
|
- 🧠 **多 LLM 适配器** — 自研统一适配层,5 个适配器覆盖主流 LLM(含 OpenAI Compatible)
|
|
54
57
|
- 🛡️ **内置安全** — Guardrail 护栏 + 权限控制;`run_skill_script` 当前为占位执行(SandboxExecutor 预留扩展)
|
|
55
58
|
- 🎭 **编排 Agent** — Sequential / Parallel / Loop 三种模式
|
|
56
|
-
- 💾 **记忆系统** — 可选集成 Mem0
|
|
59
|
+
- 💾 **记忆系统** — 可选集成 Mem0,支持自定义记忆提供者;`SimpleRAGAgent` 默认内置 `SQLiteMemoryProvider`
|
|
60
|
+
- 📄 **SimpleRAGAgent** — 内置轻量 RAG(txt/md/markdown/pdf),支持 TF-IDF / BM25 / 向量检索,知识库与默认记忆统一落盘到 SQLite
|
|
57
61
|
- ⚡ **全异步设计与 Hooks** — 底层全面采用 `asyncio`,流式响应(Streaming)、事件驱动(Event-Driven)、断点续跑机制(Checkpoint/Resume)。提供细粒度的 生命周期 Hooks,支持改写请求与结果。
|
|
58
62
|
- 🏢 **多租户数据隔离** — 框架级支持 `user_id` / `session_id` 贯穿,Memory 默认分桶,Session 结束自动释放资源。
|
|
59
63
|
- 🔗 **与大模型平台解耦** — 内置多模型支持,轻松对接 Ollama 等本地模型。
|
|
@@ -69,6 +73,7 @@ pip install "ni.agentkit[openai]"
|
|
|
69
73
|
pip install "ni.agentkit[anthropic]"
|
|
70
74
|
pip install "ni.agentkit[google]"
|
|
71
75
|
pip install "ni.agentkit[memory]"
|
|
76
|
+
pip install "ni.agentkit[pdf]"
|
|
72
77
|
pip install "ni.agentkit[all]"
|
|
73
78
|
```
|
|
74
79
|
|
|
@@ -110,13 +115,13 @@ print(agentkit.get_examples_dir()) # 示例目录路径
|
|
|
110
115
|
| 文档 | 说明 |
|
|
111
116
|
|------|------|
|
|
112
117
|
| [README](docs/README.md) | 项目概述与特性 |
|
|
113
|
-
| [QuickStart](docs/QuickStart.md) | 18 组渐进式入门示例(含 9A/9B
|
|
118
|
+
| [QuickStart](docs/QuickStart.md) | 18 组渐进式入门示例(含 8A/8B/8C、9A/9B/9C 与扩展示例) |
|
|
114
119
|
| [Architecture](docs/Architecture.md) | 六层架构设计说明 |
|
|
115
120
|
| [Reference](docs/Reference.md) | 完整 API 参考手册 |
|
|
116
121
|
|
|
117
122
|
## 🧪 示例
|
|
118
123
|
|
|
119
|
-
安装包内含可运行示例(标准版
|
|
124
|
+
安装包内含可运行示例(标准版 27 个 + Ollama 本地版 27 个):
|
|
120
125
|
|
|
121
126
|
```bash
|
|
122
127
|
# Ollama 本地版(无需 API Key)
|
|
@@ -150,8 +155,8 @@ python "$(python -c "import agentkit, os; print(os.path.join(agentkit.get_exampl
|
|
|
150
155
|
|
|
151
156
|
```bash
|
|
152
157
|
dist/
|
|
153
|
-
├── ni_agentkit-0.7.
|
|
154
|
-
└── ni_agentkit-0.7.
|
|
158
|
+
├── ni_agentkit-0.7.4-py3-none-any.whl # pip install 用这个
|
|
159
|
+
└── ni_agentkit-0.7.4.tar.gz # 源码分发
|
|
155
160
|
```
|
|
156
161
|
|
|
157
162
|
## 📄 License
|
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
- 🧠 **多 LLM 适配器** — 自研统一适配层,5 个适配器覆盖主流 LLM(含 OpenAI Compatible)
|
|
14
14
|
- 🛡️ **内置安全** — Guardrail 护栏 + 权限控制;`run_skill_script` 当前为占位执行(SandboxExecutor 预留扩展)
|
|
15
15
|
- 🎭 **编排 Agent** — Sequential / Parallel / Loop 三种模式
|
|
16
|
-
- 💾 **记忆系统** — 可选集成 Mem0
|
|
16
|
+
- 💾 **记忆系统** — 可选集成 Mem0,支持自定义记忆提供者;`SimpleRAGAgent` 默认内置 `SQLiteMemoryProvider`
|
|
17
|
+
- 📄 **SimpleRAGAgent** — 内置轻量 RAG(txt/md/markdown/pdf),支持 TF-IDF / BM25 / 向量检索,知识库与默认记忆统一落盘到 SQLite
|
|
17
18
|
- ⚡ **全异步设计与 Hooks** — 底层全面采用 `asyncio`,流式响应(Streaming)、事件驱动(Event-Driven)、断点续跑机制(Checkpoint/Resume)。提供细粒度的 生命周期 Hooks,支持改写请求与结果。
|
|
18
19
|
- 🏢 **多租户数据隔离** — 框架级支持 `user_id` / `session_id` 贯穿,Memory 默认分桶,Session 结束自动释放资源。
|
|
19
20
|
- 🔗 **与大模型平台解耦** — 内置多模型支持,轻松对接 Ollama 等本地模型。
|
|
@@ -29,6 +30,7 @@ pip install "ni.agentkit[openai]"
|
|
|
29
30
|
pip install "ni.agentkit[anthropic]"
|
|
30
31
|
pip install "ni.agentkit[google]"
|
|
31
32
|
pip install "ni.agentkit[memory]"
|
|
33
|
+
pip install "ni.agentkit[pdf]"
|
|
32
34
|
pip install "ni.agentkit[all]"
|
|
33
35
|
```
|
|
34
36
|
|
|
@@ -70,13 +72,13 @@ print(agentkit.get_examples_dir()) # 示例目录路径
|
|
|
70
72
|
| 文档 | 说明 |
|
|
71
73
|
|------|------|
|
|
72
74
|
| [README](docs/README.md) | 项目概述与特性 |
|
|
73
|
-
| [QuickStart](docs/QuickStart.md) | 18 组渐进式入门示例(含 9A/9B
|
|
75
|
+
| [QuickStart](docs/QuickStart.md) | 18 组渐进式入门示例(含 8A/8B/8C、9A/9B/9C 与扩展示例) |
|
|
74
76
|
| [Architecture](docs/Architecture.md) | 六层架构设计说明 |
|
|
75
77
|
| [Reference](docs/Reference.md) | 完整 API 参考手册 |
|
|
76
78
|
|
|
77
79
|
## 🧪 示例
|
|
78
80
|
|
|
79
|
-
安装包内含可运行示例(标准版
|
|
81
|
+
安装包内含可运行示例(标准版 27 个 + Ollama 本地版 27 个):
|
|
80
82
|
|
|
81
83
|
```bash
|
|
82
84
|
# Ollama 本地版(无需 API Key)
|
|
@@ -110,8 +112,8 @@ python "$(python -c "import agentkit, os; print(os.path.join(agentkit.get_exampl
|
|
|
110
112
|
|
|
111
113
|
```bash
|
|
112
114
|
dist/
|
|
113
|
-
├── ni_agentkit-0.7.
|
|
114
|
-
└── ni_agentkit-0.7.
|
|
115
|
+
├── ni_agentkit-0.7.4-py3-none-any.whl # pip install 用这个
|
|
116
|
+
└── ni_agentkit-0.7.4.tar.gz # 源码分发
|
|
115
117
|
```
|
|
116
118
|
|
|
117
119
|
## 📄 License
|
|
@@ -13,6 +13,8 @@ from .llm.base import BaseLLM
|
|
|
13
13
|
from .llm.registry import LLMRegistry
|
|
14
14
|
from .llm.types import LLMConfig, LLMResponse, Message, ToolCall, ToolDefinition
|
|
15
15
|
from .memory.base import BaseMemoryProvider, Memory
|
|
16
|
+
from .rag.file_memory_provider import SQLiteMemoryProvider
|
|
17
|
+
from .rag.simple_rag_agent import SimpleRAGAgent
|
|
16
18
|
from .runner.events import Event, RunResult
|
|
17
19
|
from .runner.runner import Runner
|
|
18
20
|
from .safety.guardrails import (
|
|
@@ -55,5 +57,6 @@ __all__ = [
|
|
|
55
57
|
"GuardrailResult", "InputGuardrail", "OutputGuardrail", "PermissionPolicy",
|
|
56
58
|
"input_guardrail", "output_guardrail",
|
|
57
59
|
"BaseMemoryProvider", "Memory",
|
|
60
|
+
"SimpleRAGAgent", "SQLiteMemoryProvider",
|
|
58
61
|
"get_docs_dir", "get_examples_dir",
|
|
59
62
|
]
|
|
@@ -293,11 +293,12 @@ class Agent(BaseAgent):
|
|
|
293
293
|
|
|
294
294
|
# 5. 调用 LLM(支持缓存)
|
|
295
295
|
cached = False
|
|
296
|
+
cache_key: str | None = None
|
|
296
297
|
|
|
297
298
|
# 检查缓存
|
|
298
299
|
if self.enable_cache:
|
|
299
300
|
cache = self._get_cache()
|
|
300
|
-
cached_response = cache.
|
|
301
|
+
cache_key, cached_response = cache.get_with_key(messages, tool_defs if tool_defs else None)
|
|
301
302
|
if cached_response is not None:
|
|
302
303
|
response = cached_response
|
|
303
304
|
cached = True
|
|
@@ -318,7 +319,10 @@ class Agent(BaseAgent):
|
|
|
318
319
|
|
|
319
320
|
# 写入缓存
|
|
320
321
|
if self.enable_cache:
|
|
321
|
-
|
|
322
|
+
if cache_key is not None:
|
|
323
|
+
cache.put_with_key(cache_key, response)
|
|
324
|
+
else:
|
|
325
|
+
cache.put(messages, tool_defs if tool_defs else None, response)
|
|
322
326
|
|
|
323
327
|
cache_key_ms = 0.0
|
|
324
328
|
if self.enable_cache:
|
|
@@ -471,6 +471,7 @@ agent.clear_cache()
|
|
|
471
471
|
> - 缓存仅在单 Agent 实例内有效,重新创建 Agent 会清空缓存
|
|
472
472
|
> - 默认最大 128 条缓存,LRU 淘汰最久未使用的条目
|
|
473
473
|
> - 缓存实现内置 key 生成统计:`key_gen_calls / key_gen_total_ms / key_gen_last_ms / key_gen_avg_ms`
|
|
474
|
+
> - 缓存实现对同一轮的缓存 key 计算做了复用(避免 miss 场景下重复算 key)
|
|
474
475
|
|
|
475
476
|
### 3. 记忆异步写入
|
|
476
477
|
|
|
@@ -616,12 +617,20 @@ agentkit/
|
|
|
616
617
|
│ ├── base.py # BaseMemoryProvider
|
|
617
618
|
│ └── mem0_provider.py # Mem0Provider
|
|
618
619
|
│
|
|
620
|
+
├── rag/ # 轻量 RAG 核心模块
|
|
621
|
+
│ ├── simple_rag_agent.py # SimpleRAGAgent(Agent 构建器)
|
|
622
|
+
│ ├── document_store.py # 本地文档加载、增量构建与 SQLite 持久化
|
|
623
|
+
│ ├── loaders.py # txt / md / markdown / pdf 加载器
|
|
624
|
+
│ ├── retrievers.py # TF-IDF / BM25 / Vector 检索器
|
|
625
|
+
│ ├── sqlite_store.py # documents / chunks / memories 表结构
|
|
626
|
+
│ └── file_memory_provider.py # SQLiteMemoryProvider + FileMemoryProvider 兼容别名
|
|
627
|
+
│
|
|
619
628
|
├── utils/
|
|
620
629
|
│ └── schema.py # 函数签名 → JSON Schema
|
|
621
630
|
│
|
|
622
631
|
├── examples/ # 示例
|
|
623
|
-
│ ├── standard/ # 标准版示例(
|
|
624
|
-
│ ├── ollama/ # Ollama 版示例(
|
|
632
|
+
│ ├── standard/ # 标准版示例(27 个:含 05_human_in_the_loop、19_hitl_deterministic、20_simple_rag_agent)
|
|
633
|
+
│ ├── ollama/ # Ollama 版示例(27 个:新增 20_simple_rag_agent)
|
|
625
634
|
│ ├── quickstart.py
|
|
626
635
|
│ └── test_ollama.py
|
|
627
636
|
│
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# AgentKit 快速入门教程
|
|
2
2
|
|
|
3
|
-
> 本教程将带你从零开始,通过 18
|
|
3
|
+
> 本教程将带你从零开始,通过 18 组由简到繁的主线示例(含 8A/8B/8C、9A/9B/9C)与扩展示例,掌握 AgentKit 的核心用法。
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
- [示例 16:生命周期 Hooks 与 Callbacks](#16-生命周期-hooks-与-callbacks)
|
|
32
32
|
- [示例 17:Checkpoint 深度恢复(Handoff 后挂起与原路径恢复)](#17-checkpoint-深度恢复handoff-后挂起与原路径恢复)
|
|
33
33
|
- [示例 18:ModelCosplay(运行时改写预设模型)](#18-modelcosplay运行时改写预设模型)
|
|
34
|
+
- [示例 20:SimpleRAGAgent(本地文档检索 + SQLite 记忆)](#20-simpleragagent本地文档检索--sqlite-记忆)
|
|
34
35
|
- [性能提示](#性能提示)
|
|
35
36
|
- [使用不同的 LLM](#使用不同的-llm)
|
|
36
37
|
- [下一步](#下一步)
|
|
@@ -1178,6 +1179,46 @@ if __name__ == "__main__":
|
|
|
1178
1179
|
|
|
1179
1180
|
---
|
|
1180
1181
|
|
|
1182
|
+
## 示例 20:SimpleRAGAgent(本地文档检索 + SQLite 记忆)
|
|
1183
|
+
|
|
1184
|
+
`SimpleRAGAgent` 是 AgentKit 内置的轻量 RAG 方案,默认支持:
|
|
1185
|
+
|
|
1186
|
+
- 文档类型:`txt/md/markdown/pdf`
|
|
1187
|
+
- 检索器:`TF-IDF`、`BM25`、`Vector`(默认 `hybrid` 融合)
|
|
1188
|
+
- 存储:知识库 chunk 与默认记忆统一落盘到 `./.agentkit/rag/index.db`
|
|
1189
|
+
- 记忆:默认启用 SQLite 记忆,可通过 `enable_memory=False` 关闭
|
|
1190
|
+
|
|
1191
|
+
```python
|
|
1192
|
+
from agentkit import Runner, SimpleRAGAgent
|
|
1193
|
+
|
|
1194
|
+
rag = SimpleRAGAgent.from_directory(
|
|
1195
|
+
knowledge_dir="./knowledge_base",
|
|
1196
|
+
model="gpt-4o-mini", # 任意 AgentKit 支持的模型标识
|
|
1197
|
+
top_k=3,
|
|
1198
|
+
default_retriever="hybrid",
|
|
1199
|
+
storage_path=".agentkit/rag/index.db", # 可选:自定义 SQLite 路径
|
|
1200
|
+
enable_memory=True, # 可选:关闭时仅保留知识库检索
|
|
1201
|
+
)
|
|
1202
|
+
|
|
1203
|
+
agent = rag.build_agent(name="simple-rag-assistant")
|
|
1204
|
+
result = Runner.run_sync(agent, input="请介绍一下 AgentKit 的核心能力")
|
|
1205
|
+
print(result.final_output)
|
|
1206
|
+
```
|
|
1207
|
+
|
|
1208
|
+
如果知识库中包含 PDF,请额外安装:
|
|
1209
|
+
|
|
1210
|
+
```bash
|
|
1211
|
+
pip install "ni.agentkit[pdf]"
|
|
1212
|
+
```
|
|
1213
|
+
|
|
1214
|
+
`memory_file` 参数仍可继续传入,但当前版本会将其视为 SQLite 数据库路径,用于兼容旧代码。
|
|
1215
|
+
|
|
1216
|
+
可运行文件:
|
|
1217
|
+
- `examples/standard/20_simple_rag_agent.py`
|
|
1218
|
+
- `examples/ollama/20_simple_rag_agent.py`
|
|
1219
|
+
|
|
1220
|
+
---
|
|
1221
|
+
|
|
1181
1222
|
## 性能提示
|
|
1182
1223
|
|
|
1183
1224
|
当你感觉 Agent 响应较慢时,可以尝试以下优化:
|
|
@@ -1297,6 +1338,7 @@ agent = Agent(name="assistant", instructions="...")
|
|
|
1297
1338
|
| [`03b_skill_tools_entry.py`](../examples/standard/03b_skill_tools_entry.py) | 示例 3B:Skill tools.entry 动态注册/发现 |
|
|
1298
1339
|
| [`04_multi_agent.py`](../examples/standard/04_multi_agent.py) | 示例 4:多 Agent 协作 |
|
|
1299
1340
|
| [`05_guardrail.py`](../examples/standard/05_guardrail.py) | 示例 5:安全护栏 |
|
|
1341
|
+
| [`05_human_in_the_loop.py`](../examples/standard/05_human_in_the_loop.py) | 扩展示例:HITL 工具触发(Playground) |
|
|
1300
1342
|
| [`06_orchestration.py`](../examples/standard/06_orchestration.py) | 示例 6:编排 Agent |
|
|
1301
1343
|
| [`07_sync_async_stream.py`](../examples/standard/07_sync_async_stream.py) | 示例 7:同步/异步/流式运行 |
|
|
1302
1344
|
| [`08_memory.py`](../examples/standard/08_memory.py) | 示例 8:记忆系统(综合) |
|
|
@@ -1315,6 +1357,8 @@ agent = Agent(name="assistant", instructions="...")
|
|
|
1315
1357
|
| [`16_lifecycle_hooks.py`](../examples/standard/16_lifecycle_hooks.py) | 示例 16:生命周期 Hooks 与 Callbacks |
|
|
1316
1358
|
| [`17_checkpoint_handoff_resume.py`](../examples/standard/17_checkpoint_handoff_resume.py) | 示例 17:Checkpoint 深度恢复(Handoff + Resume) |
|
|
1317
1359
|
| [`18_model_cosplay.py`](../examples/standard/18_model_cosplay.py) | 示例 18:ModelCosplay(运行时改写预设模型) |
|
|
1360
|
+
| [`19_hitl_deterministic.py`](../examples/standard/19_hitl_deterministic.py) | 扩展示例:HITL 确定性触发 |
|
|
1361
|
+
| [`20_simple_rag_agent.py`](../examples/standard/20_simple_rag_agent.py) | 示例 20:SimpleRAGAgent(本地文档检索 + SQLite 记忆) |
|
|
1318
1362
|
|
|
1319
1363
|
### 📁 `examples/ollama/` — Ollama 本地版(无需 API Key,完全本地运行)
|
|
1320
1364
|
|
|
@@ -1346,6 +1390,7 @@ agent = Agent(name="assistant", instructions="...")
|
|
|
1346
1390
|
| [`17_checkpoint_handoff_resume.py`](../examples/ollama/17_checkpoint_handoff_resume.py) | 示例 17:Checkpoint 深度恢复(Handoff + Resume) |
|
|
1347
1391
|
| [`18_model_cosplay.py`](../examples/ollama/18_model_cosplay.py) | 示例 18:ModelCosplay(运行时改写预设模型) |
|
|
1348
1392
|
| [`19_hitl_deterministic.py`](../examples/ollama/19_hitl_deterministic.py) | 示例 19:HITL 确定性触发 |
|
|
1393
|
+
| [`20_simple_rag_agent.py`](../examples/ollama/20_simple_rag_agent.py) | 示例 20:SimpleRAGAgent(本地文档检索 + SQLite 记忆) |
|
|
1349
1394
|
|
|
1350
1395
|
---
|
|
1351
1396
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
> Python 原生的 Agent 开发框架,内置一等公民级别的 Skill 支持和自研多模型适配层。
|
|
4
4
|
|
|
5
5
|
[](https://python.org)
|
|
6
|
-
[]()
|
|
7
7
|
[]()
|
|
8
8
|
|
|
9
9
|
---
|
|
@@ -18,8 +18,9 @@
|
|
|
18
18
|
| **编排 Agent** | SequentialAgent / ParallelAgent / LoopAgent,组合出任意复杂的工作流。支持 Loop 动态退出条件与 Parallel 提前取消增强 |
|
|
19
19
|
| **@function_tool** | 一行装饰器把 Python 函数变成 LLM 工具,自动推断 JSON Schema。内建 `StructuredDataTool` 防止数据库注入 |
|
|
20
20
|
| **图数据统一接口层** | 提供 `GraphAdapter + GraphRepository + GraphQueryTool`,开发/测试可切换 `networkx/litegraph`,生产可切换 `nebula` |
|
|
21
|
+
| **SimpleRAGAgent** | 内置轻量 RAG 模块,支持 `txt/md/markdown/pdf` 文档加载、TF-IDF/BM25/向量检索,知识库与默认记忆统一落盘到 `./.agentkit/rag/index.db` |
|
|
21
22
|
| **安全内置** | Input/Output 双向 Guardrail + 三层权限控制;`run_skill_script` 当前为占位执行(SandboxExecutor 预留扩展) |
|
|
22
|
-
| **记忆系统** | Mem0
|
|
23
|
+
| **记忆系统** | Mem0 集成 + 自定义记忆提供者;`SimpleRAGAgent` 默认内置 `SQLiteMemoryProvider` |
|
|
23
24
|
| **9 个回调点** | before/after × agent/model/tool/handoff + error,任何环节可拦截定制 |
|
|
24
25
|
|
|
25
26
|
---
|
|
@@ -35,6 +36,7 @@ pip install "ni.agentkit[openai]" # OpenAI + 国内兼容厂商
|
|
|
35
36
|
pip install "ni.agentkit[anthropic]" # Anthropic Claude
|
|
36
37
|
pip install "ni.agentkit[google]" # Google Gemini
|
|
37
38
|
pip install "ni.agentkit[memory]" # 记忆系统 (mem0)
|
|
39
|
+
pip install "ni.agentkit[pdf]" # PDF 知识库解析(可选)
|
|
38
40
|
pip install "ni.agentkit[all]" # 安装所有可选依赖
|
|
39
41
|
```
|
|
40
42
|
|
|
@@ -37,6 +37,8 @@
|
|
|
37
37
|
- [PermissionPolicy](#permissionpolicy)
|
|
38
38
|
- [记忆类](#记忆类)
|
|
39
39
|
- [BaseMemoryProvider / Memory](#basememoryprovider)
|
|
40
|
+
- [RAG 类](#rag-类)
|
|
41
|
+
- [SimpleRAGAgent](#simpleragagent)
|
|
40
42
|
|
|
41
43
|
---
|
|
42
44
|
|
|
@@ -575,6 +577,20 @@ from agentkit import LLMRegistry
|
|
|
575
577
|
| `LLMRegistry.create_default()` | 创建默认模型实例 |
|
|
576
578
|
| `LLMRegistry.register(prefix, adapter_class)` | 注册自定义适配器 |
|
|
577
579
|
|
|
580
|
+
默认模型解析优先级:
|
|
581
|
+
|
|
582
|
+
1. 若代码中调用过 `LLMRegistry.set_default(...)`,优先使用该默认配置。
|
|
583
|
+
2. 否则会尝试从环境变量(或本地 `.env/.evn`)读取:`AGENTKIT_MODEL` → `AGENTKIT_DEFAULT_MODEL` → `AGENTKIT_STANDARD_MODEL` → `AGENTKIT_OLLAMA_MODEL`。
|
|
584
|
+
3. 都未配置时回退到内置默认值。
|
|
585
|
+
|
|
586
|
+
示例:
|
|
587
|
+
|
|
588
|
+
```bash
|
|
589
|
+
export AGENTKIT_DEFAULT_MODEL="ollama/qwen3.5:cloud"
|
|
590
|
+
# 或在项目根目录写入 .env(无需额外依赖)
|
|
591
|
+
# AGENTKIT_DEFAULT_MODEL=ollama/qwen3.5:cloud
|
|
592
|
+
```
|
|
593
|
+
|
|
578
594
|
**前缀路由表**:
|
|
579
595
|
|
|
580
596
|
| 前缀 | 适配器 | 需要的包 |
|
|
@@ -746,13 +762,20 @@ class MyMemory(BaseMemoryProvider):
|
|
|
746
762
|
async def delete(self, memory_id) -> bool: ...
|
|
747
763
|
```
|
|
748
764
|
|
|
749
|
-
|
|
765
|
+
**内置实现**:
|
|
766
|
+
|
|
767
|
+
- `Mem0Provider`(需安装 `mem0ai`)
|
|
768
|
+
- `SQLiteMemoryProvider`(轻量 SQLite 持久化实现,`SimpleRAGAgent` 默认使用)
|
|
750
769
|
|
|
751
770
|
```python
|
|
771
|
+
from agentkit import SQLiteMemoryProvider
|
|
752
772
|
from agentkit.memory.mem0_provider import Mem0Provider
|
|
753
773
|
|
|
754
774
|
memory = Mem0Provider({"vector_store": {"provider": "qdrant", ...}})
|
|
755
775
|
agent = Agent(memory=memory, ...)
|
|
776
|
+
|
|
777
|
+
sqlite_memory = SQLiteMemoryProvider(".agentkit/rag/index.db")
|
|
778
|
+
agent = Agent(memory=sqlite_memory, ...)
|
|
756
779
|
```
|
|
757
780
|
|
|
758
781
|
Agent 会自动:
|
|
@@ -767,3 +790,57 @@ Agent 会自动:
|
|
|
767
790
|
| `content` | `str` | 记忆内容 |
|
|
768
791
|
| `metadata` | `dict` | 元数据 |
|
|
769
792
|
| `score` | `float` | 相关性分数(检索时) |
|
|
793
|
+
|
|
794
|
+
---
|
|
795
|
+
|
|
796
|
+
## RAG 类
|
|
797
|
+
|
|
798
|
+
### SimpleRAGAgent
|
|
799
|
+
|
|
800
|
+
AgentKit 内置轻量 RAG 构建器:将本地知识库检索能力组合为标准 `Agent`。
|
|
801
|
+
|
|
802
|
+
```python
|
|
803
|
+
from agentkit import SimpleRAGAgent
|
|
804
|
+
```
|
|
805
|
+
|
|
806
|
+
**能力范围(V1)**:
|
|
807
|
+
|
|
808
|
+
- 文档类型:`txt/md/markdown/pdf`
|
|
809
|
+
- 检索器:`tfidf`、`bm25`、`vector`、`hybrid`
|
|
810
|
+
- 存储:知识库源文件、chunks 与默认记忆统一写入 SQLite(默认 `./.agentkit/rag/index.db`)
|
|
811
|
+
- 记忆:默认启用 `SQLiteMemoryProvider`,可通过 `enable_memory=False` 关闭
|
|
812
|
+
- 模型:支持任意 AgentKit 可识别模型标识(`str | LLMConfig | BaseLLM`)
|
|
813
|
+
- PDF:需额外安装 `ni.agentkit[pdf]` 或 `pypdf`
|
|
814
|
+
|
|
815
|
+
**构造与工厂**:
|
|
816
|
+
|
|
817
|
+
| 方法 | 签名 | 说明 |
|
|
818
|
+
|------|------|------|
|
|
819
|
+
| `__init__` | `(..., model, config=None, memory_provider=None, storage_path=None, enable_memory=None, memory_file=None)` | 直接构造;`memory_file` 为兼容参数,当前会映射为 SQLite 路径 |
|
|
820
|
+
| `from_directory` | `(..., knowledge_dir, model, chunk_size=500, chunk_overlap=100, top_k=3, default_retriever="hybrid", storage_path=".agentkit/rag/index.db", enable_memory=True, memory_file=None, memory_provider=None)` | 推荐入口 |
|
|
821
|
+
|
|
822
|
+
**实例方法**:
|
|
823
|
+
|
|
824
|
+
| 方法 | 签名 | 说明 |
|
|
825
|
+
|------|------|------|
|
|
826
|
+
| `reload` | `() -> int` | 重新加载知识库并重建索引,返回 chunk 数 |
|
|
827
|
+
| `search` | `(query, *, top_k=None, retriever=None) -> list[SearchHit]` | 程序化检索 |
|
|
828
|
+
| `list_knowledge_files` | `() -> list[str]` | 列出知识库文件 |
|
|
829
|
+
| `storage_path` | `() -> str` | 返回当前 SQLite 存储路径 |
|
|
830
|
+
| `as_tools` | `() -> list[FunctionTool]` | 返回默认工具:`search_knowledge_base` / `list_knowledge_files` |
|
|
831
|
+
| `build_agent` | `(*, name="simple-rag-assistant", instructions=None, tool_use_behavior="run_llm_again", memory_async_write=False, **kwargs) -> Agent` | 构建标准 Agent |
|
|
832
|
+
|
|
833
|
+
**示例**:
|
|
834
|
+
|
|
835
|
+
```python
|
|
836
|
+
from agentkit import Runner, SimpleRAGAgent
|
|
837
|
+
|
|
838
|
+
rag = SimpleRAGAgent.from_directory(
|
|
839
|
+
knowledge_dir="./knowledge_base",
|
|
840
|
+
model="ollama/qwen3.5:4b",
|
|
841
|
+
default_retriever="hybrid",
|
|
842
|
+
storage_path=".agentkit/rag/index.db",
|
|
843
|
+
)
|
|
844
|
+
agent = rag.build_agent(name="rag-assistant")
|
|
845
|
+
print(Runner.run_sync(agent, input="这个项目是做什么的?").final_output)
|
|
846
|
+
```
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# AgentKit 示例测试报告
|
|
2
|
+
|
|
3
|
+
> 测试时间:`2026-06-15`
|
|
4
|
+
> 测试环境:`macOS (Apple Silicon)`
|
|
5
|
+
> 模型:`qwen/qwen3.6-flash` (DashScope)
|
|
6
|
+
> AgentKit 版本:v0.7.4
|
|
7
|
+
> Thinking 模式:开启(默认)
|
|
8
|
+
> LLM 调用模式:非流式(默认)
|
|
9
|
+
> 缓存:开启(默认)
|
|
10
|
+
> 执行脚本:`examples/test_standard.py`
|
|
11
|
+
> 说明:本报告由 `examples/test_standard.py` 批跑生成,共覆盖 26 个样例;`20_simple_rag_agent.py` 不在自动批跑范围内。
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 测试结果
|
|
16
|
+
|
|
17
|
+
| # | 示例 | 文件 | 耗时 | 状态 | 说明 |
|
|
18
|
+
|---|------|------|-----:|:----:|------|
|
|
19
|
+
| 1 | 01_basic_chat | `01_basic_chat.py` | 5.63s | ✅ | 运行通过 |
|
|
20
|
+
| 2 | 02_tool_calling | `02_tool_calling.py` | 10.70s | ✅ | 运行通过 |
|
|
21
|
+
| 3 | 03_skill_usage | `03_skill_usage.py` | 15.31s | ✅ | 运行通过 |
|
|
22
|
+
| 4 | 03b_skill_tools_entry | `03b_skill_tools_entry.py` | 7.79s | ✅ | 运行通过 |
|
|
23
|
+
| 5 | 04_multi_agent | `04_multi_agent.py` | 39.61s | ✅ | 运行通过 |
|
|
24
|
+
| 6 | 05_guardrail | `05_guardrail.py` | 7.09s | ✅ | 运行通过 |
|
|
25
|
+
| 7 | 05_human_in_the_loop | `05_human_in_the_loop.py` | 0.31s | ✅ | 运行通过 |
|
|
26
|
+
| 8 | 06_orchestration | `06_orchestration.py` | 36.54s | ✅ | 运行通过 |
|
|
27
|
+
| 9 | 07_sync_async_stream | `07_sync_async_stream.py` | 21.68s | ✅ | 运行通过 |
|
|
28
|
+
| 10 | 08_memory | `08_memory.py` | 35.79s | ✅ | 运行通过 |
|
|
29
|
+
| 11 | 08a_memory_simple_provider | `08a_memory_simple_provider.py` | 9.05s | ✅ | 运行通过 |
|
|
30
|
+
| 12 | 08b_memory_mem0_provider | `08b_memory_mem0_provider.py` | 0.29s | ✅ | 运行通过 |
|
|
31
|
+
| 13 | 08c_memory_file_provider | `08c_memory_file_provider.py` | 11.53s | ✅ | 运行通过 |
|
|
32
|
+
| 14 | 09a_structured_data_sql | `09a_structured_data_sql.py` | 6.91s | ✅ | 运行通过 |
|
|
33
|
+
| 15 | 09b_structured_data_graph | `09b_structured_data_graph.py` | 5.44s | ✅ | 运行通过 |
|
|
34
|
+
| 16 | 09c_nebula_graph_tool | `09c_nebula_graph_tool.py` | 0.45s | ✅ | 运行通过 |
|
|
35
|
+
| 17 | 10_skill_lifecycle | `10_skill_lifecycle.py` | 2.38s | ✅ | 运行通过 |
|
|
36
|
+
| 18 | 11_orchestration_enhancement | `11_orchestration_enhancement.py` | 3.16s | ✅ | 运行通过 |
|
|
37
|
+
| 19 | 12_run_context_serialization | `12_run_context_serialization.py` | 0.23s | ✅ | 运行通过 |
|
|
38
|
+
| 20 | 13_human_in_the_loop | `13_human_in_the_loop.py` | 5.88s | ✅ | 运行通过 |
|
|
39
|
+
| 21 | 14_event_standardization | `14_event_standardization.py` | 3.84s | ✅ | 运行通过 |
|
|
40
|
+
| 22 | 15_multi_tenant_isolation | `15_multi_tenant_isolation.py` | 6.93s | ✅ | 运行通过 |
|
|
41
|
+
| 23 | 16_lifecycle_hooks | `16_lifecycle_hooks.py` | 6.70s | ✅ | 运行通过 |
|
|
42
|
+
| 24 | 17_checkpoint_handoff_resume | `17_checkpoint_handoff_resume.py` | 0.22s | ✅ | 运行通过 |
|
|
43
|
+
| 25 | 18_model_cosplay | `18_model_cosplay.py` | 0.26s | ✅ | 运行通过 |
|
|
44
|
+
| 26 | 19_hitl_deterministic | `19_hitl_deterministic.py` | 0.25s | ✅ | 运行通过 |
|
|
45
|
+
| | **合计** | | **243.97s** | **26/26** | |
|
|
46
|
+
|
|
47
|
+
## 耗时分析
|
|
48
|
+
|
|
49
|
+
- **最快示例**:17_checkpoint_handoff_resume (0.22s)
|
|
50
|
+
- **最慢示例**:04_multi_agent (39.61s)
|
|
51
|
+
- **性能改进**:本次批跑合计 243.97s,耗时主要集中在 04_multi_agent / 06_orchestration / 08_memory 等编排类示例。
|
|
52
|
+
|
|
53
|
+
## 已知问题
|
|
54
|
+
|
|
55
|
+
| 问题 | 严重程度 | 说明 |
|
|
56
|
+
|------|:--------:|------|
|
|
57
|
+
| 运行异常 | - | 无,26 个示例全部通过 |
|
|
58
|
+
|
|
59
|
+
## 运行方式
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
# 在 agentkit 目录执行
|
|
63
|
+
python examples/test_standard.py
|
|
64
|
+
```
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""
|
|
2
|
+
示例 20:SimpleRAGAgent(Ollama 本地版)
|
|
3
|
+
|
|
4
|
+
运行前:
|
|
5
|
+
ollama serve
|
|
6
|
+
ollama pull qwen3.5:4b
|
|
7
|
+
mkdir -p ./knowledge_base
|
|
8
|
+
echo "AgentKit 支持 Tool、Skill、Memory 与多模型适配。" > ./knowledge_base/intro.txt
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", ".."))
|
|
17
|
+
|
|
18
|
+
from agentkit import Runner, SimpleRAGAgent
|
|
19
|
+
from model_config import resolve_model
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def main() -> None:
|
|
23
|
+
rag = SimpleRAGAgent.from_directory(
|
|
24
|
+
knowledge_dir="./knowledge_base",
|
|
25
|
+
model=resolve_model("qwen3.5:4b"),
|
|
26
|
+
top_k=3,
|
|
27
|
+
)
|
|
28
|
+
agent = rag.build_agent(name="simple-rag-ollama")
|
|
29
|
+
result = Runner.run_sync(agent, input="AgentKit 有哪些核心能力?")
|
|
30
|
+
print("✅ 回复:", result.final_output)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if __name__ == "__main__":
|
|
34
|
+
main()
|
|
@@ -46,6 +46,7 @@ pip install ni.agentkit
|
|
|
46
46
|
| `17_checkpoint_handoff_resume.py` | Checkpoint 深度恢复 — Handoff 后挂起并原路径恢复 | 增强示例 |
|
|
47
47
|
| `18_model_cosplay.py` | ModelCosplay — 运行时改写预设模型 | QuickStart 示例 18 |
|
|
48
48
|
| `19_hitl_deterministic.py` | HITL 确定性触发(必现) | 扩展示例 |
|
|
49
|
+
| `20_simple_rag_agent.py` | SimpleRAGAgent(本地文档检索 + 文件记忆) | 扩展示例 |
|
|
49
50
|
|
|
50
51
|
## 运行
|
|
51
52
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""
|
|
2
|
+
示例 5(Playground/HITL 专用):Human-in-the-loop Agent(标准版)
|
|
3
|
+
|
|
4
|
+
用途:
|
|
5
|
+
- 提供一个可被 AgentHub `entry` 直接加载的 `agent` 实例;
|
|
6
|
+
- 在工具执行前通过 `request_human_input(...)` 触发挂起,便于在 Playground 中演示 HITL。
|
|
7
|
+
"""
|
|
8
|
+
import os
|
|
9
|
+
import sys
|
|
10
|
+
|
|
11
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", ".."))
|
|
12
|
+
|
|
13
|
+
from agentkit import Agent
|
|
14
|
+
from agentkit.tools.base_tool import request_human_input
|
|
15
|
+
from agentkit.tools.function_tool import FunctionTool
|
|
16
|
+
from model_config import resolve_model
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def confirm_action(action: str) -> str:
|
|
20
|
+
"""敏感操作执行前请求人工确认。"""
|
|
21
|
+
request_human_input(f"即将执行敏感操作: {action},请确认 (approve/reject)")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def execute_action(action: str) -> str:
|
|
25
|
+
"""执行操作(示例返回)。"""
|
|
26
|
+
return f"操作 '{action}' 已执行。"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
confirm_tool = FunctionTool.from_function(confirm_action)
|
|
30
|
+
execute_tool = FunctionTool.from_function(execute_action)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
agent = Agent(
|
|
34
|
+
name="hitl-agent",
|
|
35
|
+
instructions=(
|
|
36
|
+
"你是一个需要人工审批的运维助手。"
|
|
37
|
+
"当用户要求执行敏感操作时,必须先调用 confirm_action 请求人工确认;"
|
|
38
|
+
"收到确认后再调用 execute_action。"
|
|
39
|
+
),
|
|
40
|
+
model=resolve_model("gpt-4o-mini"),
|
|
41
|
+
tools=[confirm_tool, execute_tool],
|
|
42
|
+
)
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""
|
|
2
|
+
示例 19(Playground/HITL 专用):确定性触发挂起(必现)
|
|
3
|
+
|
|
4
|
+
用途:
|
|
5
|
+
- 提供一个可被 AgentHub `entry` 直接加载的 `agent` 实例;
|
|
6
|
+
- 首次运行必然发出 `suspend_requested`,便于 Playground 稳定演示 HITL 闭环。
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
from typing import AsyncGenerator
|
|
13
|
+
|
|
14
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", ".."))
|
|
15
|
+
|
|
16
|
+
from agentkit.agents.base_agent import BaseAgent
|
|
17
|
+
from agentkit.runner.context import RunContext
|
|
18
|
+
from agentkit.runner.events import Event, EventType
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class DeterministicHITLAgent(BaseAgent):
|
|
22
|
+
async def _run_impl(self, ctx: RunContext) -> AsyncGenerator[Event, None]:
|
|
23
|
+
# 第一次进入会话时,确定性触发挂起。
|
|
24
|
+
if not ctx.state.get("deterministic_hitl_suspended_once"):
|
|
25
|
+
ctx.state["deterministic_hitl_suspended_once"] = True
|
|
26
|
+
suspension = ctx.register_suspension(
|
|
27
|
+
tool_call_id="det-hitl-1",
|
|
28
|
+
tool_name="manual_approval",
|
|
29
|
+
prompt="请审批该操作(approve/reject)",
|
|
30
|
+
)
|
|
31
|
+
yield Event(
|
|
32
|
+
agent=self.name,
|
|
33
|
+
type=EventType.SUSPEND_REQUESTED,
|
|
34
|
+
data={
|
|
35
|
+
"suspension_id": suspension.suspension_id,
|
|
36
|
+
"prompt": "请审批该操作(approve/reject)",
|
|
37
|
+
"tool": "manual_approval",
|
|
38
|
+
"tool_call_id": "det-hitl-1",
|
|
39
|
+
},
|
|
40
|
+
)
|
|
41
|
+
return
|
|
42
|
+
|
|
43
|
+
decision = "unknown"
|
|
44
|
+
for msg in reversed(ctx.messages):
|
|
45
|
+
if msg.get("role") == "tool" and msg.get("tool_call_id") == "det-hitl-1":
|
|
46
|
+
decision = msg.get("content", "unknown")
|
|
47
|
+
break
|
|
48
|
+
|
|
49
|
+
yield Event(
|
|
50
|
+
agent=self.name,
|
|
51
|
+
type=EventType.FINAL_OUTPUT,
|
|
52
|
+
data=f"已收到人工决策: {decision}",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
agent = DeterministicHITLAgent(name="deterministic-hitl-agent")
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
示例 20:SimpleRAGAgent(标准版)
|
|
3
|
+
|
|
4
|
+
运行前:
|
|
5
|
+
export OPENAI_API_KEY="sk-..."
|
|
6
|
+
mkdir -p ./knowledge_base
|
|
7
|
+
echo "AgentKit 是一个 Python 原生 Agent 框架。" > ./knowledge_base/intro.txt
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import os
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", ".."))
|
|
16
|
+
|
|
17
|
+
from agentkit import Runner, SimpleRAGAgent
|
|
18
|
+
from model_config import resolve_model
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def create_agent():
|
|
22
|
+
rag = SimpleRAGAgent.from_directory(
|
|
23
|
+
knowledge_dir="./knowledge_base",
|
|
24
|
+
model=resolve_model("gpt-4o-mini"),
|
|
25
|
+
top_k=3,
|
|
26
|
+
)
|
|
27
|
+
return rag.build_agent(name="simple-rag-standard")
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def main() -> None:
|
|
31
|
+
agent = create_agent()
|
|
32
|
+
result = Runner.run_sync(agent, input="AgentKit 是什么?")
|
|
33
|
+
print("✅ 回复:", result.final_output)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
main()
|