wisruntime 0.5.0__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.
Files changed (44) hide show
  1. {wisruntime-0.5.0/wisruntime.egg-info → wisruntime-0.6.0}/PKG-INFO +44 -10
  2. {wisruntime-0.5.0 → wisruntime-0.6.0}/README.md +43 -9
  3. {wisruntime-0.5.0 → wisruntime-0.6.0}/pyproject.toml +1 -1
  4. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/__init__.py +2 -0
  5. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/adapters/__init__.py +4 -1
  6. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/adapters/langgraph/__init__.py +18 -0
  7. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/adapters/langgraph/builtin.py +14 -6
  8. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/adapters/langgraph/memory_middleware.py +19 -7
  9. wisruntime-0.6.0/wisruntime/client.py +73 -0
  10. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/conversation/client.py +29 -11
  11. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/memory/client.py +23 -5
  12. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/skill/client.py +28 -10
  13. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/tool/client.py +24 -8
  14. {wisruntime-0.5.0 → wisruntime-0.6.0/wisruntime.egg-info}/PKG-INFO +44 -10
  15. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime.egg-info/SOURCES.txt +1 -1
  16. wisruntime-0.5.0/wisruntime/adapters/memory/__init__.py +0 -35
  17. {wisruntime-0.5.0 → wisruntime-0.6.0}/MANIFEST.in +0 -0
  18. {wisruntime-0.5.0 → wisruntime-0.6.0}/setup.cfg +0 -0
  19. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/adapters/langgraph/_utils.py +0 -0
  20. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/adapters/langgraph/converter.py +0 -0
  21. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/adapters/langgraph/tool_adapter.py +0 -0
  22. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/adapters/langgraph/wrap_agent.py +0 -0
  23. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/config.py +0 -0
  24. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/conversation/__init__.py +0 -0
  25. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/conversation/model.py +0 -0
  26. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/conversation/recorder.py +0 -0
  27. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/exceptions.py +0 -0
  28. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/memory/__init__.py +0 -0
  29. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/memory/formatter.py +0 -0
  30. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/memory/model.py +0 -0
  31. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/model.py +0 -0
  32. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/server/__init__.py +0 -0
  33. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/server/dify_handler.py +0 -0
  34. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/server/invoker.py +0 -0
  35. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/server/protocol.py +0 -0
  36. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/server/server.py +0 -0
  37. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/skill/__init__.py +0 -0
  38. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/skill/model.py +0 -0
  39. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/tool/__init__.py +0 -0
  40. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/tool/model.py +0 -0
  41. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime/tool/protocol.py +0 -0
  42. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime.egg-info/dependency_links.txt +0 -0
  43. {wisruntime-0.5.0 → wisruntime-0.6.0}/wisruntime.egg-info/requires.txt +0 -0
  44. {wisruntime-0.5.0 → 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.5.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=600):
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() # 自动读取 WIS_HUB_API_KEY
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
- client = MCPClient()
407
- tools = await LangChainToolAdapter.from_client(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
- client, filter_fn=lambda t: "search" in t.name
446
+ mcp_client, filter_fn=lambda t: "search" in t.name
413
447
  )
414
448
 
415
449
  # 方式 D: 单工具手动创建
@@ -718,15 +752,15 @@ def create_server(
718
752
  │ │
719
753
  │ 验收标准: │
720
754
  │ from deepagents import create_deep_agent │
755
+ │ from wisruntime import WisHubClient │
721
756
  │ from wisruntime.adapters.langgraph import WishubMemoryMiddleware │
722
- │ from wisruntime.memory import WishubMemoryClient │
723
757
  │ │
724
- │ memory_client = WishubMemoryClient( │
725
- │ base_url="https://wishub.example.com", │
758
+ │ client = WisHubClient( │
759
+ │ hub_endpoint="https://wishub.example.com", │
726
760
  │ api_key="your-api-key" │
727
761
  │ ) │
728
762
  │ middleware = WishubMemoryMiddleware( │
729
- │ client=memory_client, │
763
+ │ client=client, │
730
764
  │ namespaces=["user_profile", "preferences"], │
731
765
  │ top_k=5 │
732
766
  │ ) │
@@ -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=600):
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() # 自动读取 WIS_HUB_API_KEY
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
- client = MCPClient()
375
- tools = await LangChainToolAdapter.from_client(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
- client, filter_fn=lambda t: "search" in t.name
414
+ mcp_client, filter_fn=lambda t: "search" in t.name
381
415
  )
382
416
 
383
417
  # 方式 D: 单工具手动创建
@@ -686,15 +720,15 @@ def create_server(
686
720
  │ │
687
721
  │ 验收标准: │
688
722
  │ from deepagents import create_deep_agent │
723
+ │ from wisruntime import WisHubClient │
689
724
  │ from wisruntime.adapters.langgraph import WishubMemoryMiddleware │
690
- │ from wisruntime.memory import WishubMemoryClient │
691
725
  │ │
692
- │ memory_client = WishubMemoryClient( │
693
- │ base_url="https://wishub.example.com", │
726
+ │ client = WisHubClient( │
727
+ │ hub_endpoint="https://wishub.example.com", │
694
728
  │ api_key="your-api-key" │
695
729
  │ ) │
696
730
  │ middleware = WishubMemoryMiddleware( │
697
- │ client=memory_client, │
731
+ │ client=client, │
698
732
  │ namespaces=["user_profile", "preferences"], │
699
733
  │ top_k=5 │
700
734
  │ ) │
@@ -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.6.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 (
@@ -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",
@@ -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 对象的封装糖函数
@@ -7,6 +7,10 @@
7
7
  - create_model: 快速创建 LangChain 模型实例
8
8
  - create_mcp_tools: 一行获取 MCP 工具列表
9
9
  - WishubMemoryMiddleware: Wishub 记忆检索中间件
10
+ - WishubMemoryClient / MemoryPromptFormatter / MemoryItem /
11
+ RetrieveRequest / RetrieveResponse: wisruntime.memory 的转发导出
12
+ (框架无关,权威定义在 wisruntime.memory),使本包成为适配层
13
+ 唯一的记忆入口
10
14
  """
11
15
 
12
16
  from wisruntime.adapters.langgraph.builtin import create_mcp_tools, create_model
@@ -19,6 +23,15 @@ from wisruntime.adapters.langgraph.memory_middleware import (
19
23
  from wisruntime.adapters.langgraph.tool_adapter import LangChainToolAdapter
20
24
  from wisruntime.adapters.langgraph.wrap_agent import wrap_agent
21
25
 
26
+ # wisruntime.memory 的转发导出(框架无关,权威定义见 wisruntime.memory)
27
+ from wisruntime.memory import (
28
+ WishubMemoryClient,
29
+ MemoryPromptFormatter,
30
+ MemoryItem,
31
+ RetrieveRequest,
32
+ RetrieveResponse,
33
+ )
34
+
22
35
  __all__ = [
23
36
  "LangGraphEventConverter",
24
37
  "wrap_agent",
@@ -28,4 +41,9 @@ __all__ = [
28
41
  "WishubMemoryMiddleware",
29
42
  "WishubMemoryState",
30
43
  "WishubMemoryStateUpdate",
44
+ "WishubMemoryClient",
45
+ "MemoryPromptFormatter",
46
+ "MemoryItem",
47
+ "RetrieveRequest",
48
+ "RetrieveResponse",
31
49
  ]
@@ -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
- >>> tools = await create_mcp_tools()
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
- url: MCP Server URL。None 时使用 Config 默认值。
82
- api_key: API Key。None 时使用 Config 三级获取。
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
- >>> tools = await create_mcp_tools()
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
- client = MCPClient(url=url, api_key=api_key)
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(client, filter_fn=filter_fn)
104
+ return await LangChainToolAdapter.from_client(mcp_client, filter_fn=filter_fn)
97
105
 
98
106
 
99
107
  async def create_skill_sources(
@@ -20,6 +20,7 @@ from langchain.agents.middleware.types import (
20
20
  omit_payload,
21
21
  )
22
22
 
23
+ from wisruntime.client import WisHubClient
23
24
  from wisruntime.memory import WishubMemoryClient, MemoryPromptFormatter, MemoryItem
24
25
  from wisruntime.adapters.langgraph._utils import append_to_system_message
25
26
 
@@ -44,12 +45,17 @@ class WishubMemoryMiddleware(AgentMiddleware[WishubMemoryState, ContextT, Respon
44
45
  在 Agent 执行前,根据用户查询检索相关记忆,并注入到系统提示词中。
45
46
 
46
47
  Example:
48
+ >>> from wisruntime import WisHubClient
47
49
  >>> from wisruntime.adapters.langgraph import WishubMemoryMiddleware
48
50
  >>> from deepagents import create_deep_agent
49
51
  >>>
50
- >>> middleware = WishubMemoryMiddleware(
51
- ... base_url="https://aip-open-api-dev.infinitus.com.cn",
52
+ >>> # 统一 client 注入(推荐)
53
+ >>> client = WisHubClient(
54
+ ... hub_endpoint="https://aip-open-api-dev.infinitus.com.cn",
52
55
  ... api_key="your-api-key",
56
+ ... )
57
+ >>> middleware = WishubMemoryMiddleware(
58
+ ... client=client,
53
59
  ... namespaces=["preference", "history"],
54
60
  ... top_k=5,
55
61
  ... )
@@ -66,8 +72,9 @@ class WishubMemoryMiddleware(AgentMiddleware[WishubMemoryState, ContextT, Respon
66
72
  def __init__(
67
73
  self,
68
74
  *,
69
- base_url: str,
70
- api_key: str,
75
+ client: Optional[WisHubClient] = None,
76
+ base_url: Optional[str] = None,
77
+ api_key: Optional[str] = None,
71
78
  namespaces: Optional[list[str]] = None,
72
79
  top_k: int = 5,
73
80
  timeout: float = 5.0,
@@ -76,14 +83,19 @@ class WishubMemoryMiddleware(AgentMiddleware[WishubMemoryState, ContextT, Respon
76
83
  """初始化 Wishub Memory 中间件。
77
84
 
78
85
  Args:
79
- base_url: Wishub Memory API 基础地址
80
- api_key: API Key (智能体通道鉴权)
86
+ client: WisHubClient 统一配置容器(推荐)。传入时
87
+ base_url/api_key 从中推导;显式参数可覆盖。
88
+ base_url: Wishub Memory API 基础地址(兼容参数,
89
+ 无 client 时必填)
90
+ api_key: API Key (智能体通道鉴权,兼容参数,
91
+ 无 client 时必填)
81
92
  namespaces: 可选的命名空间过滤列表
82
93
  top_k: 检索记忆数量上限(默认5)
83
- timeout: API 请求超时时间(秒)
94
+ timeout: API 请求超时时间(秒),独立于 client.timeout
84
95
  include_guidelines: 是否在提示词中包含使用指南
85
96
  """
86
97
  self.client = WishubMemoryClient(
98
+ client=client,
87
99
  base_url=base_url,
88
100
  api_key=api_key,
89
101
  timeout=timeout,
@@ -0,0 +1,73 @@
1
+ """WIS Hub 统一客户端 / WIS Hub Unified Client.
2
+
3
+ WisHubClient — 统一配置容器,一次初始化持有中台连接配置
4
+ (hub_endpoint / api_key / timeout),注入到需要平台能力的模块
5
+ (MCP / Skill / Conversation / Memory 等),消除重复配置。
6
+
7
+ 使用示例:
8
+ >>> from wisruntime import WisHubClient
9
+ >>> from wisruntime.adapters.langgraph import WishubMemoryMiddleware
10
+ >>> from wisruntime.adapters.langgraph.builtin import create_mcp_tools
11
+ >>>
12
+ >>> # 一次初始化
13
+ >>> client = WisHubClient(
14
+ ... hub_endpoint="https://aip.example.com",
15
+ ... api_key="sk-xxx",
16
+ ... )
17
+ >>>
18
+ >>> # 注入到需要的模块
19
+ >>> middleware = WishubMemoryMiddleware(client=client, top_k=5)
20
+ >>> tools = await create_mcp_tools(client=client)
21
+
22
+ 配置默认值: 未显式传入时从 Config() 三级获取
23
+ (显式 > contextvars > 环境变量),与各 client 构造语义一致。
24
+
25
+ WisHubClient 是纯配置容器: 不建立网络连接、不持有 HTTP client、
26
+ 不依赖任何平台 client 模块。
27
+ """
28
+
29
+ from wisruntime.config import Config
30
+
31
+
32
+ class WisHubClient:
33
+ """WIS Hub 统一配置容器。
34
+
35
+ 一次初始化持有 hub_endpoint / api_key / timeout,供各平台能力
36
+ 模块通过 ``client`` 参数共享配置。传入 client 的模块无需再重复
37
+ 配置 hub_endpoint 与 api_key;显式参数仍可覆盖 client 的值。
38
+
39
+ 纯配置容器: 构造时不建立网络连接,不创建 HTTP client。
40
+
41
+ Demo:
42
+ >>> # 显式配置
43
+ >>> client = WisHubClient(
44
+ ... hub_endpoint="https://aip.example.com",
45
+ ... api_key="sk-xxx",
46
+ ... )
47
+ >>> client.hub_endpoint
48
+ 'https://aip.example.com'
49
+ >>>
50
+ >>> # 从环境变量读取 (WIS_HUB_ENDPOINT / WIS_HUB_API_KEY)
51
+ >>> client = WisHubClient()
52
+ """
53
+
54
+ def __init__(
55
+ self,
56
+ hub_endpoint: str | None = None,
57
+ api_key: str | None = None,
58
+ timeout: int = 600,
59
+ ):
60
+ """初始化 WisHubClient——不建立网络连接。
61
+
62
+ Args:
63
+ hub_endpoint: WIS Hub 中台基础地址。None 时使用
64
+ Config().hub_endpoint(环境变量 WIS_HUB_ENDPOINT
65
+ 或内置默认地址)。尾部斜杠自动去除。
66
+ api_key: API-KEY。None 时使用 Config 三级获取
67
+ (显式 > contextvars > 环境变量 WIS_HUB_API_KEY)。
68
+ timeout: HTTP 请求超时秒数,默认 600 秒。
69
+ """
70
+ config = Config()
71
+ self.hub_endpoint = (hub_endpoint or config.hub_endpoint).rstrip("/")
72
+ self.api_key = api_key or config.api_key or ""
73
+ self.timeout = timeout
@@ -35,6 +35,7 @@ from typing import Any, Literal
35
35
  import httpx
36
36
 
37
37
  from wisruntime.config import Config
38
+ from wisruntime.client import WisHubClient
38
39
  from wisruntime.conversation.model import AppendMessage, ConversationInfo, MessageInfo
39
40
  from wisruntime.exceptions import (
40
41
  ResourceNotFoundError,
@@ -63,6 +64,11 @@ class ConversationClient:
63
64
  ... conv = await client.create_conversation(user_id="u_001")
64
65
  ... await client.append_message(conv.conversation_id, "u_001", "user", "你好")
65
66
  >>>
67
+ >>> # 统一 client 注入(推荐)
68
+ >>> from wisruntime import WisHubClient
69
+ >>> hub = WisHubClient(hub_endpoint="https://...", api_key="sk-...")
70
+ >>> client = ConversationClient(client=hub)
71
+ >>>
66
72
  >>> # 同步用法
67
73
  >>> client = ConversationClient()
68
74
  >>> conv = client.create_conversation_sync(user_id="u_001")
@@ -71,24 +77,36 @@ class ConversationClient:
71
77
 
72
78
  def __init__(
73
79
  self,
80
+ client: WisHubClient | None = None,
74
81
  url: str | None = None,
75
82
  api_key: str | None = None,
76
- timeout: int = 600,
83
+ timeout: int | None = None,
77
84
  ):
78
85
  """初始化 ConversationClient——不建立网络连接。
79
86
 
80
87
  Args:
81
- url: wishub-memory 会话端点。None 时使用
82
- {hub_endpoint}/wishub-memory/openapi/v1/conversations。
83
- api_key: API-KEY。None 时使用 Config 三级获取。
84
- timeout: HTTP 请求超时秒数,默认 600 秒。
88
+ client: WisHubClient 统一配置容器(推荐)。传入时
89
+ url/api_key/timeout 从中推导;显式参数可覆盖。
90
+ url: wishub-memory 会话端点。None 时从 client 或 Config
91
+ 推断({hub_endpoint}/wishub-memory/openapi/v1/conversations)。
92
+ api_key: API-KEY。None 时从 client 或 Config 三级获取。
93
+ timeout: HTTP 请求超时秒数。None 时取 client.timeout,
94
+ 无 client 时默认 600 秒。
85
95
  """
86
- config = Config()
87
- self._base_url = (
88
- url or config.hub_endpoint.rstrip("/") + "/wishub-memory/openapi/v1/conversations"
89
- ).rstrip("/")
90
- self._api_key = api_key or config.api_key or ""
91
- self._timeout = timeout
96
+ if client is not None:
97
+ self._base_url = (
98
+ url
99
+ or f"{client.hub_endpoint.rstrip('/')}/wishub-memory/openapi/v1/conversations"
100
+ ).rstrip("/")
101
+ self._api_key = api_key or client.api_key or ""
102
+ self._timeout = timeout if timeout is not None else client.timeout
103
+ else:
104
+ config = Config()
105
+ self._base_url = (
106
+ url or config.hub_endpoint.rstrip("/") + "/wishub-memory/openapi/v1/conversations"
107
+ ).rstrip("/")
108
+ self._api_key = api_key or config.api_key or ""
109
+ self._timeout = timeout if timeout is not None else 600
92
110
  self._client: httpx.AsyncClient | None = None
93
111
 
94
112
  # =========================================================================
@@ -5,6 +5,7 @@ from typing import Optional
5
5
 
6
6
  import httpx
7
7
 
8
+ from wisruntime.client import WisHubClient
8
9
  from wisruntime.memory.model import (
9
10
  MemoryItem,
10
11
  RetrieveResponse,
@@ -19,17 +20,34 @@ class WishubMemoryClient:
19
20
  def __init__(
20
21
  self,
21
22
  *,
22
- base_url: str,
23
- api_key: str,
23
+ client: Optional[WisHubClient] = None,
24
+ base_url: Optional[str] = None,
25
+ api_key: Optional[str] = None,
24
26
  timeout: float = 5.0,
25
27
  ):
26
28
  """初始化记忆客户端。
27
29
 
28
30
  Args:
29
- base_url: API 基础地址,如 "https://aip-open-api-dev.infinitus.com.cn"
30
- api_key: API Key (智能体通道鉴权)
31
- timeout: 请求超时时间(秒)
31
+ client: WisHubClient 统一配置容器(推荐)。传入时
32
+ base_url/api_key 从中推导;显式参数可覆盖。
33
+ base_url: API 基础地址,如 "https://aip-open-api-dev.infinitus.com.cn"。
34
+ None 时从 client.hub_endpoint 推导。
35
+ api_key: API Key (智能体通道鉴权)。None 时从 client.api_key 推导。
36
+ timeout: 请求超时时间(秒),默认 5.0——独立于 client.timeout
37
+ (记忆检索需要短超时,与统一 600s 语义不同)。
32
38
  """
39
+ if client is not None:
40
+ base_url = base_url or client.hub_endpoint
41
+ api_key = api_key or client.api_key
42
+ self.base_url = base_url.rstrip("/")
43
+ self.api_key = api_key or ""
44
+ self.timeout = timeout
45
+ self._endpoint = f"{self.base_url}/wishub-memory/openapi/v1/memories/retrieve"
46
+ return
47
+
48
+ if base_url is None or api_key is None:
49
+ raise ValueError("Must provide either 'client' or both 'base_url' and 'api_key'")
50
+
33
51
  self.base_url = base_url.rstrip("/")
34
52
  self.api_key = api_key
35
53
  self.timeout = timeout
@@ -45,6 +45,7 @@ from typing import Any
45
45
  import httpx
46
46
 
47
47
  from wisruntime.config import Config
48
+ from wisruntime.client import WisHubClient
48
49
  from wisruntime.exceptions import (
49
50
  ForbiddenError,
50
51
  ResourceNotFoundError,
@@ -76,6 +77,11 @@ class SkillClient:
76
77
  ... skills = await client.list_skills()
77
78
  ... await client.download_skill("skill_k67go1cujb6ji", ".skills")
78
79
  >>>
80
+ >>> # 统一 client 注入(推荐)
81
+ >>> from wisruntime import WisHubClient
82
+ >>> hub = WisHubClient(hub_endpoint="https://...", api_key="sk-...")
83
+ >>> client = SkillClient(client=hub)
84
+ >>>
79
85
  >>> # 同步用法
80
86
  >>> client = SkillClient()
81
87
  >>> skills = client.list_skills_sync()
@@ -84,23 +90,35 @@ class SkillClient:
84
90
 
85
91
  def __init__(
86
92
  self,
93
+ client: WisHubClient | None = None,
87
94
  url: str | None = None,
88
95
  api_key: str | None = None,
89
- timeout: int = 600,
96
+ timeout: int | None = None,
90
97
  ):
91
98
  """初始化 SkillClient——不建立网络连接。
92
99
 
93
100
  Args:
94
- url: WIS Hub Skill 端点。None 时使用 {hub_endpoint}/wishub-skill/openapi/v1。
95
- api_key: API-KEY。None 时使用 Config 三级获取。
96
- timeout: HTTP 请求超时秒数,默认 600 秒。
101
+ client: WisHubClient 统一配置容器(推荐)。传入时
102
+ url/api_key/timeout 从中推导;显式参数可覆盖。
103
+ url: WIS Hub Skill 端点。None 时从 client 或 Config
104
+ 推断({hub_endpoint}/wishub-skill/openapi/v1)。
105
+ api_key: API-KEY。None 时从 client 或 Config 三级获取。
106
+ timeout: HTTP 请求超时秒数。None 时取 client.timeout,
107
+ 无 client 时默认 600 秒。
97
108
  """
98
- config = Config()
99
- self._base_url = (
100
- url or config.hub_endpoint.rstrip("/") + "/wishub-skill/openapi/v1"
101
- ).rstrip("/")
102
- self._api_key = api_key or config.api_key or ""
103
- self._timeout = timeout
109
+ if client is not None:
110
+ self._base_url = (
111
+ url or f"{client.hub_endpoint.rstrip('/')}/wishub-skill/openapi/v1"
112
+ ).rstrip("/")
113
+ self._api_key = api_key or client.api_key or ""
114
+ self._timeout = timeout if timeout is not None else client.timeout
115
+ else:
116
+ config = Config()
117
+ self._base_url = (
118
+ url or config.hub_endpoint.rstrip("/") + "/wishub-skill/openapi/v1"
119
+ ).rstrip("/")
120
+ self._api_key = api_key or config.api_key or ""
121
+ self._timeout = timeout if timeout is not None else 600
104
122
  self._client: httpx.AsyncClient | None = None
105
123
 
106
124
  # =========================================================================
@@ -25,6 +25,7 @@ import logging
25
25
  from typing import Any
26
26
 
27
27
  from wisruntime.config import Config
28
+ from wisruntime.client import WisHubClient
28
29
  from wisruntime.exceptions import MCPSessionError
29
30
  from wisruntime.tool.model import ToolInfo, ToolResult
30
31
  from wisruntime.tool.protocol import ToolClient
@@ -67,6 +68,11 @@ class MCPClient(ToolClient):
67
68
  >>> tools = await c.list_tools()
68
69
  >>> result = await c.call_tool("search", {"q": "..."})
69
70
  >>>
71
+ >>> # 统一 client 注入(推荐)
72
+ >>> from wisruntime import WisHubClient
73
+ >>> hub = WisHubClient(hub_endpoint="https://...", api_key="sk-...")
74
+ >>> c = MCPClient(client=hub)
75
+ >>>
70
76
  >>> # Notebook/脚本场景——sync
71
77
  >>> c = MCPClient()
72
78
  >>> tools = c.list_tools_sync()
@@ -74,22 +80,32 @@ class MCPClient(ToolClient):
74
80
 
75
81
  def __init__(
76
82
  self,
83
+ client: WisHubClient | None = None,
77
84
  url: str | None = None,
78
85
  api_key: str | None = None,
79
- timeout: int = 600,
86
+ timeout: int | None = None,
80
87
  ):
81
88
  """初始化 MCPClient——不建立网络连接。
82
89
 
83
90
  Args:
91
+ client: WisHubClient 统一配置容器(推荐)。传入时
92
+ url/api_key/timeout 从中推导;显式参数可覆盖。
84
93
  url: MCP Server 的 Streamable HTTP 端点地址。
85
- None 时从 Config 推断({hub_endpoint}/wishub-mcp/mcp)。
86
- api_key: Bearer token 的值。None 时从 Config.api_key 三级获取。
87
- timeout: HTTP 超时秒数,默认 600 秒。
94
+ None 时从 client 或 Config 推断({hub_endpoint}/wishub-mcp/mcp)。
95
+ api_key: Bearer token 的值。None 时从 client 或
96
+ Config.api_key 三级获取。
97
+ timeout: HTTP 超时秒数。None 时取 client.timeout,
98
+ 无 client 时默认 600 秒。
88
99
  """
89
- config = Config()
90
- self._url = url or config.hub_endpoint.rstrip("/") + "/wishub-mcp/mcp"
91
- self._api_key = api_key or config.api_key or ""
92
- self._timeout = timeout
100
+ if client is not None:
101
+ self._url = url or f"{client.hub_endpoint.rstrip('/')}/wishub-mcp/mcp"
102
+ self._api_key = api_key or client.api_key or ""
103
+ self._timeout = timeout if timeout is not None else client.timeout
104
+ else:
105
+ config = Config()
106
+ self._url = url or config.hub_endpoint.rstrip("/") + "/wishub-mcp/mcp"
107
+ self._api_key = api_key or config.api_key or ""
108
+ self._timeout = timeout if timeout is not None else 600
93
109
 
94
110
  # =========================================================================
95
111
  # Session 管理(无状态:每次调用自包含)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wisruntime
3
- Version: 0.5.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=600):
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() # 自动读取 WIS_HUB_API_KEY
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
- client = MCPClient()
407
- tools = await LangChainToolAdapter.from_client(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
- client, filter_fn=lambda t: "search" in t.name
446
+ mcp_client, filter_fn=lambda t: "search" in t.name
413
447
  )
414
448
 
415
449
  # 方式 D: 单工具手动创建
@@ -718,15 +752,15 @@ def create_server(
718
752
  │ │
719
753
  │ 验收标准: │
720
754
  │ from deepagents import create_deep_agent │
755
+ │ from wisruntime import WisHubClient │
721
756
  │ from wisruntime.adapters.langgraph import WishubMemoryMiddleware │
722
- │ from wisruntime.memory import WishubMemoryClient │
723
757
  │ │
724
- │ memory_client = WishubMemoryClient( │
725
- │ base_url="https://wishub.example.com", │
758
+ │ client = WisHubClient( │
759
+ │ hub_endpoint="https://wishub.example.com", │
726
760
  │ api_key="your-api-key" │
727
761
  │ ) │
728
762
  │ middleware = WishubMemoryMiddleware( │
729
- │ client=memory_client, │
763
+ │ client=client, │
730
764
  │ namespaces=["user_profile", "preferences"], │
731
765
  │ top_k=5 │
732
766
  │ ) │
@@ -2,6 +2,7 @@ MANIFEST.in
2
2
  README.md
3
3
  pyproject.toml
4
4
  wisruntime/__init__.py
5
+ wisruntime/client.py
5
6
  wisruntime/config.py
6
7
  wisruntime/exceptions.py
7
8
  wisruntime/model.py
@@ -18,7 +19,6 @@ wisruntime/adapters/langgraph/converter.py
18
19
  wisruntime/adapters/langgraph/memory_middleware.py
19
20
  wisruntime/adapters/langgraph/tool_adapter.py
20
21
  wisruntime/adapters/langgraph/wrap_agent.py
21
- wisruntime/adapters/memory/__init__.py
22
22
  wisruntime/conversation/__init__.py
23
23
  wisruntime/conversation/client.py
24
24
  wisruntime/conversation/model.py
@@ -1,35 +0,0 @@
1
- """
2
- Deprecated: This module has moved to wisruntime.memory
3
-
4
- This compatibility shim will be removed in a future version.
5
- Please update your imports:
6
- from wisruntime.adapters.memory import X # Old (deprecated)
7
- from wisruntime.memory import X # New
8
- """
9
-
10
- import warnings
11
-
12
- # Issue deprecation warning
13
- warnings.warn(
14
- "wisruntime.adapters.memory is deprecated and will be removed in a future version. "
15
- "Please use wisruntime.memory instead.",
16
- DeprecationWarning,
17
- stacklevel=2,
18
- )
19
-
20
- # Re-export from new location for backward compatibility
21
- from wisruntime.memory import (
22
- WishubMemoryClient,
23
- MemoryPromptFormatter,
24
- MemoryItem,
25
- RetrieveRequest,
26
- RetrieveResponse,
27
- )
28
-
29
- __all__ = [
30
- "WishubMemoryClient",
31
- "MemoryPromptFormatter",
32
- "MemoryItem",
33
- "RetrieveRequest",
34
- "RetrieveResponse",
35
- ]
File without changes
File without changes