wisruntime 0.4.2__tar.gz → 0.6.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.4.2/wisruntime.egg-info → wisruntime-0.6.0}/PKG-INFO +96 -11
- {wisruntime-0.4.2 → wisruntime-0.6.0}/README.md +95 -10
- {wisruntime-0.4.2 → wisruntime-0.6.0}/pyproject.toml +1 -1
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/__init__.py +2 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/adapters/__init__.py +4 -0
- wisruntime-0.6.0/wisruntime/adapters/langgraph/__init__.py +49 -0
- wisruntime-0.6.0/wisruntime/adapters/langgraph/_utils.py +34 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/adapters/langgraph/builtin.py +14 -6
- wisruntime-0.6.0/wisruntime/adapters/langgraph/memory_middleware.py +235 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/adapters/langgraph/wrap_agent.py +18 -0
- wisruntime-0.6.0/wisruntime/client.py +73 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/conversation/client.py +29 -11
- wisruntime-0.6.0/wisruntime/memory/__init__.py +17 -0
- wisruntime-0.6.0/wisruntime/memory/client.py +126 -0
- wisruntime-0.6.0/wisruntime/memory/formatter.py +67 -0
- wisruntime-0.6.0/wisruntime/memory/model.py +45 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/skill/client.py +28 -10
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/tool/client.py +24 -8
- {wisruntime-0.4.2 → wisruntime-0.6.0/wisruntime.egg-info}/PKG-INFO +96 -11
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime.egg-info/SOURCES.txt +7 -0
- wisruntime-0.4.2/wisruntime/adapters/langgraph/__init__.py +0 -22
- {wisruntime-0.4.2 → wisruntime-0.6.0}/MANIFEST.in +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/setup.cfg +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/adapters/langgraph/converter.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/adapters/langgraph/tool_adapter.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/config.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/conversation/__init__.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/conversation/model.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/conversation/recorder.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/exceptions.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/model.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/server/__init__.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/server/dify_handler.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/server/invoker.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/server/protocol.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/server/server.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/skill/__init__.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/skill/model.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/tool/__init__.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/tool/model.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime/tool/protocol.py +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime.egg-info/dependency_links.txt +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.0}/wisruntime.egg-info/requires.txt +0 -0
- {wisruntime-0.4.2 → wisruntime-0.6.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.6.0
|
|
4
4
|
Summary: 企业级 Agent Runtime SDK — 让 AI 工程师专注 Agent 能力开发,无需关心底层基础设施
|
|
5
5
|
Author: WIS Team
|
|
6
6
|
License-Expression: MIT
|
|
@@ -352,6 +352,34 @@ interrupt() / interrupt_on InterruptEvent workflow_paus
|
|
|
352
352
|
|
|
353
353
|
**与 AgentRun 的差异**: AgentRun 使用 AK/SK + STS + RAM 签名三级体系,wisruntime 只使用 API-KEY,结构大幅简化。但 contextvars 注入模式完全复用。
|
|
354
354
|
|
|
355
|
+
#### WisHubClient — 统一配置入口
|
|
356
|
+
|
|
357
|
+
所有平台能力(MCP / Skill / Conversation / Memory)都指向同一个 WIS Hub 中台、使用同一种 Bearer 鉴权。`WisHubClient` 一次初始化持有 `hub_endpoint` / `api_key` / `timeout`,注入到需要的模块,无需重复配置:
|
|
358
|
+
|
|
359
|
+
```python
|
|
360
|
+
from wisruntime import WisHubClient
|
|
361
|
+
from wisruntime.adapters.langgraph import WishubMemoryMiddleware, create_mcp_tools
|
|
362
|
+
from wisruntime.conversation import ConversationClient
|
|
363
|
+
from wisruntime.skill import SkillClient
|
|
364
|
+
from wisruntime.tool import MCPClient
|
|
365
|
+
|
|
366
|
+
# 1️⃣ 一次初始化
|
|
367
|
+
client = WisHubClient(
|
|
368
|
+
hub_endpoint="https://aip-open-api-dev.infinitus.com.cn",
|
|
369
|
+
api_key="sk-xxx", # 也可省略,自动走 Config 三级获取
|
|
370
|
+
timeout=600, # 可选,默认 600 秒
|
|
371
|
+
)
|
|
372
|
+
|
|
373
|
+
# 2️⃣ 注入到各个模块
|
|
374
|
+
middleware = WishubMemoryMiddleware(client=client, top_k=5)
|
|
375
|
+
mcp_tools = await create_mcp_tools(client=client)
|
|
376
|
+
conv = ConversationClient(client=client)
|
|
377
|
+
skills = await SkillClient(client=client).list_skills()
|
|
378
|
+
mcp = MCPClient(client=client)
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
配置优先级(显式参数 > client > Config 三级获取):传入 `client` 后仍可用显式参数覆盖单个模块的配置。原有构造参数(`url` / `api_key` / `base_url`)全部保留可用。
|
|
382
|
+
|
|
355
383
|
### 4.2 Platform Client 层 (`tool/`)
|
|
356
384
|
|
|
357
385
|
**核心原则: 框架无关,只写一次。ToolClient 抽象协议 + MCP 实现。**
|
|
@@ -367,7 +395,9 @@ class ToolClient(ABC):
|
|
|
367
395
|
|
|
368
396
|
# MCP 协议实现 (薄封装标准 mcp 包)
|
|
369
397
|
class MCPClient(ToolClient):
|
|
370
|
-
def __init__(self, url=None, api_key=None, timeout=
|
|
398
|
+
def __init__(self, client=None, url=None, api_key=None, timeout=None):
|
|
399
|
+
# 统一 client 注入: 从 WisHubClient 推导 url/api_key/timeout
|
|
400
|
+
# 显式参数可覆盖; 无 client 时走 Config 三级获取
|
|
371
401
|
self._url = url or f"{Config().hub_endpoint}/wishub-mcp/mcp"
|
|
372
402
|
self._api_key = api_key or Config().api_key # 三级获取
|
|
373
403
|
|
|
@@ -394,22 +424,26 @@ class MCPClient(ToolClient):
|
|
|
394
424
|
**核心原则: 将 ToolClient 的 ToolInfo 转换为 LangChain StructuredTool。**
|
|
395
425
|
|
|
396
426
|
```python
|
|
427
|
+
from wisruntime import WisHubClient
|
|
397
428
|
from wisruntime.tool import MCPClient
|
|
398
429
|
from wisruntime.adapters.langgraph import create_mcp_tools, LangChainToolAdapter
|
|
399
430
|
from deepagents import create_deep_agent
|
|
400
431
|
|
|
432
|
+
# 0. 一次初始化统一 client
|
|
433
|
+
client = WisHubClient(hub_endpoint="https://...", api_key="sk-xxx")
|
|
434
|
+
|
|
401
435
|
# 方式 A: 一行获取 MCP 工具并创建 Agent(推荐)
|
|
402
|
-
tools = await create_mcp_tools()
|
|
436
|
+
tools = await create_mcp_tools(client=client)
|
|
403
437
|
agent = create_deep_agent(model=model, tools=tools)
|
|
404
438
|
|
|
405
439
|
# 方式 B: 手动控制 — 创建 client,桥接所有工具
|
|
406
|
-
|
|
407
|
-
tools = await LangChainToolAdapter.from_client(
|
|
440
|
+
mcp_client = MCPClient(client=client) # 也支持旧方式: MCPClient() 自动读 Config
|
|
441
|
+
tools = await LangChainToolAdapter.from_client(mcp_client)
|
|
408
442
|
agent = create_deep_agent(model=model, tools=tools)
|
|
409
443
|
|
|
410
444
|
# 方式 C: 过滤只接入部分工具
|
|
411
445
|
tools = await LangChainToolAdapter.from_client(
|
|
412
|
-
|
|
446
|
+
mcp_client, filter_fn=lambda t: "search" in t.name
|
|
413
447
|
)
|
|
414
448
|
|
|
415
449
|
# 方式 D: 单工具手动创建
|
|
@@ -713,6 +747,30 @@ def create_server(
|
|
|
713
747
|
└─────────────────────────────────────────────────────────────────────┘
|
|
714
748
|
|
|
715
749
|
故事 6 ──────────────────────────────────────────────────────────────
|
|
750
|
+
│ 用户故事: 作为 AI 工程师,我可以用 WishubMemoryMiddleware 为我的 │
|
|
751
|
+
│ DeepAgents Agent 添加长期记忆能力,自动检索用户历史对话记忆 │
|
|
752
|
+
│ │
|
|
753
|
+
│ 验收标准: │
|
|
754
|
+
│ from deepagents import create_deep_agent │
|
|
755
|
+
│ from wisruntime import WisHubClient │
|
|
756
|
+
│ from wisruntime.adapters.langgraph import WishubMemoryMiddleware │
|
|
757
|
+
│ │
|
|
758
|
+
│ client = WisHubClient( │
|
|
759
|
+
│ hub_endpoint="https://wishub.example.com", │
|
|
760
|
+
│ api_key="your-api-key" │
|
|
761
|
+
│ ) │
|
|
762
|
+
│ middleware = WishubMemoryMiddleware( │
|
|
763
|
+
│ client=client, │
|
|
764
|
+
│ namespaces=["user_profile", "preferences"], │
|
|
765
|
+
│ top_k=5 │
|
|
766
|
+
│ ) │
|
|
767
|
+
│ agent = create_deep_agent(model=model, middlewares=[middleware]) │
|
|
768
|
+
│ # → Agent 在每次对话前自动检索相关历史记忆 │
|
|
769
|
+
│ # → 记忆以结构化 XML 格式注入系统提示词 │
|
|
770
|
+
│ # → 支持优雅降级: API 超时/失败时返回空列表,不影响对话 │
|
|
771
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
772
|
+
|
|
773
|
+
故事 7 ──────────────────────────────────────────────────────────────
|
|
716
774
|
│ 用户故事: 作为 AI 工程师,我的 Agent 对话历史可以自动持久化到 │
|
|
717
775
|
│ WIS Hub Checkpoint 服务,支持断点续传 │
|
|
718
776
|
│ │
|
|
@@ -782,16 +840,36 @@ Phase 3: 平台能力接入 (MCP ✅ 已完成 — v0.3)
|
|
|
782
840
|
分页发现 / 详情 / 302 预签名下载 / 严格 SemVer 版本, create_skill_sources() deepagents 集成
|
|
783
841
|
□ SandboxClient + Sandbox 数据模型
|
|
784
842
|
|
|
843
|
+
Phase 3.5: 记忆能力接入 (✅ 已完成 — v0.4)
|
|
844
|
+
═══════════════════════════════
|
|
845
|
+
目标: 用户故事 6 — WishubMemoryMiddleware 长期记忆
|
|
846
|
+
|
|
847
|
+
✅ memory/ 模块: MemoryItem, RetrieveRequest, RetrieveResponse 数据模型
|
|
848
|
+
✅ WishubMemoryClient — 异步 HTTP 客户端,对接 Wishub Memory API
|
|
849
|
+
- 优雅降级: 超时/错误返回空列表,不影响对话
|
|
850
|
+
- 完整日志: debug/info/warning/error 四级
|
|
851
|
+
✅ MemoryPromptFormatter — 记忆列表 → 结构化 XML 提示词片段
|
|
852
|
+
- 支持相关度评分显示
|
|
853
|
+
- 空记忆占位符
|
|
854
|
+
- 可选使用指南
|
|
855
|
+
✅ WishubMemoryMiddleware — DeepAgents 中间件
|
|
856
|
+
- abefore_agent: 检索记忆并存入 state
|
|
857
|
+
- modify_request: 注入记忆到系统提示词
|
|
858
|
+
- 跳过重复检索
|
|
859
|
+
- user_id/query 缺失时优雅处理
|
|
860
|
+
✅ wrap_agent config 注入 — user_id, thread_id 传递到 LangGraph config.configurable
|
|
861
|
+
✅ 完整测试覆盖 (39 个测试用例全部通过)
|
|
862
|
+
|
|
785
863
|
Phase 4: 高级特性
|
|
786
864
|
════════════════
|
|
787
|
-
目标: 用户故事
|
|
865
|
+
目标: 用户故事 7 — Checkpoint、多协议
|
|
788
866
|
|
|
789
867
|
□ CheckpointClient + 自动持久化
|
|
790
868
|
□ AGUIHandler
|
|
791
869
|
□ Stop endpoint
|
|
792
870
|
□ ApiKeyMiddleware
|
|
793
871
|
|
|
794
|
-
Phase
|
|
872
|
+
Phase 5: 多框架 + 多协议
|
|
795
873
|
══════════════════════
|
|
796
874
|
目标: 验证可扩展性
|
|
797
875
|
|
|
@@ -817,12 +895,19 @@ wisruntime/
|
|
|
817
895
|
│ └── client.py # MCPClient(ToolClient) — 薄封装标准 mcp 包
|
|
818
896
|
│
|
|
819
897
|
├── 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
|
+
│ │
|
|
820
904
|
│ └── langgraph/ # LangGraph/LangChain/DeepAgents 框架 (✅ v0.3)
|
|
821
|
-
│ ├── __init__.py # 导出 LangGraphEventConverter, wrap_agent, LangChainToolAdapter, create_model, create_mcp_tools
|
|
905
|
+
│ ├── __init__.py # 导出 LangGraphEventConverter, wrap_agent, LangChainToolAdapter, create_model, create_mcp_tools, WishubMemoryMiddleware
|
|
822
906
|
│ ├── converter.py # LangGraphEventConverter (astream_events → CanonicalEvent)
|
|
823
|
-
│ ├── wrap_agent.py # wrap_agent() 糖函数
|
|
907
|
+
│ ├── wrap_agent.py # wrap_agent() 糖函数 (注入 config: user_id, thread_id)
|
|
824
908
|
│ ├── tool_adapter.py # LangChainToolAdapter (ToolInfo → StructuredTool)
|
|
825
|
-
│
|
|
909
|
+
│ ├── builtin.py # create_model() / create_mcp_tools() 一行接入
|
|
910
|
+
│ └── memory_middleware.py # WishubMemoryMiddleware — DeepAgents 记忆中间件
|
|
826
911
|
│
|
|
827
912
|
├── server/ # Server 层
|
|
828
913
|
│ ├── __init__.py
|
|
@@ -320,6 +320,34 @@ interrupt() / interrupt_on InterruptEvent workflow_paus
|
|
|
320
320
|
|
|
321
321
|
**与 AgentRun 的差异**: AgentRun 使用 AK/SK + STS + RAM 签名三级体系,wisruntime 只使用 API-KEY,结构大幅简化。但 contextvars 注入模式完全复用。
|
|
322
322
|
|
|
323
|
+
#### WisHubClient — 统一配置入口
|
|
324
|
+
|
|
325
|
+
所有平台能力(MCP / Skill / Conversation / Memory)都指向同一个 WIS Hub 中台、使用同一种 Bearer 鉴权。`WisHubClient` 一次初始化持有 `hub_endpoint` / `api_key` / `timeout`,注入到需要的模块,无需重复配置:
|
|
326
|
+
|
|
327
|
+
```python
|
|
328
|
+
from wisruntime import WisHubClient
|
|
329
|
+
from wisruntime.adapters.langgraph import WishubMemoryMiddleware, create_mcp_tools
|
|
330
|
+
from wisruntime.conversation import ConversationClient
|
|
331
|
+
from wisruntime.skill import SkillClient
|
|
332
|
+
from wisruntime.tool import MCPClient
|
|
333
|
+
|
|
334
|
+
# 1️⃣ 一次初始化
|
|
335
|
+
client = WisHubClient(
|
|
336
|
+
hub_endpoint="https://aip-open-api-dev.infinitus.com.cn",
|
|
337
|
+
api_key="sk-xxx", # 也可省略,自动走 Config 三级获取
|
|
338
|
+
timeout=600, # 可选,默认 600 秒
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
# 2️⃣ 注入到各个模块
|
|
342
|
+
middleware = WishubMemoryMiddleware(client=client, top_k=5)
|
|
343
|
+
mcp_tools = await create_mcp_tools(client=client)
|
|
344
|
+
conv = ConversationClient(client=client)
|
|
345
|
+
skills = await SkillClient(client=client).list_skills()
|
|
346
|
+
mcp = MCPClient(client=client)
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
配置优先级(显式参数 > client > Config 三级获取):传入 `client` 后仍可用显式参数覆盖单个模块的配置。原有构造参数(`url` / `api_key` / `base_url`)全部保留可用。
|
|
350
|
+
|
|
323
351
|
### 4.2 Platform Client 层 (`tool/`)
|
|
324
352
|
|
|
325
353
|
**核心原则: 框架无关,只写一次。ToolClient 抽象协议 + MCP 实现。**
|
|
@@ -335,7 +363,9 @@ class ToolClient(ABC):
|
|
|
335
363
|
|
|
336
364
|
# MCP 协议实现 (薄封装标准 mcp 包)
|
|
337
365
|
class MCPClient(ToolClient):
|
|
338
|
-
def __init__(self, url=None, api_key=None, timeout=
|
|
366
|
+
def __init__(self, client=None, url=None, api_key=None, timeout=None):
|
|
367
|
+
# 统一 client 注入: 从 WisHubClient 推导 url/api_key/timeout
|
|
368
|
+
# 显式参数可覆盖; 无 client 时走 Config 三级获取
|
|
339
369
|
self._url = url or f"{Config().hub_endpoint}/wishub-mcp/mcp"
|
|
340
370
|
self._api_key = api_key or Config().api_key # 三级获取
|
|
341
371
|
|
|
@@ -362,22 +392,26 @@ class MCPClient(ToolClient):
|
|
|
362
392
|
**核心原则: 将 ToolClient 的 ToolInfo 转换为 LangChain StructuredTool。**
|
|
363
393
|
|
|
364
394
|
```python
|
|
395
|
+
from wisruntime import WisHubClient
|
|
365
396
|
from wisruntime.tool import MCPClient
|
|
366
397
|
from wisruntime.adapters.langgraph import create_mcp_tools, LangChainToolAdapter
|
|
367
398
|
from deepagents import create_deep_agent
|
|
368
399
|
|
|
400
|
+
# 0. 一次初始化统一 client
|
|
401
|
+
client = WisHubClient(hub_endpoint="https://...", api_key="sk-xxx")
|
|
402
|
+
|
|
369
403
|
# 方式 A: 一行获取 MCP 工具并创建 Agent(推荐)
|
|
370
|
-
tools = await create_mcp_tools()
|
|
404
|
+
tools = await create_mcp_tools(client=client)
|
|
371
405
|
agent = create_deep_agent(model=model, tools=tools)
|
|
372
406
|
|
|
373
407
|
# 方式 B: 手动控制 — 创建 client,桥接所有工具
|
|
374
|
-
|
|
375
|
-
tools = await LangChainToolAdapter.from_client(
|
|
408
|
+
mcp_client = MCPClient(client=client) # 也支持旧方式: MCPClient() 自动读 Config
|
|
409
|
+
tools = await LangChainToolAdapter.from_client(mcp_client)
|
|
376
410
|
agent = create_deep_agent(model=model, tools=tools)
|
|
377
411
|
|
|
378
412
|
# 方式 C: 过滤只接入部分工具
|
|
379
413
|
tools = await LangChainToolAdapter.from_client(
|
|
380
|
-
|
|
414
|
+
mcp_client, filter_fn=lambda t: "search" in t.name
|
|
381
415
|
)
|
|
382
416
|
|
|
383
417
|
# 方式 D: 单工具手动创建
|
|
@@ -681,6 +715,30 @@ def create_server(
|
|
|
681
715
|
└─────────────────────────────────────────────────────────────────────┘
|
|
682
716
|
|
|
683
717
|
故事 6 ──────────────────────────────────────────────────────────────
|
|
718
|
+
│ 用户故事: 作为 AI 工程师,我可以用 WishubMemoryMiddleware 为我的 │
|
|
719
|
+
│ DeepAgents Agent 添加长期记忆能力,自动检索用户历史对话记忆 │
|
|
720
|
+
│ │
|
|
721
|
+
│ 验收标准: │
|
|
722
|
+
│ from deepagents import create_deep_agent │
|
|
723
|
+
│ from wisruntime import WisHubClient │
|
|
724
|
+
│ from wisruntime.adapters.langgraph import WishubMemoryMiddleware │
|
|
725
|
+
│ │
|
|
726
|
+
│ client = WisHubClient( │
|
|
727
|
+
│ hub_endpoint="https://wishub.example.com", │
|
|
728
|
+
│ api_key="your-api-key" │
|
|
729
|
+
│ ) │
|
|
730
|
+
│ middleware = WishubMemoryMiddleware( │
|
|
731
|
+
│ client=client, │
|
|
732
|
+
│ namespaces=["user_profile", "preferences"], │
|
|
733
|
+
│ top_k=5 │
|
|
734
|
+
│ ) │
|
|
735
|
+
│ agent = create_deep_agent(model=model, middlewares=[middleware]) │
|
|
736
|
+
│ # → Agent 在每次对话前自动检索相关历史记忆 │
|
|
737
|
+
│ # → 记忆以结构化 XML 格式注入系统提示词 │
|
|
738
|
+
│ # → 支持优雅降级: API 超时/失败时返回空列表,不影响对话 │
|
|
739
|
+
└─────────────────────────────────────────────────────────────────────┘
|
|
740
|
+
|
|
741
|
+
故事 7 ──────────────────────────────────────────────────────────────
|
|
684
742
|
│ 用户故事: 作为 AI 工程师,我的 Agent 对话历史可以自动持久化到 │
|
|
685
743
|
│ WIS Hub Checkpoint 服务,支持断点续传 │
|
|
686
744
|
│ │
|
|
@@ -750,16 +808,36 @@ Phase 3: 平台能力接入 (MCP ✅ 已完成 — v0.3)
|
|
|
750
808
|
分页发现 / 详情 / 302 预签名下载 / 严格 SemVer 版本, create_skill_sources() deepagents 集成
|
|
751
809
|
□ SandboxClient + Sandbox 数据模型
|
|
752
810
|
|
|
811
|
+
Phase 3.5: 记忆能力接入 (✅ 已完成 — v0.4)
|
|
812
|
+
═══════════════════════════════
|
|
813
|
+
目标: 用户故事 6 — WishubMemoryMiddleware 长期记忆
|
|
814
|
+
|
|
815
|
+
✅ memory/ 模块: MemoryItem, RetrieveRequest, RetrieveResponse 数据模型
|
|
816
|
+
✅ WishubMemoryClient — 异步 HTTP 客户端,对接 Wishub Memory API
|
|
817
|
+
- 优雅降级: 超时/错误返回空列表,不影响对话
|
|
818
|
+
- 完整日志: debug/info/warning/error 四级
|
|
819
|
+
✅ MemoryPromptFormatter — 记忆列表 → 结构化 XML 提示词片段
|
|
820
|
+
- 支持相关度评分显示
|
|
821
|
+
- 空记忆占位符
|
|
822
|
+
- 可选使用指南
|
|
823
|
+
✅ WishubMemoryMiddleware — DeepAgents 中间件
|
|
824
|
+
- abefore_agent: 检索记忆并存入 state
|
|
825
|
+
- modify_request: 注入记忆到系统提示词
|
|
826
|
+
- 跳过重复检索
|
|
827
|
+
- user_id/query 缺失时优雅处理
|
|
828
|
+
✅ wrap_agent config 注入 — user_id, thread_id 传递到 LangGraph config.configurable
|
|
829
|
+
✅ 完整测试覆盖 (39 个测试用例全部通过)
|
|
830
|
+
|
|
753
831
|
Phase 4: 高级特性
|
|
754
832
|
════════════════
|
|
755
|
-
目标: 用户故事
|
|
833
|
+
目标: 用户故事 7 — Checkpoint、多协议
|
|
756
834
|
|
|
757
835
|
□ CheckpointClient + 自动持久化
|
|
758
836
|
□ AGUIHandler
|
|
759
837
|
□ Stop endpoint
|
|
760
838
|
□ ApiKeyMiddleware
|
|
761
839
|
|
|
762
|
-
Phase
|
|
840
|
+
Phase 5: 多框架 + 多协议
|
|
763
841
|
══════════════════════
|
|
764
842
|
目标: 验证可扩展性
|
|
765
843
|
|
|
@@ -785,12 +863,19 @@ wisruntime/
|
|
|
785
863
|
│ └── client.py # MCPClient(ToolClient) — 薄封装标准 mcp 包
|
|
786
864
|
│
|
|
787
865
|
├── 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
|
+
│ │
|
|
788
872
|
│ └── langgraph/ # LangGraph/LangChain/DeepAgents 框架 (✅ v0.3)
|
|
789
|
-
│ ├── __init__.py # 导出 LangGraphEventConverter, wrap_agent, LangChainToolAdapter, create_model, create_mcp_tools
|
|
873
|
+
│ ├── __init__.py # 导出 LangGraphEventConverter, wrap_agent, LangChainToolAdapter, create_model, create_mcp_tools, WishubMemoryMiddleware
|
|
790
874
|
│ ├── converter.py # LangGraphEventConverter (astream_events → CanonicalEvent)
|
|
791
|
-
│ ├── wrap_agent.py # wrap_agent() 糖函数
|
|
875
|
+
│ ├── wrap_agent.py # wrap_agent() 糖函数 (注入 config: user_id, thread_id)
|
|
792
876
|
│ ├── tool_adapter.py # LangChainToolAdapter (ToolInfo → StructuredTool)
|
|
793
|
-
│
|
|
877
|
+
│ ├── builtin.py # create_model() / create_mcp_tools() 一行接入
|
|
878
|
+
│ └── memory_middleware.py # WishubMemoryMiddleware — DeepAgents 记忆中间件
|
|
794
879
|
│
|
|
795
880
|
├── server/ # Server 层
|
|
796
881
|
│ ├── __init__.py
|
|
@@ -20,6 +20,7 @@ Quick Start:
|
|
|
20
20
|
# → 首轮自动建会话、conversation_id 透传到流式事件、每轮自动落库
|
|
21
21
|
"""
|
|
22
22
|
|
|
23
|
+
from wisruntime.client import WisHubClient
|
|
23
24
|
from wisruntime.config import Config, CredentialContext
|
|
24
25
|
from wisruntime.exceptions import ConfigError, InvokerError, ProtocolError, WisRuntimeError
|
|
25
26
|
from wisruntime.model import (
|
|
@@ -123,6 +124,7 @@ __all__ = [
|
|
|
123
124
|
"wrap_agent",
|
|
124
125
|
"Config",
|
|
125
126
|
"CredentialContext",
|
|
127
|
+
"WisHubClient",
|
|
126
128
|
"AgentRequest",
|
|
127
129
|
"Message",
|
|
128
130
|
"TextDeltaEvent",
|
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
- (未来) llamaindex/ — LlamaIndex 框架适配
|
|
6
6
|
- (未来) crewai/ — CrewAI 框架适配
|
|
7
7
|
|
|
8
|
+
注意:记忆能力(记忆检索客户端与提示词格式化)是框架无关的平台能力,
|
|
9
|
+
不在 adapters/ 下——请从 wisruntime.memory 导入;LangGraph 适配层也
|
|
10
|
+
从 wisruntime.adapters.langgraph 转发导出这些符号。
|
|
11
|
+
|
|
8
12
|
每个子目录包含:
|
|
9
13
|
- converter.py — 框架事件 → CanonicalEvent 转换器
|
|
10
14
|
- wrap_agent.py — 框架 Agent 对象的封装糖函数
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
|
|
16
|
+
from wisruntime.adapters.langgraph.builtin import create_mcp_tools, create_model
|
|
17
|
+
from wisruntime.adapters.langgraph.converter import LangGraphEventConverter
|
|
18
|
+
from wisruntime.adapters.langgraph.memory_middleware import (
|
|
19
|
+
WishubMemoryMiddleware,
|
|
20
|
+
WishubMemoryState,
|
|
21
|
+
WishubMemoryStateUpdate,
|
|
22
|
+
)
|
|
23
|
+
from wisruntime.adapters.langgraph.tool_adapter import LangChainToolAdapter
|
|
24
|
+
from wisruntime.adapters.langgraph.wrap_agent import wrap_agent
|
|
25
|
+
|
|
26
|
+
# wisruntime.memory 的转发导出(框架无关,权威定义见 wisruntime.memory)
|
|
27
|
+
from wisruntime.memory import (
|
|
28
|
+
WishubMemoryClient,
|
|
29
|
+
MemoryPromptFormatter,
|
|
30
|
+
MemoryItem,
|
|
31
|
+
RetrieveRequest,
|
|
32
|
+
RetrieveResponse,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
__all__ = [
|
|
36
|
+
"LangGraphEventConverter",
|
|
37
|
+
"wrap_agent",
|
|
38
|
+
"LangChainToolAdapter",
|
|
39
|
+
"create_model",
|
|
40
|
+
"create_mcp_tools",
|
|
41
|
+
"WishubMemoryMiddleware",
|
|
42
|
+
"WishubMemoryState",
|
|
43
|
+
"WishubMemoryStateUpdate",
|
|
44
|
+
"WishubMemoryClient",
|
|
45
|
+
"MemoryPromptFormatter",
|
|
46
|
+
"MemoryItem",
|
|
47
|
+
"RetrieveRequest",
|
|
48
|
+
"RetrieveResponse",
|
|
49
|
+
]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Utility functions for LangGraph middleware."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from langchain_core.messages import SystemMessage
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def append_to_system_message(
|
|
9
|
+
system_message: Optional[SystemMessage], content: str
|
|
10
|
+
) -> SystemMessage:
|
|
11
|
+
"""Append content to an existing system message or create a new one.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
system_message: Existing system message or None
|
|
15
|
+
content: Content to append
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
SystemMessage with appended content
|
|
19
|
+
"""
|
|
20
|
+
if system_message is None:
|
|
21
|
+
return SystemMessage(content=content)
|
|
22
|
+
|
|
23
|
+
# Get existing content
|
|
24
|
+
existing_content = system_message.content
|
|
25
|
+
if isinstance(existing_content, str):
|
|
26
|
+
new_content = existing_content + "\n\n" + content
|
|
27
|
+
elif isinstance(existing_content, list):
|
|
28
|
+
# Handle list of content blocks
|
|
29
|
+
new_content = existing_content + [{"type": "text", "text": content}]
|
|
30
|
+
else:
|
|
31
|
+
new_content = str(existing_content) + "\n\n" + content
|
|
32
|
+
|
|
33
|
+
# Create new message with combined content
|
|
34
|
+
return SystemMessage(content=new_content)
|
|
@@ -3,16 +3,19 @@
|
|
|
3
3
|
提供快速创建 LangChain 兼容模型和工具的便捷函数。
|
|
4
4
|
|
|
5
5
|
使用示例:
|
|
6
|
+
>>> from wisruntime import WisHubClient
|
|
6
7
|
>>> from wisruntime.adapters.langgraph.builtin import create_model, create_mcp_tools
|
|
7
8
|
>>> from deepagents import create_deep_agent
|
|
8
9
|
>>>
|
|
9
10
|
>>> model = create_model()
|
|
10
|
-
>>>
|
|
11
|
+
>>> client = WisHubClient(hub_endpoint="https://...", api_key="sk-...")
|
|
12
|
+
>>> tools = await create_mcp_tools(client=client)
|
|
11
13
|
>>> agent = create_deep_agent(model=model, tools=tools)
|
|
12
14
|
"""
|
|
13
15
|
|
|
14
16
|
import os
|
|
15
17
|
|
|
18
|
+
from wisruntime.client import WisHubClient
|
|
16
19
|
from wisruntime.tool.client import MCPClient
|
|
17
20
|
from wisruntime.adapters.langgraph.tool_adapter import LangChainToolAdapter
|
|
18
21
|
|
|
@@ -69,6 +72,7 @@ def create_model(provider: str = "deepseek", model: str | None = None, **kwargs)
|
|
|
69
72
|
|
|
70
73
|
|
|
71
74
|
async def create_mcp_tools(
|
|
75
|
+
client: WisHubClient | None = None,
|
|
72
76
|
url: str | None = None,
|
|
73
77
|
api_key: str | None = None,
|
|
74
78
|
filter_fn=None,
|
|
@@ -78,22 +82,26 @@ async def create_mcp_tools(
|
|
|
78
82
|
内部: MCPClient → LangChainToolAdapter.from_client()
|
|
79
83
|
|
|
80
84
|
Args:
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
client: WisHubClient 统一配置容器(推荐)。传入时
|
|
86
|
+
url/api_key/timeout 从中推导;显式参数可覆盖。
|
|
87
|
+
url: MCP Server URL。None 时从 client 或 Config 推导。
|
|
88
|
+
api_key: API Key。None 时从 client 或 Config 三级获取。
|
|
83
89
|
filter_fn: 可选过滤函数。
|
|
84
90
|
|
|
85
91
|
Returns:
|
|
86
92
|
LangChainToolAdapter 列表(兼容 StructuredTool)。
|
|
87
93
|
|
|
88
94
|
Example:
|
|
95
|
+
>>> from wisruntime import WisHubClient
|
|
89
96
|
>>> from deepagents import create_deep_agent
|
|
90
|
-
>>>
|
|
97
|
+
>>> client = WisHubClient(hub_endpoint="https://...", api_key="sk-...")
|
|
98
|
+
>>> tools = await create_mcp_tools(client=client)
|
|
91
99
|
>>> agent = create_deep_agent(model=model, tools=tools)
|
|
92
100
|
"""
|
|
93
|
-
|
|
101
|
+
mcp_client = MCPClient(client=client, url=url, api_key=api_key)
|
|
94
102
|
# No explicit close() needed — MCPClient is stateless, each call_tool()
|
|
95
103
|
# invocation creates and destroys its own session independently.
|
|
96
|
-
return await LangChainToolAdapter.from_client(
|
|
104
|
+
return await LangChainToolAdapter.from_client(mcp_client, filter_fn=filter_fn)
|
|
97
105
|
|
|
98
106
|
|
|
99
107
|
async def create_skill_sources(
|