wisruntime 0.6.0__tar.gz → 0.7.0__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.
- {wisruntime-0.6.0/wisruntime.egg-info → wisruntime-0.7.0}/PKG-INFO +72 -18
- {wisruntime-0.6.0 → wisruntime-0.7.0}/README.md +71 -17
- {wisruntime-0.6.0 → wisruntime-0.7.0}/pyproject.toml +1 -1
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/__init__.py +58 -22
- wisruntime-0.7.0/wisruntime/adapters/langgraph/__init__.py +70 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/adapters/langgraph/builtin.py +34 -5
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/adapters/langgraph/converter.py +91 -1
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/adapters/langgraph/wrap_agent.py +30 -6
- wisruntime-0.7.0/wisruntime/agent_stream.py +144 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/client.py +73 -73
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/config.py +19 -8
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/conversation/__init__.py +8 -1
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/conversation/client.py +123 -15
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/conversation/model.py +121 -4
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/conversation/recorder.py +18 -5
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/exceptions.py +18 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/model.py +9 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/server/dify_handler.py +23 -148
- wisruntime-0.7.0/wisruntime/server/formatter.py +251 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/server/invoker.py +32 -3
- wisruntime-0.7.0/wisruntime/server/protocol.py +178 -0
- wisruntime-0.7.0/wisruntime/server/server.py +349 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/skill/client.py +193 -12
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/tool/__init__.py +6 -1
- wisruntime-0.7.0/wisruntime/tool/client.py +536 -0
- wisruntime-0.7.0/wisruntime/tool/model.py +158 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0/wisruntime.egg-info}/PKG-INFO +72 -18
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime.egg-info/SOURCES.txt +2 -0
- wisruntime-0.6.0/wisruntime/adapters/langgraph/__init__.py +0 -49
- wisruntime-0.6.0/wisruntime/server/protocol.py +0 -104
- wisruntime-0.6.0/wisruntime/server/server.py +0 -195
- wisruntime-0.6.0/wisruntime/tool/client.py +0 -292
- wisruntime-0.6.0/wisruntime/tool/model.py +0 -84
- {wisruntime-0.6.0 → wisruntime-0.7.0}/MANIFEST.in +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/setup.cfg +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/adapters/__init__.py +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/adapters/langgraph/_utils.py +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/adapters/langgraph/memory_middleware.py +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/adapters/langgraph/tool_adapter.py +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/memory/__init__.py +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/memory/client.py +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/memory/formatter.py +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/memory/model.py +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/server/__init__.py +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/skill/__init__.py +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/skill/model.py +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime/tool/protocol.py +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime.egg-info/dependency_links.txt +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime.egg-info/requires.txt +0 -0
- {wisruntime-0.6.0 → wisruntime-0.7.0}/wisruntime.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: wisruntime
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: 企业级 Agent Runtime SDK — 让 AI 工程师专注 Agent 能力开发,无需关心底层基础设施
|
|
5
5
|
Author: WIS Team
|
|
6
6
|
License-Expression: MIT
|
|
@@ -32,7 +32,9 @@ Requires-Dist: langchain-core>=0.3; extra == "langgraph"
|
|
|
32
32
|
|
|
33
33
|
# wisruntime — 企业级 Agent Runtime SDK
|
|
34
34
|
|
|
35
|
-
> **版本**: v0.
|
|
35
|
+
> **版本**: v0.6.0 | **日期**: 2026-10 | **团队**: WIS Team
|
|
36
|
+
|
|
37
|
+
> 📖 **用户指南**: [wisruntime-user-guide-v2.html](docs/wisruntime-user-guide-v2.html) —— 快速上手、手把手实现 invoke_agent、平台能力(MCP / Skill / 记忆)集成与进阶实践,建议优先阅读
|
|
36
38
|
|
|
37
39
|
---
|
|
38
40
|
|
|
@@ -395,7 +397,18 @@ class ToolClient(ABC):
|
|
|
395
397
|
|
|
396
398
|
# MCP 协议实现 (薄封装标准 mcp 包)
|
|
397
399
|
class MCPClient(ToolClient):
|
|
398
|
-
def __init__(self, client=None, url=None, api_key=None, timeout=None
|
|
400
|
+
def __init__(self, client=None, url=None, api_key=None, timeout=None, *,
|
|
401
|
+
read_timeout=None, # SSE 读超时,默认 300s
|
|
402
|
+
headers=None, # 额外请求头(显式 Authorization 优先)
|
|
403
|
+
auth=None, # httpx.Auth 动态鉴权
|
|
404
|
+
http_client=None, # 注入外部共享连接池(不建也不关)
|
|
405
|
+
limits=None, # 自建池限额,默认 100/20/60s
|
|
406
|
+
tools=None, # 自定义工具契约 ToolSpec 列表
|
|
407
|
+
discover=True, # 是否动态发现远端工具
|
|
408
|
+
tool_filter=None, # 只过滤发现结果
|
|
409
|
+
content_converter=None, # content item → dict 自定义映射
|
|
410
|
+
session_factory=None, # 完全接管传输层(SSE/私有网关/mock)
|
|
411
|
+
terminate_on_close=True):
|
|
399
412
|
# 统一 client 注入: 从 WisHubClient 推导 url/api_key/timeout
|
|
400
413
|
# 显式参数可覆盖; 无 client 时走 Config 三级获取
|
|
401
414
|
self._url = url or f"{Config().hub_endpoint}/wishub-mcp/mcp"
|
|
@@ -411,6 +424,22 @@ class MCPClient(ToolClient):
|
|
|
411
424
|
...
|
|
412
425
|
```
|
|
413
426
|
|
|
427
|
+
**自定义工具契约**(业务参数留在本地,传输复用 MCP):
|
|
428
|
+
|
|
429
|
+
```python
|
|
430
|
+
from wisruntime import ToolSpec
|
|
431
|
+
|
|
432
|
+
spec = ToolSpec(
|
|
433
|
+
name="annotationQuery",
|
|
434
|
+
description="查询指标标注",
|
|
435
|
+
parameters={"type": "object", "properties": {"query": {"type": "string"}}},
|
|
436
|
+
remote_name="query_annotation",
|
|
437
|
+
build_arguments=lambda a: {"annotationQuery": a["query"], "appId": "app-xxx"},
|
|
438
|
+
parse_result=lambda r: ToolResult(content=[{"type": "text", "text": r.text}]),
|
|
439
|
+
)
|
|
440
|
+
client = MCPClient(client=hub, tools=[spec], discover=False) # 只用本地契约
|
|
441
|
+
```
|
|
442
|
+
|
|
414
443
|
各 Client 职责:
|
|
415
444
|
|
|
416
445
|
| Client | 职责 | 端点示例 |
|
|
@@ -465,7 +494,7 @@ agent = create_deep_agent(model=model, tools=tools, skills=skill_paths)
|
|
|
465
494
|
|
|
466
495
|
Skill 客户端完整用法(发现/详情/批量下载)见 [docs/wishub-skill-api.md](docs/wishub-skill-api.md)。
|
|
467
496
|
|
|
468
|
-
**核心能力**: `from_tool_info()` 将 `ToolInfo` + 调用函数转为 `StructuredTool`(`BaseTool` 子类),内部自动完成 JSON Schema → Pydantic Model 的动态生成,无需手写参数校验。`from_client()` / `create_mcp_tools()` 一键发现所有工具并批量创建。MCPClient 无状态设计——每次 `call_tool()` 自包含 session
|
|
497
|
+
**核心能力**: `from_tool_info()` 将 `ToolInfo` + 调用函数转为 `StructuredTool`(`BaseTool` 子类),内部自动完成 JSON Schema → Pydantic Model 的动态生成,无需手写参数校验。`from_client()` / `create_mcp_tools()` 一键发现所有工具并批量创建。MCPClient 无状态设计——每次 `call_tool()` 自包含 session;HTTP 连接池在实例内复用(或注入外部共享池),`close()` 关闭自建池且幂等。
|
|
469
498
|
|
|
470
499
|
### 4.4 Adapter 层
|
|
471
500
|
|
|
@@ -860,6 +889,21 @@ Phase 3.5: 记忆能力接入 (✅ 已完成 — v0.4)
|
|
|
860
889
|
✅ wrap_agent config 注入 — user_id, thread_id 传递到 LangGraph config.configurable
|
|
861
890
|
✅ 完整测试覆盖 (39 个测试用例全部通过)
|
|
862
891
|
|
|
892
|
+
Phase 3.6: 统一客户端与会话能力 (✅ 已完成 — v0.5)
|
|
893
|
+
═══════════════════════════════════
|
|
894
|
+
✅ conversation/ 模块 — 会话数据模型、客户端与录制
|
|
895
|
+
✅ 记忆检索增强
|
|
896
|
+
✅ memory/ 重构为顶层平台客户端模块(与 tool/、skill/ 平行,框架无关)
|
|
897
|
+
- 旧路径 adapters/memory 降级为弃用 shim(DeprecationWarning)
|
|
898
|
+
|
|
899
|
+
Phase 3.7: 记忆入口统一与官方发布 (✅ 已完成 — v0.6.0)
|
|
900
|
+
═══════════════════════════════════
|
|
901
|
+
✅ WisHubClient 统一配置容器 — hub_endpoint/api_key/timeout 一次初始化、全模块注入
|
|
902
|
+
✅ 移除弃用的 adapters/memory shim
|
|
903
|
+
✅ WishubMemoryClient 等 5 个记忆符号转发导出并入 adapters.langgraph
|
|
904
|
+
(适配层唯一记忆入口;权威定义仍在 wisruntime.memory)
|
|
905
|
+
✅ 发布至官方 PyPI: pip install wisruntime
|
|
906
|
+
|
|
863
907
|
Phase 4: 高级特性
|
|
864
908
|
════════════════
|
|
865
909
|
目标: 用户故事 7 — Checkpoint、多协议
|
|
@@ -875,15 +919,16 @@ Phase 5: 多框架 + 多协议
|
|
|
875
919
|
|
|
876
920
|
□ AgentScope Adapter
|
|
877
921
|
□ AGUI Handler
|
|
878
|
-
|
|
922
|
+
✅ 官方 PyPI 发布 (v0.6.0 — pypi.org/project/wisruntime)
|
|
879
923
|
□ 性能基准测试
|
|
880
924
|
```
|
|
881
925
|
|
|
882
|
-
### 5.3 目录结构 (
|
|
926
|
+
### 5.3 目录结构 (v0.6)
|
|
883
927
|
|
|
884
928
|
```
|
|
885
929
|
wisruntime/
|
|
886
930
|
├── __init__.py # 顶层导出: create_server, Config, ToolInfo, ToolResult
|
|
931
|
+
├── client.py # WisHubClient — 统一配置容器 (hub_endpoint/api_key/timeout)
|
|
887
932
|
├── config.py # Config, CredentialContext
|
|
888
933
|
├── model.py # CanonicalEvent (13 种), AgentRequest, Message
|
|
889
934
|
├── exceptions.py # 自定义异常
|
|
@@ -894,15 +939,29 @@ wisruntime/
|
|
|
894
939
|
│ ├── protocol.py # ToolClient (ABC) — 抽象协议
|
|
895
940
|
│ └── client.py # MCPClient(ToolClient) — 薄封装标准 mcp 包
|
|
896
941
|
│
|
|
942
|
+
├── skill/ # Skill 知识包接入层 (✅ v0.3.x — wishub-skill openapi/v1)
|
|
943
|
+
│ ├── __init__.py # exports: SkillClient, SkillInfo, SkillDetailInfo, SkillPage
|
|
944
|
+
│ ├── model.py # SkillInfo / SkillDetailInfo / SkillPage(信封分页模型)
|
|
945
|
+
│ └── client.py # SkillClient — 分页发现 / 详情 / 302 预签名下载
|
|
946
|
+
│
|
|
947
|
+
├── memory/ # 记忆能力 — 框架无关平台客户端 (✅ v0.4, v0.5 重构至顶层)
|
|
948
|
+
│ ├── __init__.py # exports: WishubMemoryClient, MemoryPromptFormatter,
|
|
949
|
+
│ │ # MemoryItem, RetrieveRequest, RetrieveResponse
|
|
950
|
+
│ ├── model.py # MemoryItem, RetrieveRequest, RetrieveResponse (Pydantic 模型)
|
|
951
|
+
│ ├── client.py # WishubMemoryClient — 异步 HTTP 客户端,优雅降级
|
|
952
|
+
│ └── formatter.py # MemoryPromptFormatter — 记忆列表 → XML 提示词片段
|
|
953
|
+
│
|
|
954
|
+
├── conversation/ # 会话能力 — 会话模型/客户端/录制 (✅ v0.5)
|
|
955
|
+
│ ├── __init__.py
|
|
956
|
+
│ ├── model.py # 会话数据模型
|
|
957
|
+
│ ├── client.py # ConversationClient
|
|
958
|
+
│ └── recorder.py # 会话录制
|
|
959
|
+
│
|
|
897
960
|
├── adapters/ # Adapter + Capability Bridge
|
|
898
|
-
│ ├── memory/ # Memory 记忆检索适配器 (✅ v0.4)
|
|
899
|
-
│ │ ├── __init__.py # 导出 WishubMemoryClient, MemoryPromptFormatter, MemoryItem
|
|
900
|
-
│ │ ├── model.py # MemoryItem, RetrieveRequest, RetrieveResponse (Pydantic 模型)
|
|
901
|
-
│ │ ├── client.py # WishubMemoryClient — 异步 HTTP 客户端,优雅降级
|
|
902
|
-
│ │ └── formatter.py # MemoryPromptFormatter — 记忆列表 → XML 提示词片段
|
|
903
|
-
│ │
|
|
904
961
|
│ └── langgraph/ # LangGraph/LangChain/DeepAgents 框架 (✅ v0.3)
|
|
905
|
-
│ ├── __init__.py # 导出 LangGraphEventConverter, wrap_agent, LangChainToolAdapter,
|
|
962
|
+
│ ├── __init__.py # 导出 LangGraphEventConverter, wrap_agent, LangChainToolAdapter,
|
|
963
|
+
│ │ # create_model, create_mcp_tools, WishubMemoryMiddleware
|
|
964
|
+
│ │ # (v0.6 起转发导出 wisruntime.memory 的 5 个记忆符号)
|
|
906
965
|
│ ├── converter.py # LangGraphEventConverter (astream_events → CanonicalEvent)
|
|
907
966
|
│ ├── wrap_agent.py # wrap_agent() 糖函数 (注入 config: user_id, thread_id)
|
|
908
967
|
│ ├── tool_adapter.py # LangChainToolAdapter (ToolInfo → StructuredTool)
|
|
@@ -916,11 +975,6 @@ wisruntime/
|
|
|
916
975
|
│ ├── dify_handler.py # DifyHandler (SSE + Blocking)
|
|
917
976
|
│ └── protocol.py # ProtocolHandler 抽象基类
|
|
918
977
|
│
|
|
919
|
-
├── skill/ # Skill 知识包接入层 (✅ v0.3.x — wishub-skill openapi/v1)
|
|
920
|
-
│ ├── __init__.py # exports: SkillClient, SkillInfo, SkillDetailInfo, SkillPage
|
|
921
|
-
│ ├── model.py # SkillInfo / SkillDetailInfo / SkillPage(信封分页模型)
|
|
922
|
-
│ └── client.py # SkillClient — 分页发现 / 详情 / 302 预签名下载
|
|
923
|
-
│
|
|
924
978
|
└── (未来: sandbox/, checkpoint/) # 远程工具接入走 ToolClient 协议,不同实现
|
|
925
979
|
```
|
|
926
980
|
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# wisruntime — 企业级 Agent Runtime SDK
|
|
2
2
|
|
|
3
|
-
> **版本**: v0.
|
|
3
|
+
> **版本**: v0.6.0 | **日期**: 2026-10 | **团队**: WIS Team
|
|
4
|
+
|
|
5
|
+
> 📖 **用户指南**: [wisruntime-user-guide-v2.html](docs/wisruntime-user-guide-v2.html) —— 快速上手、手把手实现 invoke_agent、平台能力(MCP / Skill / 记忆)集成与进阶实践,建议优先阅读
|
|
4
6
|
|
|
5
7
|
---
|
|
6
8
|
|
|
@@ -363,7 +365,18 @@ class ToolClient(ABC):
|
|
|
363
365
|
|
|
364
366
|
# MCP 协议实现 (薄封装标准 mcp 包)
|
|
365
367
|
class MCPClient(ToolClient):
|
|
366
|
-
def __init__(self, client=None, url=None, api_key=None, timeout=None
|
|
368
|
+
def __init__(self, client=None, url=None, api_key=None, timeout=None, *,
|
|
369
|
+
read_timeout=None, # SSE 读超时,默认 300s
|
|
370
|
+
headers=None, # 额外请求头(显式 Authorization 优先)
|
|
371
|
+
auth=None, # httpx.Auth 动态鉴权
|
|
372
|
+
http_client=None, # 注入外部共享连接池(不建也不关)
|
|
373
|
+
limits=None, # 自建池限额,默认 100/20/60s
|
|
374
|
+
tools=None, # 自定义工具契约 ToolSpec 列表
|
|
375
|
+
discover=True, # 是否动态发现远端工具
|
|
376
|
+
tool_filter=None, # 只过滤发现结果
|
|
377
|
+
content_converter=None, # content item → dict 自定义映射
|
|
378
|
+
session_factory=None, # 完全接管传输层(SSE/私有网关/mock)
|
|
379
|
+
terminate_on_close=True):
|
|
367
380
|
# 统一 client 注入: 从 WisHubClient 推导 url/api_key/timeout
|
|
368
381
|
# 显式参数可覆盖; 无 client 时走 Config 三级获取
|
|
369
382
|
self._url = url or f"{Config().hub_endpoint}/wishub-mcp/mcp"
|
|
@@ -379,6 +392,22 @@ class MCPClient(ToolClient):
|
|
|
379
392
|
...
|
|
380
393
|
```
|
|
381
394
|
|
|
395
|
+
**自定义工具契约**(业务参数留在本地,传输复用 MCP):
|
|
396
|
+
|
|
397
|
+
```python
|
|
398
|
+
from wisruntime import ToolSpec
|
|
399
|
+
|
|
400
|
+
spec = ToolSpec(
|
|
401
|
+
name="annotationQuery",
|
|
402
|
+
description="查询指标标注",
|
|
403
|
+
parameters={"type": "object", "properties": {"query": {"type": "string"}}},
|
|
404
|
+
remote_name="query_annotation",
|
|
405
|
+
build_arguments=lambda a: {"annotationQuery": a["query"], "appId": "app-xxx"},
|
|
406
|
+
parse_result=lambda r: ToolResult(content=[{"type": "text", "text": r.text}]),
|
|
407
|
+
)
|
|
408
|
+
client = MCPClient(client=hub, tools=[spec], discover=False) # 只用本地契约
|
|
409
|
+
```
|
|
410
|
+
|
|
382
411
|
各 Client 职责:
|
|
383
412
|
|
|
384
413
|
| Client | 职责 | 端点示例 |
|
|
@@ -433,7 +462,7 @@ agent = create_deep_agent(model=model, tools=tools, skills=skill_paths)
|
|
|
433
462
|
|
|
434
463
|
Skill 客户端完整用法(发现/详情/批量下载)见 [docs/wishub-skill-api.md](docs/wishub-skill-api.md)。
|
|
435
464
|
|
|
436
|
-
**核心能力**: `from_tool_info()` 将 `ToolInfo` + 调用函数转为 `StructuredTool`(`BaseTool` 子类),内部自动完成 JSON Schema → Pydantic Model 的动态生成,无需手写参数校验。`from_client()` / `create_mcp_tools()` 一键发现所有工具并批量创建。MCPClient 无状态设计——每次 `call_tool()` 自包含 session
|
|
465
|
+
**核心能力**: `from_tool_info()` 将 `ToolInfo` + 调用函数转为 `StructuredTool`(`BaseTool` 子类),内部自动完成 JSON Schema → Pydantic Model 的动态生成,无需手写参数校验。`from_client()` / `create_mcp_tools()` 一键发现所有工具并批量创建。MCPClient 无状态设计——每次 `call_tool()` 自包含 session;HTTP 连接池在实例内复用(或注入外部共享池),`close()` 关闭自建池且幂等。
|
|
437
466
|
|
|
438
467
|
### 4.4 Adapter 层
|
|
439
468
|
|
|
@@ -828,6 +857,21 @@ Phase 3.5: 记忆能力接入 (✅ 已完成 — v0.4)
|
|
|
828
857
|
✅ wrap_agent config 注入 — user_id, thread_id 传递到 LangGraph config.configurable
|
|
829
858
|
✅ 完整测试覆盖 (39 个测试用例全部通过)
|
|
830
859
|
|
|
860
|
+
Phase 3.6: 统一客户端与会话能力 (✅ 已完成 — v0.5)
|
|
861
|
+
═══════════════════════════════════
|
|
862
|
+
✅ conversation/ 模块 — 会话数据模型、客户端与录制
|
|
863
|
+
✅ 记忆检索增强
|
|
864
|
+
✅ memory/ 重构为顶层平台客户端模块(与 tool/、skill/ 平行,框架无关)
|
|
865
|
+
- 旧路径 adapters/memory 降级为弃用 shim(DeprecationWarning)
|
|
866
|
+
|
|
867
|
+
Phase 3.7: 记忆入口统一与官方发布 (✅ 已完成 — v0.6.0)
|
|
868
|
+
═══════════════════════════════════
|
|
869
|
+
✅ WisHubClient 统一配置容器 — hub_endpoint/api_key/timeout 一次初始化、全模块注入
|
|
870
|
+
✅ 移除弃用的 adapters/memory shim
|
|
871
|
+
✅ WishubMemoryClient 等 5 个记忆符号转发导出并入 adapters.langgraph
|
|
872
|
+
(适配层唯一记忆入口;权威定义仍在 wisruntime.memory)
|
|
873
|
+
✅ 发布至官方 PyPI: pip install wisruntime
|
|
874
|
+
|
|
831
875
|
Phase 4: 高级特性
|
|
832
876
|
════════════════
|
|
833
877
|
目标: 用户故事 7 — Checkpoint、多协议
|
|
@@ -843,15 +887,16 @@ Phase 5: 多框架 + 多协议
|
|
|
843
887
|
|
|
844
888
|
□ AgentScope Adapter
|
|
845
889
|
□ AGUI Handler
|
|
846
|
-
|
|
890
|
+
✅ 官方 PyPI 发布 (v0.6.0 — pypi.org/project/wisruntime)
|
|
847
891
|
□ 性能基准测试
|
|
848
892
|
```
|
|
849
893
|
|
|
850
|
-
### 5.3 目录结构 (
|
|
894
|
+
### 5.3 目录结构 (v0.6)
|
|
851
895
|
|
|
852
896
|
```
|
|
853
897
|
wisruntime/
|
|
854
898
|
├── __init__.py # 顶层导出: create_server, Config, ToolInfo, ToolResult
|
|
899
|
+
├── client.py # WisHubClient — 统一配置容器 (hub_endpoint/api_key/timeout)
|
|
855
900
|
├── config.py # Config, CredentialContext
|
|
856
901
|
├── model.py # CanonicalEvent (13 种), AgentRequest, Message
|
|
857
902
|
├── exceptions.py # 自定义异常
|
|
@@ -862,15 +907,29 @@ wisruntime/
|
|
|
862
907
|
│ ├── protocol.py # ToolClient (ABC) — 抽象协议
|
|
863
908
|
│ └── client.py # MCPClient(ToolClient) — 薄封装标准 mcp 包
|
|
864
909
|
│
|
|
910
|
+
├── skill/ # Skill 知识包接入层 (✅ v0.3.x — wishub-skill openapi/v1)
|
|
911
|
+
│ ├── __init__.py # exports: SkillClient, SkillInfo, SkillDetailInfo, SkillPage
|
|
912
|
+
│ ├── model.py # SkillInfo / SkillDetailInfo / SkillPage(信封分页模型)
|
|
913
|
+
│ └── client.py # SkillClient — 分页发现 / 详情 / 302 预签名下载
|
|
914
|
+
│
|
|
915
|
+
├── memory/ # 记忆能力 — 框架无关平台客户端 (✅ v0.4, v0.5 重构至顶层)
|
|
916
|
+
│ ├── __init__.py # exports: WishubMemoryClient, MemoryPromptFormatter,
|
|
917
|
+
│ │ # MemoryItem, RetrieveRequest, RetrieveResponse
|
|
918
|
+
│ ├── model.py # MemoryItem, RetrieveRequest, RetrieveResponse (Pydantic 模型)
|
|
919
|
+
│ ├── client.py # WishubMemoryClient — 异步 HTTP 客户端,优雅降级
|
|
920
|
+
│ └── formatter.py # MemoryPromptFormatter — 记忆列表 → XML 提示词片段
|
|
921
|
+
│
|
|
922
|
+
├── conversation/ # 会话能力 — 会话模型/客户端/录制 (✅ v0.5)
|
|
923
|
+
│ ├── __init__.py
|
|
924
|
+
│ ├── model.py # 会话数据模型
|
|
925
|
+
│ ├── client.py # ConversationClient
|
|
926
|
+
│ └── recorder.py # 会话录制
|
|
927
|
+
│
|
|
865
928
|
├── adapters/ # Adapter + Capability Bridge
|
|
866
|
-
│ ├── memory/ # Memory 记忆检索适配器 (✅ v0.4)
|
|
867
|
-
│ │ ├── __init__.py # 导出 WishubMemoryClient, MemoryPromptFormatter, MemoryItem
|
|
868
|
-
│ │ ├── model.py # MemoryItem, RetrieveRequest, RetrieveResponse (Pydantic 模型)
|
|
869
|
-
│ │ ├── client.py # WishubMemoryClient — 异步 HTTP 客户端,优雅降级
|
|
870
|
-
│ │ └── formatter.py # MemoryPromptFormatter — 记忆列表 → XML 提示词片段
|
|
871
|
-
│ │
|
|
872
929
|
│ └── langgraph/ # LangGraph/LangChain/DeepAgents 框架 (✅ v0.3)
|
|
873
|
-
│ ├── __init__.py # 导出 LangGraphEventConverter, wrap_agent, LangChainToolAdapter,
|
|
930
|
+
│ ├── __init__.py # 导出 LangGraphEventConverter, wrap_agent, LangChainToolAdapter,
|
|
931
|
+
│ │ # create_model, create_mcp_tools, WishubMemoryMiddleware
|
|
932
|
+
│ │ # (v0.6 起转发导出 wisruntime.memory 的 5 个记忆符号)
|
|
874
933
|
│ ├── converter.py # LangGraphEventConverter (astream_events → CanonicalEvent)
|
|
875
934
|
│ ├── wrap_agent.py # wrap_agent() 糖函数 (注入 config: user_id, thread_id)
|
|
876
935
|
│ ├── tool_adapter.py # LangChainToolAdapter (ToolInfo → StructuredTool)
|
|
@@ -884,11 +943,6 @@ wisruntime/
|
|
|
884
943
|
│ ├── dify_handler.py # DifyHandler (SSE + Blocking)
|
|
885
944
|
│ └── protocol.py # ProtocolHandler 抽象基类
|
|
886
945
|
│
|
|
887
|
-
├── skill/ # Skill 知识包接入层 (✅ v0.3.x — wishub-skill openapi/v1)
|
|
888
|
-
│ ├── __init__.py # exports: SkillClient, SkillInfo, SkillDetailInfo, SkillPage
|
|
889
|
-
│ ├── model.py # SkillInfo / SkillDetailInfo / SkillPage(信封分页模型)
|
|
890
|
-
│ └── client.py # SkillClient — 分页发现 / 详情 / 302 预签名下载
|
|
891
|
-
│
|
|
892
946
|
└── (未来: sandbox/, checkpoint/) # 远程工具接入走 ToolClient 协议,不同实现
|
|
893
947
|
```
|
|
894
948
|
|
|
@@ -41,20 +41,25 @@ from wisruntime.model import (
|
|
|
41
41
|
UsageEvent,
|
|
42
42
|
)
|
|
43
43
|
|
|
44
|
-
# ToolInfo / ToolResult — re-exported from wisruntime.tool for backward compatibility
|
|
45
|
-
from wisruntime.tool.model import ToolInfo, ToolResult
|
|
44
|
+
# ToolInfo / ToolResult / ToolSpec — re-exported from wisruntime.tool for backward compatibility
|
|
45
|
+
from wisruntime.tool.model import ToolInfo, ToolResult, ToolSpec
|
|
46
46
|
|
|
47
47
|
# Server 层延迟导入 — 避免在非 Web 场景拉动 fastapi/uvicorn
|
|
48
48
|
# 用户需要 Server 时显式导入: from wisruntime.server import create_server
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
def create_server(
|
|
52
|
-
invoke_agent,
|
|
52
|
+
invoke_agent=None,
|
|
53
53
|
*,
|
|
54
54
|
protocols=None,
|
|
55
55
|
config=None,
|
|
56
|
-
checkpoint_enabled=False,
|
|
57
56
|
conversation_client=None,
|
|
57
|
+
middlewares=None,
|
|
58
|
+
routers=None,
|
|
59
|
+
lifespan=None,
|
|
60
|
+
http_middlewares=None,
|
|
61
|
+
exception_handlers=None,
|
|
62
|
+
auto_done=True,
|
|
58
63
|
):
|
|
59
64
|
"""创建 WisRuntimeServer 实例 (顶层入口 API)。
|
|
60
65
|
|
|
@@ -66,14 +71,25 @@ def create_server(
|
|
|
66
71
|
|
|
67
72
|
Args:
|
|
68
73
|
invoke_agent: 用户函数 (async def fn(request: AgentRequest) → AsyncGenerator)
|
|
69
|
-
或 LangGraph CompiledStateGraph
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
74
|
+
或 LangGraph CompiledStateGraph。``protocols`` 为空时可省略
|
|
75
|
+
——此时外壳只承载宿主自有路由,不产出任何事件流。
|
|
76
|
+
protocols: 协议处理器列表,默认 [DifyHandler()]。显式传 ``[]``
|
|
77
|
+
表示不注册任何协议路由(宿主自带接口、只想复用外壳时用)。
|
|
78
|
+
config: ServerConfig 实例,配置 CORS、健康检查、应用标题等。
|
|
73
79
|
conversation_client: 会话客户端 (ConversationClient)。传入时启用
|
|
74
80
|
会话自动持久化:首轮自动建会话并回填 conversation_id 到
|
|
75
81
|
流式事件,每轮结束后后台追加 user/assistant 消息。
|
|
76
82
|
不传则行为与之前完全一致 (不落库)。
|
|
83
|
+
middlewares: 流中间件列表,按注册序由外到内串联。
|
|
84
|
+
routers: 宿主自有路由,注册在协议路由之前。元素为 ``APIRouter``
|
|
85
|
+
或 ``(APIRouter, prefix)``——后者把宿主前缀随 router 一起交出。
|
|
86
|
+
lifespan: 宿主 lifespan,与 recorder 收尾自动组合。
|
|
87
|
+
http_middlewares: Starlette 中间件列表,元素为
|
|
88
|
+
``(MiddlewareClass, kwargs_dict)``。
|
|
89
|
+
exception_handlers: 全局异常处理器 ``{异常类型: handler}``,
|
|
90
|
+
宿主自带兜底逻辑时经此传入,无需装配后再操作 app。
|
|
91
|
+
auto_done: 正常结束后是否自动补 ``done`` 终态。宿主 Agent 函数已产出
|
|
92
|
+
终态事件(如灵知 ``message_end``)时置 ``False``,避免终止帧重复。
|
|
77
93
|
|
|
78
94
|
Returns:
|
|
79
95
|
WisRuntimeServer 实例,调用 .start(port=8000) 或 .as_fastapi_app() 启动服务。
|
|
@@ -95,32 +111,42 @@ def create_server(
|
|
|
95
111
|
>>> server = create_server(my_agent, conversation_client=ConversationClient())
|
|
96
112
|
"""
|
|
97
113
|
from wisruntime.server.server import WisRuntimeServer, ServerConfig
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
114
|
+
|
|
115
|
+
# 注意:不能用 ``protocols or [...]``——空列表是合法入参,表示不注册协议路由
|
|
116
|
+
if protocols is None:
|
|
117
|
+
from wisruntime.server.dify_handler import DifyHandler
|
|
118
|
+
|
|
119
|
+
_protocols = [DifyHandler()]
|
|
120
|
+
else:
|
|
121
|
+
_protocols = list(protocols)
|
|
122
|
+
|
|
123
|
+
# 只在确实传了 agent 函数/图时才归一化:空协议外壳不需要事件流函数,
|
|
124
|
+
# 也就不必拉起 langgraph adapter(外壳对框架保持无关)
|
|
125
|
+
if invoke_agent is not None:
|
|
126
|
+
from wisruntime.adapters.langgraph.wrap_agent import coerce_invoke_agent
|
|
127
|
+
|
|
128
|
+
invoke_agent = coerce_invoke_agent(invoke_agent)
|
|
111
129
|
|
|
112
130
|
_config = config or ServerConfig()
|
|
113
|
-
_protocols = protocols or [DifyHandler()]
|
|
114
131
|
return WisRuntimeServer(
|
|
115
132
|
invoke_agent=invoke_agent,
|
|
116
133
|
protocols=_protocols,
|
|
117
134
|
config=_config,
|
|
118
135
|
conversation_client=conversation_client,
|
|
136
|
+
middlewares=middlewares,
|
|
137
|
+
routers=routers,
|
|
138
|
+
lifespan=lifespan,
|
|
139
|
+
http_middlewares=http_middlewares,
|
|
140
|
+
exception_handlers=exception_handlers,
|
|
141
|
+
auto_done=auto_done,
|
|
119
142
|
)
|
|
120
143
|
|
|
121
144
|
|
|
122
145
|
__all__ = [
|
|
123
146
|
"create_server",
|
|
147
|
+
"create_agent_stream",
|
|
148
|
+
"combine_lifespans",
|
|
149
|
+
"AgentStream",
|
|
124
150
|
"wrap_agent",
|
|
125
151
|
"Config",
|
|
126
152
|
"CredentialContext",
|
|
@@ -142,6 +168,7 @@ __all__ = [
|
|
|
142
168
|
"DoneEvent",
|
|
143
169
|
"ToolInfo",
|
|
144
170
|
"ToolResult",
|
|
171
|
+
"ToolSpec",
|
|
145
172
|
"WisRuntimeError",
|
|
146
173
|
"ConfigError",
|
|
147
174
|
"ProtocolError",
|
|
@@ -158,4 +185,13 @@ def __getattr__(name):
|
|
|
158
185
|
if name == "wrap_agent":
|
|
159
186
|
from wisruntime.adapters.langgraph import wrap_agent as _wrap_agent
|
|
160
187
|
return _wrap_agent
|
|
188
|
+
if name in ("create_agent_stream", "AgentStream"):
|
|
189
|
+
from wisruntime import agent_stream as _agent_stream
|
|
190
|
+
return getattr(_agent_stream, name)
|
|
191
|
+
if name == "combine_lifespans":
|
|
192
|
+
from wisruntime.server.server import combine_lifespans as _combine
|
|
193
|
+
return _combine
|
|
194
|
+
if name == "DifyEventFormatter":
|
|
195
|
+
from wisruntime.server.formatter import DifyEventFormatter as _fmt
|
|
196
|
+
return _fmt
|
|
161
197
|
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""LangGraph/LangChain/DeepAgents 框架适配器。
|
|
2
|
+
|
|
3
|
+
提供:
|
|
4
|
+
- LangGraphEventConverter: astream_events v2 → CanonicalEvent 转换器
|
|
5
|
+
- wrap_agent: CompiledStateGraph → invoke_agent 糖函数
|
|
6
|
+
- LangChainToolAdapter: ToolClient → StructuredTool 适配器
|
|
7
|
+
- create_model: 快速创建 LangChain 模型实例
|
|
8
|
+
- create_mcp_tools: 一行获取 MCP 工具列表
|
|
9
|
+
- WishubMemoryMiddleware: Wishub 记忆检索中间件
|
|
10
|
+
- WishubMemoryClient / MemoryPromptFormatter / MemoryItem /
|
|
11
|
+
RetrieveRequest / RetrieveResponse: wisruntime.memory 的转发导出
|
|
12
|
+
(框架无关,权威定义在 wisruntime.memory),使本包成为适配层
|
|
13
|
+
唯一的记忆入口
|
|
14
|
+
|
|
15
|
+
**惰性导出**:本包不 eager 导入 langgraph/langchain。只想用某个子模块
|
|
16
|
+
(例如 ``wrap_agent.coerce_invoke_agent`` 做类型判定)的宿主,不会因为
|
|
17
|
+
包级导入而被拉进整套框架依赖。
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from importlib import import_module
|
|
21
|
+
|
|
22
|
+
# 符号名 → (模块路径, 属性名)
|
|
23
|
+
_LAZY_ATTRS: dict[str, tuple[str, str]] = {
|
|
24
|
+
"LangGraphEventConverter": (
|
|
25
|
+
"wisruntime.adapters.langgraph.converter",
|
|
26
|
+
"LangGraphEventConverter",
|
|
27
|
+
),
|
|
28
|
+
"wrap_agent": ("wisruntime.adapters.langgraph.wrap_agent", "wrap_agent"),
|
|
29
|
+
"LangChainToolAdapter": (
|
|
30
|
+
"wisruntime.adapters.langgraph.tool_adapter",
|
|
31
|
+
"LangChainToolAdapter",
|
|
32
|
+
),
|
|
33
|
+
"create_model": ("wisruntime.adapters.langgraph.builtin", "create_model"),
|
|
34
|
+
"create_mcp_tools": ("wisruntime.adapters.langgraph.builtin", "create_mcp_tools"),
|
|
35
|
+
"WishubMemoryMiddleware": (
|
|
36
|
+
"wisruntime.adapters.langgraph.memory_middleware",
|
|
37
|
+
"WishubMemoryMiddleware",
|
|
38
|
+
),
|
|
39
|
+
"WishubMemoryState": (
|
|
40
|
+
"wisruntime.adapters.langgraph.memory_middleware",
|
|
41
|
+
"WishubMemoryState",
|
|
42
|
+
),
|
|
43
|
+
"WishubMemoryStateUpdate": (
|
|
44
|
+
"wisruntime.adapters.langgraph.memory_middleware",
|
|
45
|
+
"WishubMemoryStateUpdate",
|
|
46
|
+
),
|
|
47
|
+
# wisruntime.memory 的转发导出(框架无关,权威定义见 wisruntime.memory)
|
|
48
|
+
"WishubMemoryClient": ("wisruntime.memory", "WishubMemoryClient"),
|
|
49
|
+
"MemoryPromptFormatter": ("wisruntime.memory", "MemoryPromptFormatter"),
|
|
50
|
+
"MemoryItem": ("wisruntime.memory", "MemoryItem"),
|
|
51
|
+
"RetrieveRequest": ("wisruntime.memory", "RetrieveRequest"),
|
|
52
|
+
"RetrieveResponse": ("wisruntime.memory", "RetrieveResponse"),
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
__all__ = list(_LAZY_ATTRS)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def __getattr__(name: str):
|
|
59
|
+
"""按需导入符号(PEP 562),首次取用后缓存进模块命名空间。"""
|
|
60
|
+
target = _LAZY_ATTRS.get(name)
|
|
61
|
+
if target is None:
|
|
62
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
63
|
+
module_path, attr = target
|
|
64
|
+
value = getattr(import_module(module_path), attr)
|
|
65
|
+
globals()[name] = value
|
|
66
|
+
return value
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def __dir__() -> list[str]:
|
|
70
|
+
return sorted(__all__)
|
|
@@ -76,6 +76,11 @@ async def create_mcp_tools(
|
|
|
76
76
|
url: str | None = None,
|
|
77
77
|
api_key: str | None = None,
|
|
78
78
|
filter_fn=None,
|
|
79
|
+
*,
|
|
80
|
+
tools: list | None = None,
|
|
81
|
+
discover: bool = True,
|
|
82
|
+
timeout: int | None = None,
|
|
83
|
+
**client_kwargs,
|
|
79
84
|
) -> list:
|
|
80
85
|
"""一行获取 MCP 工具列表,Ready for DeepAgents。
|
|
81
86
|
|
|
@@ -86,21 +91,45 @@ async def create_mcp_tools(
|
|
|
86
91
|
url/api_key/timeout 从中推导;显式参数可覆盖。
|
|
87
92
|
url: MCP Server URL。None 时从 client 或 Config 推导。
|
|
88
93
|
api_key: API Key。None 时从 client 或 Config 三级获取。
|
|
89
|
-
filter_fn:
|
|
94
|
+
filter_fn: 可选过滤函数,作用于最终工具列表(含自定义契约)。
|
|
95
|
+
tools: 自定义工具契约(``ToolSpec`` 列表),与动态发现并存,
|
|
96
|
+
同名时以自定义为准。
|
|
97
|
+
discover: 是否动态发现远端工具。False 时只用 ``tools``。
|
|
98
|
+
timeout: 连接/常规请求超时(秒)。
|
|
99
|
+
**client_kwargs: 透传给 ``MCPClient`` 的其余参数,如
|
|
100
|
+
``read_timeout`` / ``headers`` / ``auth`` / ``http_client`` /
|
|
101
|
+
``limits`` / ``tool_filter`` / ``content_converter`` /
|
|
102
|
+
``session_factory`` / ``terminate_on_close``。
|
|
90
103
|
|
|
91
104
|
Returns:
|
|
92
105
|
LangChainToolAdapter 列表(兼容 StructuredTool)。
|
|
93
106
|
|
|
94
107
|
Example:
|
|
95
|
-
>>> from wisruntime import WisHubClient
|
|
108
|
+
>>> from wisruntime import WisHubClient, ToolSpec
|
|
96
109
|
>>> from deepagents import create_deep_agent
|
|
97
110
|
>>> client = WisHubClient(hub_endpoint="https://...", api_key="sk-...")
|
|
98
111
|
>>> tools = await create_mcp_tools(client=client)
|
|
99
112
|
>>> agent = create_deep_agent(model=model, tools=tools)
|
|
113
|
+
>>>
|
|
114
|
+
>>> # 自定义契约 + 共享连接池
|
|
115
|
+
>>> tools = await create_mcp_tools(
|
|
116
|
+
... client=client,
|
|
117
|
+
... tools=[ToolSpec(name="annotationQuery", ...)],
|
|
118
|
+
... http_client=shared_httpx_client,
|
|
119
|
+
... )
|
|
100
120
|
"""
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
121
|
+
# 只传显式给出的项:其余留空走 MCPClient / Config 的默认推导
|
|
122
|
+
kwargs: dict = dict(client_kwargs)
|
|
123
|
+
if timeout is not None:
|
|
124
|
+
kwargs["timeout"] = timeout
|
|
125
|
+
if tools is not None:
|
|
126
|
+
kwargs["tools"] = tools
|
|
127
|
+
if not discover:
|
|
128
|
+
kwargs["discover"] = False
|
|
129
|
+
|
|
130
|
+
mcp_client = MCPClient(client=client, url=url, api_key=api_key, **kwargs)
|
|
131
|
+
# No explicit close() needed — session 每次调用自建自销;
|
|
132
|
+
# 连接池在 mcp_client 实例内复用,进程退出由 GC 回收。
|
|
104
133
|
return await LangChainToolAdapter.from_client(mcp_client, filter_fn=filter_fn)
|
|
105
134
|
|
|
106
135
|
|