wisruntime 0.5.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.
Files changed (51) hide show
  1. {wisruntime-0.5.0/wisruntime.egg-info → wisruntime-0.7.0}/PKG-INFO +114 -26
  2. {wisruntime-0.5.0 → wisruntime-0.7.0}/README.md +113 -25
  3. {wisruntime-0.5.0 → wisruntime-0.7.0}/pyproject.toml +1 -1
  4. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/__init__.py +60 -22
  5. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/adapters/__init__.py +4 -1
  6. wisruntime-0.7.0/wisruntime/adapters/langgraph/__init__.py +70 -0
  7. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/adapters/langgraph/builtin.py +46 -9
  8. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/adapters/langgraph/converter.py +91 -1
  9. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/adapters/langgraph/memory_middleware.py +19 -7
  10. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/adapters/langgraph/wrap_agent.py +30 -6
  11. wisruntime-0.7.0/wisruntime/agent_stream.py +144 -0
  12. wisruntime-0.7.0/wisruntime/client.py +73 -0
  13. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/config.py +19 -8
  14. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/conversation/__init__.py +8 -1
  15. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/conversation/client.py +152 -26
  16. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/conversation/model.py +121 -4
  17. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/conversation/recorder.py +18 -5
  18. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/exceptions.py +18 -0
  19. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/memory/client.py +23 -5
  20. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/model.py +9 -0
  21. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/server/dify_handler.py +23 -148
  22. wisruntime-0.7.0/wisruntime/server/formatter.py +251 -0
  23. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/server/invoker.py +32 -3
  24. wisruntime-0.7.0/wisruntime/server/protocol.py +178 -0
  25. wisruntime-0.7.0/wisruntime/server/server.py +349 -0
  26. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/skill/client.py +221 -22
  27. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/tool/__init__.py +6 -1
  28. wisruntime-0.7.0/wisruntime/tool/client.py +536 -0
  29. wisruntime-0.7.0/wisruntime/tool/model.py +158 -0
  30. {wisruntime-0.5.0 → wisruntime-0.7.0/wisruntime.egg-info}/PKG-INFO +114 -26
  31. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime.egg-info/SOURCES.txt +3 -1
  32. wisruntime-0.5.0/wisruntime/adapters/langgraph/__init__.py +0 -31
  33. wisruntime-0.5.0/wisruntime/adapters/memory/__init__.py +0 -35
  34. wisruntime-0.5.0/wisruntime/server/protocol.py +0 -104
  35. wisruntime-0.5.0/wisruntime/server/server.py +0 -195
  36. wisruntime-0.5.0/wisruntime/tool/client.py +0 -276
  37. wisruntime-0.5.0/wisruntime/tool/model.py +0 -84
  38. {wisruntime-0.5.0 → wisruntime-0.7.0}/MANIFEST.in +0 -0
  39. {wisruntime-0.5.0 → wisruntime-0.7.0}/setup.cfg +0 -0
  40. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/adapters/langgraph/_utils.py +0 -0
  41. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/adapters/langgraph/tool_adapter.py +0 -0
  42. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/memory/__init__.py +0 -0
  43. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/memory/formatter.py +0 -0
  44. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/memory/model.py +0 -0
  45. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/server/__init__.py +0 -0
  46. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/skill/__init__.py +0 -0
  47. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/skill/model.py +0 -0
  48. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime/tool/protocol.py +0 -0
  49. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime.egg-info/dependency_links.txt +0 -0
  50. {wisruntime-0.5.0 → wisruntime-0.7.0}/wisruntime.egg-info/requires.txt +0 -0
  51. {wisruntime-0.5.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.5.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.1.1 (Adapter Layer) | **日期**: 2026-07 | **团队**: WIS Team
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
 
@@ -352,6 +354,34 @@ interrupt() / interrupt_on InterruptEvent workflow_paus
352
354
 
353
355
  **与 AgentRun 的差异**: AgentRun 使用 AK/SK + STS + RAM 签名三级体系,wisruntime 只使用 API-KEY,结构大幅简化。但 contextvars 注入模式完全复用。
354
356
 
357
+ #### WisHubClient — 统一配置入口
358
+
359
+ 所有平台能力(MCP / Skill / Conversation / Memory)都指向同一个 WIS Hub 中台、使用同一种 Bearer 鉴权。`WisHubClient` 一次初始化持有 `hub_endpoint` / `api_key` / `timeout`,注入到需要的模块,无需重复配置:
360
+
361
+ ```python
362
+ from wisruntime import WisHubClient
363
+ from wisruntime.adapters.langgraph import WishubMemoryMiddleware, create_mcp_tools
364
+ from wisruntime.conversation import ConversationClient
365
+ from wisruntime.skill import SkillClient
366
+ from wisruntime.tool import MCPClient
367
+
368
+ # 1️⃣ 一次初始化
369
+ client = WisHubClient(
370
+ hub_endpoint="https://aip-open-api-dev.infinitus.com.cn",
371
+ api_key="sk-xxx", # 也可省略,自动走 Config 三级获取
372
+ timeout=600, # 可选,默认 600 秒
373
+ )
374
+
375
+ # 2️⃣ 注入到各个模块
376
+ middleware = WishubMemoryMiddleware(client=client, top_k=5)
377
+ mcp_tools = await create_mcp_tools(client=client)
378
+ conv = ConversationClient(client=client)
379
+ skills = await SkillClient(client=client).list_skills()
380
+ mcp = MCPClient(client=client)
381
+ ```
382
+
383
+ 配置优先级(显式参数 > client > Config 三级获取):传入 `client` 后仍可用显式参数覆盖单个模块的配置。原有构造参数(`url` / `api_key` / `base_url`)全部保留可用。
384
+
355
385
  ### 4.2 Platform Client 层 (`tool/`)
356
386
 
357
387
  **核心原则: 框架无关,只写一次。ToolClient 抽象协议 + MCP 实现。**
@@ -367,7 +397,20 @@ class ToolClient(ABC):
367
397
 
368
398
  # MCP 协议实现 (薄封装标准 mcp 包)
369
399
  class MCPClient(ToolClient):
370
- def __init__(self, url=None, api_key=None, timeout=600):
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):
412
+ # 统一 client 注入: 从 WisHubClient 推导 url/api_key/timeout
413
+ # 显式参数可覆盖; 无 client 时走 Config 三级获取
371
414
  self._url = url or f"{Config().hub_endpoint}/wishub-mcp/mcp"
372
415
  self._api_key = api_key or Config().api_key # 三级获取
373
416
 
@@ -381,6 +424,22 @@ class MCPClient(ToolClient):
381
424
  ...
382
425
  ```
383
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
+
384
443
  各 Client 职责:
385
444
 
386
445
  | Client | 职责 | 端点示例 |
@@ -394,22 +453,26 @@ class MCPClient(ToolClient):
394
453
  **核心原则: 将 ToolClient 的 ToolInfo 转换为 LangChain StructuredTool。**
395
454
 
396
455
  ```python
456
+ from wisruntime import WisHubClient
397
457
  from wisruntime.tool import MCPClient
398
458
  from wisruntime.adapters.langgraph import create_mcp_tools, LangChainToolAdapter
399
459
  from deepagents import create_deep_agent
400
460
 
461
+ # 0. 一次初始化统一 client
462
+ client = WisHubClient(hub_endpoint="https://...", api_key="sk-xxx")
463
+
401
464
  # 方式 A: 一行获取 MCP 工具并创建 Agent(推荐)
402
- tools = await create_mcp_tools() # 自动读取 WIS_HUB_API_KEY
465
+ tools = await create_mcp_tools(client=client)
403
466
  agent = create_deep_agent(model=model, tools=tools)
404
467
 
405
468
  # 方式 B: 手动控制 — 创建 client,桥接所有工具
406
- client = MCPClient()
407
- tools = await LangChainToolAdapter.from_client(client)
469
+ mcp_client = MCPClient(client=client) # 也支持旧方式: MCPClient() 自动读 Config
470
+ tools = await LangChainToolAdapter.from_client(mcp_client)
408
471
  agent = create_deep_agent(model=model, tools=tools)
409
472
 
410
473
  # 方式 C: 过滤只接入部分工具
411
474
  tools = await LangChainToolAdapter.from_client(
412
- client, filter_fn=lambda t: "search" in t.name
475
+ mcp_client, filter_fn=lambda t: "search" in t.name
413
476
  )
414
477
 
415
478
  # 方式 D: 单工具手动创建
@@ -431,7 +494,7 @@ agent = create_deep_agent(model=model, tools=tools, skills=skill_paths)
431
494
 
432
495
  Skill 客户端完整用法(发现/详情/批量下载)见 [docs/wishub-skill-api.md](docs/wishub-skill-api.md)。
433
496
 
434
- **核心能力**: `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()` 关闭自建池且幂等。
435
498
 
436
499
  ### 4.4 Adapter 层
437
500
 
@@ -718,15 +781,15 @@ def create_server(
718
781
  │ │
719
782
  │ 验收标准: │
720
783
  │ from deepagents import create_deep_agent │
784
+ │ from wisruntime import WisHubClient │
721
785
  │ from wisruntime.adapters.langgraph import WishubMemoryMiddleware │
722
- │ from wisruntime.memory import WishubMemoryClient │
723
786
  │ │
724
- │ memory_client = WishubMemoryClient( │
725
- │ base_url="https://wishub.example.com", │
787
+ │ client = WisHubClient( │
788
+ │ hub_endpoint="https://wishub.example.com", │
726
789
  │ api_key="your-api-key" │
727
790
  │ ) │
728
791
  │ middleware = WishubMemoryMiddleware( │
729
- │ client=memory_client, │
792
+ │ client=client, │
730
793
  │ namespaces=["user_profile", "preferences"], │
731
794
  │ top_k=5 │
732
795
  │ ) │
@@ -826,6 +889,21 @@ Phase 3.5: 记忆能力接入 (✅ 已完成 — v0.4)
826
889
  ✅ wrap_agent config 注入 — user_id, thread_id 传递到 LangGraph config.configurable
827
890
  ✅ 完整测试覆盖 (39 个测试用例全部通过)
828
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
+
829
907
  Phase 4: 高级特性
830
908
  ════════════════
831
909
  目标: 用户故事 7 — Checkpoint、多协议
@@ -841,15 +919,16 @@ Phase 5: 多框架 + 多协议
841
919
 
842
920
  □ AgentScope Adapter
843
921
  □ AGUI Handler
844
- □ 内部 PyPI 发布
922
+ ✅ 官方 PyPI 发布 (v0.6.0 — pypi.org/project/wisruntime)
845
923
  □ 性能基准测试
846
924
  ```
847
925
 
848
- ### 5.3 目录结构 (目标态)
926
+ ### 5.3 目录结构 (v0.6)
849
927
 
850
928
  ```
851
929
  wisruntime/
852
930
  ├── __init__.py # 顶层导出: create_server, Config, ToolInfo, ToolResult
931
+ ├── client.py # WisHubClient — 统一配置容器 (hub_endpoint/api_key/timeout)
853
932
  ├── config.py # Config, CredentialContext
854
933
  ├── model.py # CanonicalEvent (13 种), AgentRequest, Message
855
934
  ├── exceptions.py # 自定义异常
@@ -860,15 +939,29 @@ wisruntime/
860
939
  │ ├── protocol.py # ToolClient (ABC) — 抽象协议
861
940
  │ └── client.py # MCPClient(ToolClient) — 薄封装标准 mcp 包
862
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
+ │
863
960
  ├── adapters/ # Adapter + Capability Bridge
864
- │ ├── memory/ # Memory 记忆检索适配器 (✅ v0.4)
865
- │ │ ├── __init__.py # 导出 WishubMemoryClient, MemoryPromptFormatter, MemoryItem
866
- │ │ ├── model.py # MemoryItem, RetrieveRequest, RetrieveResponse (Pydantic 模型)
867
- │ │ ├── client.py # WishubMemoryClient — 异步 HTTP 客户端,优雅降级
868
- │ │ └── formatter.py # MemoryPromptFormatter — 记忆列表 → XML 提示词片段
869
- │ │
870
961
  │ └── langgraph/ # LangGraph/LangChain/DeepAgents 框架 (✅ v0.3)
871
- │ ├── __init__.py # 导出 LangGraphEventConverter, wrap_agent, LangChainToolAdapter, create_model, create_mcp_tools, WishubMemoryMiddleware
962
+ │ ├── __init__.py # 导出 LangGraphEventConverter, wrap_agent, LangChainToolAdapter,
963
+ │ │ # create_model, create_mcp_tools, WishubMemoryMiddleware
964
+ │ │ # (v0.6 起转发导出 wisruntime.memory 的 5 个记忆符号)
872
965
  │ ├── converter.py # LangGraphEventConverter (astream_events → CanonicalEvent)
873
966
  │ ├── wrap_agent.py # wrap_agent() 糖函数 (注入 config: user_id, thread_id)
874
967
  │ ├── tool_adapter.py # LangChainToolAdapter (ToolInfo → StructuredTool)
@@ -882,11 +975,6 @@ wisruntime/
882
975
  │ ├── dify_handler.py # DifyHandler (SSE + Blocking)
883
976
  │ └── protocol.py # ProtocolHandler 抽象基类
884
977
  │
885
- ├── skill/ # Skill 知识包接入层 (✅ v0.3.x — wishub-skill openapi/v1)
886
- │ ├── __init__.py # exports: SkillClient, SkillInfo, SkillDetailInfo, SkillPage
887
- │ ├── model.py # SkillInfo / SkillDetailInfo / SkillPage(信封分页模型)
888
- │ └── client.py # SkillClient — 分页发现 / 详情 / 302 预签名下载
889
- │
890
978
  └── (未来: sandbox/, checkpoint/) # 远程工具接入走 ToolClient 协议,不同实现
891
979
  ```
892
980
 
@@ -1,6 +1,8 @@
1
1
  # wisruntime — 企业级 Agent Runtime SDK
2
2
 
3
- > **版本**: v0.1.1 (Adapter Layer) | **日期**: 2026-07 | **团队**: WIS Team
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
 
@@ -320,6 +322,34 @@ interrupt() / interrupt_on InterruptEvent workflow_paus
320
322
 
321
323
  **与 AgentRun 的差异**: AgentRun 使用 AK/SK + STS + RAM 签名三级体系,wisruntime 只使用 API-KEY,结构大幅简化。但 contextvars 注入模式完全复用。
322
324
 
325
+ #### WisHubClient — 统一配置入口
326
+
327
+ 所有平台能力(MCP / Skill / Conversation / Memory)都指向同一个 WIS Hub 中台、使用同一种 Bearer 鉴权。`WisHubClient` 一次初始化持有 `hub_endpoint` / `api_key` / `timeout`,注入到需要的模块,无需重复配置:
328
+
329
+ ```python
330
+ from wisruntime import WisHubClient
331
+ from wisruntime.adapters.langgraph import WishubMemoryMiddleware, create_mcp_tools
332
+ from wisruntime.conversation import ConversationClient
333
+ from wisruntime.skill import SkillClient
334
+ from wisruntime.tool import MCPClient
335
+
336
+ # 1️⃣ 一次初始化
337
+ client = WisHubClient(
338
+ hub_endpoint="https://aip-open-api-dev.infinitus.com.cn",
339
+ api_key="sk-xxx", # 也可省略,自动走 Config 三级获取
340
+ timeout=600, # 可选,默认 600 秒
341
+ )
342
+
343
+ # 2️⃣ 注入到各个模块
344
+ middleware = WishubMemoryMiddleware(client=client, top_k=5)
345
+ mcp_tools = await create_mcp_tools(client=client)
346
+ conv = ConversationClient(client=client)
347
+ skills = await SkillClient(client=client).list_skills()
348
+ mcp = MCPClient(client=client)
349
+ ```
350
+
351
+ 配置优先级(显式参数 > client > Config 三级获取):传入 `client` 后仍可用显式参数覆盖单个模块的配置。原有构造参数(`url` / `api_key` / `base_url`)全部保留可用。
352
+
323
353
  ### 4.2 Platform Client 层 (`tool/`)
324
354
 
325
355
  **核心原则: 框架无关,只写一次。ToolClient 抽象协议 + MCP 实现。**
@@ -335,7 +365,20 @@ class ToolClient(ABC):
335
365
 
336
366
  # MCP 协议实现 (薄封装标准 mcp 包)
337
367
  class MCPClient(ToolClient):
338
- def __init__(self, url=None, api_key=None, timeout=600):
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):
380
+ # 统一 client 注入: 从 WisHubClient 推导 url/api_key/timeout
381
+ # 显式参数可覆盖; 无 client 时走 Config 三级获取
339
382
  self._url = url or f"{Config().hub_endpoint}/wishub-mcp/mcp"
340
383
  self._api_key = api_key or Config().api_key # 三级获取
341
384
 
@@ -349,6 +392,22 @@ class MCPClient(ToolClient):
349
392
  ...
350
393
  ```
351
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
+
352
411
  各 Client 职责:
353
412
 
354
413
  | Client | 职责 | 端点示例 |
@@ -362,22 +421,26 @@ class MCPClient(ToolClient):
362
421
  **核心原则: 将 ToolClient 的 ToolInfo 转换为 LangChain StructuredTool。**
363
422
 
364
423
  ```python
424
+ from wisruntime import WisHubClient
365
425
  from wisruntime.tool import MCPClient
366
426
  from wisruntime.adapters.langgraph import create_mcp_tools, LangChainToolAdapter
367
427
  from deepagents import create_deep_agent
368
428
 
429
+ # 0. 一次初始化统一 client
430
+ client = WisHubClient(hub_endpoint="https://...", api_key="sk-xxx")
431
+
369
432
  # 方式 A: 一行获取 MCP 工具并创建 Agent(推荐)
370
- tools = await create_mcp_tools() # 自动读取 WIS_HUB_API_KEY
433
+ tools = await create_mcp_tools(client=client)
371
434
  agent = create_deep_agent(model=model, tools=tools)
372
435
 
373
436
  # 方式 B: 手动控制 — 创建 client,桥接所有工具
374
- client = MCPClient()
375
- tools = await LangChainToolAdapter.from_client(client)
437
+ mcp_client = MCPClient(client=client) # 也支持旧方式: MCPClient() 自动读 Config
438
+ tools = await LangChainToolAdapter.from_client(mcp_client)
376
439
  agent = create_deep_agent(model=model, tools=tools)
377
440
 
378
441
  # 方式 C: 过滤只接入部分工具
379
442
  tools = await LangChainToolAdapter.from_client(
380
- client, filter_fn=lambda t: "search" in t.name
443
+ mcp_client, filter_fn=lambda t: "search" in t.name
381
444
  )
382
445
 
383
446
  # 方式 D: 单工具手动创建
@@ -399,7 +462,7 @@ agent = create_deep_agent(model=model, tools=tools, skills=skill_paths)
399
462
 
400
463
  Skill 客户端完整用法(发现/详情/批量下载)见 [docs/wishub-skill-api.md](docs/wishub-skill-api.md)。
401
464
 
402
- **核心能力**: `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()` 关闭自建池且幂等。
403
466
 
404
467
  ### 4.4 Adapter 层
405
468
 
@@ -686,15 +749,15 @@ def create_server(
686
749
  │ │
687
750
  │ 验收标准: │
688
751
  │ from deepagents import create_deep_agent │
752
+ │ from wisruntime import WisHubClient │
689
753
  │ from wisruntime.adapters.langgraph import WishubMemoryMiddleware │
690
- │ from wisruntime.memory import WishubMemoryClient │
691
754
  │ │
692
- │ memory_client = WishubMemoryClient( │
693
- │ base_url="https://wishub.example.com", │
755
+ │ client = WisHubClient( │
756
+ │ hub_endpoint="https://wishub.example.com", │
694
757
  │ api_key="your-api-key" │
695
758
  │ ) │
696
759
  │ middleware = WishubMemoryMiddleware( │
697
- │ client=memory_client, │
760
+ │ client=client, │
698
761
  │ namespaces=["user_profile", "preferences"], │
699
762
  │ top_k=5 │
700
763
  │ ) │
@@ -794,6 +857,21 @@ Phase 3.5: 记忆能力接入 (✅ 已完成 — v0.4)
794
857
  ✅ wrap_agent config 注入 — user_id, thread_id 传递到 LangGraph config.configurable
795
858
  ✅ 完整测试覆盖 (39 个测试用例全部通过)
796
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
+
797
875
  Phase 4: 高级特性
798
876
  ════════════════
799
877
  目标: 用户故事 7 — Checkpoint、多协议
@@ -809,15 +887,16 @@ Phase 5: 多框架 + 多协议
809
887
 
810
888
  □ AgentScope Adapter
811
889
  □ AGUI Handler
812
- □ 内部 PyPI 发布
890
+ ✅ 官方 PyPI 发布 (v0.6.0 — pypi.org/project/wisruntime)
813
891
  □ 性能基准测试
814
892
  ```
815
893
 
816
- ### 5.3 目录结构 (目标态)
894
+ ### 5.3 目录结构 (v0.6)
817
895
 
818
896
  ```
819
897
  wisruntime/
820
898
  ├── __init__.py # 顶层导出: create_server, Config, ToolInfo, ToolResult
899
+ ├── client.py # WisHubClient — 统一配置容器 (hub_endpoint/api_key/timeout)
821
900
  ├── config.py # Config, CredentialContext
822
901
  ├── model.py # CanonicalEvent (13 种), AgentRequest, Message
823
902
  ├── exceptions.py # 自定义异常
@@ -828,15 +907,29 @@ wisruntime/
828
907
  │ ├── protocol.py # ToolClient (ABC) — 抽象协议
829
908
  │ └── client.py # MCPClient(ToolClient) — 薄封装标准 mcp 包
830
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
+ │
831
928
  ├── adapters/ # Adapter + Capability Bridge
832
- │ ├── memory/ # Memory 记忆检索适配器 (✅ v0.4)
833
- │ │ ├── __init__.py # 导出 WishubMemoryClient, MemoryPromptFormatter, MemoryItem
834
- │ │ ├── model.py # MemoryItem, RetrieveRequest, RetrieveResponse (Pydantic 模型)
835
- │ │ ├── client.py # WishubMemoryClient — 异步 HTTP 客户端,优雅降级
836
- │ │ └── formatter.py # MemoryPromptFormatter — 记忆列表 → XML 提示词片段
837
- │ │
838
929
  │ └── langgraph/ # LangGraph/LangChain/DeepAgents 框架 (✅ v0.3)
839
- │ ├── __init__.py # 导出 LangGraphEventConverter, wrap_agent, LangChainToolAdapter, create_model, create_mcp_tools, WishubMemoryMiddleware
930
+ │ ├── __init__.py # 导出 LangGraphEventConverter, wrap_agent, LangChainToolAdapter,
931
+ │ │ # create_model, create_mcp_tools, WishubMemoryMiddleware
932
+ │ │ # (v0.6 起转发导出 wisruntime.memory 的 5 个记忆符号)
840
933
  │ ├── converter.py # LangGraphEventConverter (astream_events → CanonicalEvent)
841
934
  │ ├── wrap_agent.py # wrap_agent() 糖函数 (注入 config: user_id, thread_id)
842
935
  │ ├── tool_adapter.py # LangChainToolAdapter (ToolInfo → StructuredTool)
@@ -850,11 +943,6 @@ wisruntime/
850
943
  │ ├── dify_handler.py # DifyHandler (SSE + Blocking)
851
944
  │ └── protocol.py # ProtocolHandler 抽象基类
852
945
  │
853
- ├── skill/ # Skill 知识包接入层 (✅ v0.3.x — wishub-skill openapi/v1)
854
- │ ├── __init__.py # exports: SkillClient, SkillInfo, SkillDetailInfo, SkillPage
855
- │ ├── model.py # SkillInfo / SkillDetailInfo / SkillPage(信封分页模型)
856
- │ └── client.py # SkillClient — 分页发现 / 详情 / 302 预签名下载
857
- │
858
946
  └── (未来: sandbox/, checkpoint/) # 远程工具接入走 ToolClient 协议,不同实现
859
947
  ```
860
948
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "wisruntime"
7
- version = "0.5.0"
7
+ version = "0.7.0"
8
8
  description = "企业级 Agent Runtime SDK — 让 AI 工程师专注 Agent 能力开发,无需关心底层基础设施"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -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 (
@@ -40,20 +41,25 @@ from wisruntime.model import (
40
41
  UsageEvent,
41
42
  )
42
43
 
43
- # ToolInfo / ToolResult — re-exported from wisruntime.tool for backward compatibility
44
- 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
45
46
 
46
47
  # Server 层延迟导入 — 避免在非 Web 场景拉动 fastapi/uvicorn
47
48
  # 用户需要 Server 时显式导入: from wisruntime.server import create_server
48
49
 
49
50
 
50
51
  def create_server(
51
- invoke_agent,
52
+ invoke_agent=None,
52
53
  *,
53
54
  protocols=None,
54
55
  config=None,
55
- checkpoint_enabled=False,
56
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,
57
63
  ):
58
64
  """创建 WisRuntimeServer 实例 (顶层入口 API)。
59
65
 
@@ -65,14 +71,25 @@ def create_server(
65
71
 
66
72
  Args:
67
73
  invoke_agent: 用户函数 (async def fn(request: AgentRequest) → AsyncGenerator)
68
- 或 LangGraph CompiledStateGraph。
69
- protocols: 协议处理器列表,默认 [DifyHandler()]。
70
- config: ServerConfig 实例,配置 CORS、健康检查路径等。
71
- checkpoint_enabled: 是否启用 Checkpoint 自动持久化 (Phase 3)。
74
+ 或 LangGraph CompiledStateGraph。``protocols`` 为空时可省略
75
+ ——此时外壳只承载宿主自有路由,不产出任何事件流。
76
+ protocols: 协议处理器列表,默认 [DifyHandler()]。显式传 ``[]``
77
+ 表示不注册任何协议路由(宿主自带接口、只想复用外壳时用)。
78
+ config: ServerConfig 实例,配置 CORS、健康检查、应用标题等。
72
79
  conversation_client: 会话客户端 (ConversationClient)。传入时启用
73
80
  会话自动持久化:首轮自动建会话并回填 conversation_id 到
74
81
  流式事件,每轮结束后后台追加 user/assistant 消息。
75
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``,避免终止帧重复。
76
93
 
77
94
  Returns:
78
95
  WisRuntimeServer 实例,调用 .start(port=8000) 或 .as_fastapi_app() 启动服务。
@@ -94,35 +111,46 @@ def create_server(
94
111
  >>> server = create_server(my_agent, conversation_client=ConversationClient())
95
112
  """
96
113
  from wisruntime.server.server import WisRuntimeServer, ServerConfig
97
- from wisruntime.server.dify_handler import DifyHandler
98
-
99
- # 自动检测 CompiledStateGraph:如果不是 async 函数,尝试 wrap_agent
100
- if not callable(invoke_agent) or (
101
- hasattr(invoke_agent, "__class__")
102
- and type(invoke_agent).__name__ == "CompiledStateGraph"
103
- ):
104
- from wisruntime.adapters.langgraph import wrap_agent as _wrap
105
- invoke_agent = _wrap(invoke_agent)
106
- elif hasattr(invoke_agent, "astream_events") and hasattr(invoke_agent, "ainvoke"):
107
- # 有 astream_events + ainvoke 的对象 → 很可能是 CompiledStateGraph
108
- from wisruntime.adapters.langgraph import wrap_agent as _wrap
109
- invoke_agent = _wrap(invoke_agent)
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)
110
129
 
111
130
  _config = config or ServerConfig()
112
- _protocols = protocols or [DifyHandler()]
113
131
  return WisRuntimeServer(
114
132
  invoke_agent=invoke_agent,
115
133
  protocols=_protocols,
116
134
  config=_config,
117
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,
118
142
  )
119
143
 
120
144
 
121
145
  __all__ = [
122
146
  "create_server",
147
+ "create_agent_stream",
148
+ "combine_lifespans",
149
+ "AgentStream",
123
150
  "wrap_agent",
124
151
  "Config",
125
152
  "CredentialContext",
153
+ "WisHubClient",
126
154
  "AgentRequest",
127
155
  "Message",
128
156
  "TextDeltaEvent",
@@ -140,6 +168,7 @@ __all__ = [
140
168
  "DoneEvent",
141
169
  "ToolInfo",
142
170
  "ToolResult",
171
+ "ToolSpec",
143
172
  "WisRuntimeError",
144
173
  "ConfigError",
145
174
  "ProtocolError",
@@ -156,4 +185,13 @@ def __getattr__(name):
156
185
  if name == "wrap_agent":
157
186
  from wisruntime.adapters.langgraph import wrap_agent as _wrap_agent
158
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
159
197
  raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
@@ -2,10 +2,13 @@
2
2
 
3
3
  按框架分子目录组织:
4
4
  - langgraph/ — LangGraph/LangChain/DeepAgents 框架适配
5
- - memory/ — DEPRECATED: 已移至 wisruntime.memory(此处仅为兼容性 shim)
6
5
  - (未来) llamaindex/ — LlamaIndex 框架适配
7
6
  - (未来) crewai/ — CrewAI 框架适配
8
7
 
8
+ 注意:记忆能力(记忆检索客户端与提示词格式化)是框架无关的平台能力,
9
+ 不在 adapters/ 下——请从 wisruntime.memory 导入;LangGraph 适配层也
10
+ 从 wisruntime.adapters.langgraph 转发导出这些符号。
11
+
9
12
  每个子目录包含:
10
13
  - converter.py — 框架事件 → CanonicalEvent 转换器
11
14
  - wrap_agent.py — 框架 Agent 对象的封装糖函数