fae-plugin-py 0.2.0__tar.gz → 0.3.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 (29) hide show
  1. fae_plugin_py-0.3.0/PKG-INFO +102 -0
  2. fae_plugin_py-0.3.0/README.md +83 -0
  3. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/pyproject.toml +1 -1
  4. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/_protocol.py +5 -1
  5. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/_worker.py +15 -1
  6. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/config.py +3 -1
  7. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/context.py +13 -1
  8. fae_plugin_py-0.3.0/src/fae_plugin_py.egg-info/PKG-INFO +102 -0
  9. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/tests/test_sdk.py +13 -0
  10. fae_plugin_py-0.2.0/PKG-INFO +0 -309
  11. fae_plugin_py-0.2.0/README.md +0 -290
  12. fae_plugin_py-0.2.0/src/fae_plugin_py.egg-info/PKG-INFO +0 -309
  13. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/LICENSE +0 -0
  14. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/setup.cfg +0 -0
  15. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/__init__.py +0 -0
  16. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/_host.py +0 -0
  17. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/_inspect.py +0 -0
  18. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/chain.py +0 -0
  19. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/data.py +0 -0
  20. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/engine.py +0 -0
  21. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/errors.py +0 -0
  22. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/hooks.py +0 -0
  23. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/py.typed +0 -0
  24. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/registration.py +0 -0
  25. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/session.py +0 -0
  26. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin/types.py +0 -0
  27. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin_py.egg-info/SOURCES.txt +0 -0
  28. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin_py.egg-info/dependency_links.txt +0 -0
  29. {fae_plugin_py-0.2.0 → fae_plugin_py-0.3.0}/src/fae_plugin_py.egg-info/top_level.txt +0 -0
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: fae-plugin-py
3
+ Version: 0.3.0
4
+ Summary: Typed Python plugins for the FAE agent engine
5
+ Author-email: Teshin <1443965173@qq.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/woshihaoren4/free-agent-engine
8
+ Project-URL: Documentation, https://github.com/woshihaoren4/free-agent-engine/tree/v2-plugins/python/fae-plugin-py
9
+ Project-URL: Issues, https://github.com/woshihaoren4/free-agent-engine/issues
10
+ Keywords: fae,agent,plugins,sdk
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Dynamic: license-file
19
+
20
+ # fae-plugin-py
21
+
22
+ FAE Agent Engine 的类型化 Python 插件 SDK,支持 Agent、工具和模型钩子,
23
+ 以及执行上下文读取、Session 输出和子调用。
24
+
25
+ 需要 Python 3.10 或更新版本。SDK 的发行版本与插件 API 版本分别管理;
26
+ 当前插件 API 为 `0.2.0`,使用公共 v4 协议,需要对应版本的 FAE 宿主。
27
+
28
+ ## 安装
29
+
30
+ ```bash
31
+ python3 -m pip install fae-plugin-py
32
+ ```
33
+
34
+ 在仓库根目录进行本地开发:
35
+
36
+ ```bash
37
+ python3 -m pip install -e ./python/fae-plugin-py
38
+ ```
39
+
40
+ 将 SDK 安装到宿主使用的 Python 解释器中。若使用虚拟环境,在启动 FAE 服务前
41
+ 设置 `FAE_PLUGIN_PYTHON` 为该环境的 Python 路径。
42
+
43
+ ## 最小 Agent 插件
44
+
45
+ 保存为 `project_context.py`:
46
+
47
+ ```python
48
+ from fae_plugin import Context, SingleAgentHook, TextContent
49
+
50
+
51
+ def plugin_config() -> dict:
52
+ return {
53
+ "plugin_version": "1.0.0",
54
+ "fae_plugin_api_version": "0.2.0",
55
+ "description": "清理输入并补充项目规范",
56
+ "mounts": [{
57
+ "point": "SingleAgentHook",
58
+ "implementation": "ProjectContext",
59
+ "agent_id": "fae",
60
+ }],
61
+ }
62
+
63
+
64
+ class ProjectContext(SingleAgentHook):
65
+ async def on_query(self, ctx: Context, query: str) -> str:
66
+ if ctx.session is not None:
67
+ await ctx.session.send([TextContent("开始处理请求。")])
68
+ return query.strip()
69
+
70
+ async def on_prompt(self, ctx: Context, prompt: str) -> str:
71
+ return prompt + "\n遵守当前项目的代码规范。"
72
+ ```
73
+
74
+ 安装插件并使用已配置的 `fae` Agent:
75
+
76
+ ```bash
77
+ fae plugin install ./project_context.py
78
+ fae agent --agent-id fae
79
+ ```
80
+
81
+ 目录插件通过 `plugin.config` 声明挂载点,`implementation` 使用
82
+ `plugin.py:ClassName` 格式;单文件插件通过同步的 `plugin_config()` 返回配置。
83
+
84
+ ## 主要接口
85
+
86
+ - `SingleAgentHook`:处理输入、提示词、记忆、历史、模型请求与响应、工具请求与响应。
87
+ - `ToolsHook`:实现 `desc` 和 `exec`,提供工具描述和执行结果。
88
+ - `ModelHook`:实现 `match_model` 和 `exec`,提供模型响应。
89
+ - `ChainSingleAgentHook`、`ChainToolsHook`、`ChainModelHook`:通过 `HookNext`
90
+ 将调用传给后续插件,配置 `registration_mode: "chain"`。
91
+ - `Context`:通过 `read_summary()` 和 `export_context()` 读取公共上下文;
92
+ `execution_id` 和 `invocation_id` 标识当前调用。
93
+ - `Session.send()`:发送由 `TextContent`、`JsonContent` 或 `ResourceContent`
94
+ 组成的内容,并返回输出回执;Session 可能为空,使用前需检查。
95
+ - `Context.complete_query(text)`:在 `on_query` 的原始上下文中发送最终回答并结束执行;
96
+ 此方法不返回,后续查询钩子和模型任务不会继续执行。
97
+
98
+ ## 示例与源码
99
+
100
+ 完整示例见 [插件示例](https://github.com/woshihaoren4/free-agent-engine/tree/v2-plugins/examples/plugin)
101
+ 和 [SDK 示例](https://github.com/woshihaoren4/free-agent-engine/tree/v2-plugins/python/fae-plugin-py/examples)。
102
+ 项目使用 Apache-2.0 许可证。
@@ -0,0 +1,83 @@
1
+ # fae-plugin-py
2
+
3
+ FAE Agent Engine 的类型化 Python 插件 SDK,支持 Agent、工具和模型钩子,
4
+ 以及执行上下文读取、Session 输出和子调用。
5
+
6
+ 需要 Python 3.10 或更新版本。SDK 的发行版本与插件 API 版本分别管理;
7
+ 当前插件 API 为 `0.2.0`,使用公共 v4 协议,需要对应版本的 FAE 宿主。
8
+
9
+ ## 安装
10
+
11
+ ```bash
12
+ python3 -m pip install fae-plugin-py
13
+ ```
14
+
15
+ 在仓库根目录进行本地开发:
16
+
17
+ ```bash
18
+ python3 -m pip install -e ./python/fae-plugin-py
19
+ ```
20
+
21
+ 将 SDK 安装到宿主使用的 Python 解释器中。若使用虚拟环境,在启动 FAE 服务前
22
+ 设置 `FAE_PLUGIN_PYTHON` 为该环境的 Python 路径。
23
+
24
+ ## 最小 Agent 插件
25
+
26
+ 保存为 `project_context.py`:
27
+
28
+ ```python
29
+ from fae_plugin import Context, SingleAgentHook, TextContent
30
+
31
+
32
+ def plugin_config() -> dict:
33
+ return {
34
+ "plugin_version": "1.0.0",
35
+ "fae_plugin_api_version": "0.2.0",
36
+ "description": "清理输入并补充项目规范",
37
+ "mounts": [{
38
+ "point": "SingleAgentHook",
39
+ "implementation": "ProjectContext",
40
+ "agent_id": "fae",
41
+ }],
42
+ }
43
+
44
+
45
+ class ProjectContext(SingleAgentHook):
46
+ async def on_query(self, ctx: Context, query: str) -> str:
47
+ if ctx.session is not None:
48
+ await ctx.session.send([TextContent("开始处理请求。")])
49
+ return query.strip()
50
+
51
+ async def on_prompt(self, ctx: Context, prompt: str) -> str:
52
+ return prompt + "\n遵守当前项目的代码规范。"
53
+ ```
54
+
55
+ 安装插件并使用已配置的 `fae` Agent:
56
+
57
+ ```bash
58
+ fae plugin install ./project_context.py
59
+ fae agent --agent-id fae
60
+ ```
61
+
62
+ 目录插件通过 `plugin.config` 声明挂载点,`implementation` 使用
63
+ `plugin.py:ClassName` 格式;单文件插件通过同步的 `plugin_config()` 返回配置。
64
+
65
+ ## 主要接口
66
+
67
+ - `SingleAgentHook`:处理输入、提示词、记忆、历史、模型请求与响应、工具请求与响应。
68
+ - `ToolsHook`:实现 `desc` 和 `exec`,提供工具描述和执行结果。
69
+ - `ModelHook`:实现 `match_model` 和 `exec`,提供模型响应。
70
+ - `ChainSingleAgentHook`、`ChainToolsHook`、`ChainModelHook`:通过 `HookNext`
71
+ 将调用传给后续插件,配置 `registration_mode: "chain"`。
72
+ - `Context`:通过 `read_summary()` 和 `export_context()` 读取公共上下文;
73
+ `execution_id` 和 `invocation_id` 标识当前调用。
74
+ - `Session.send()`:发送由 `TextContent`、`JsonContent` 或 `ResourceContent`
75
+ 组成的内容,并返回输出回执;Session 可能为空,使用前需检查。
76
+ - `Context.complete_query(text)`:在 `on_query` 的原始上下文中发送最终回答并结束执行;
77
+ 此方法不返回,后续查询钩子和模型任务不会继续执行。
78
+
79
+ ## 示例与源码
80
+
81
+ 完整示例见 [插件示例](https://github.com/woshihaoren4/free-agent-engine/tree/v2-plugins/examples/plugin)
82
+ 和 [SDK 示例](https://github.com/woshihaoren4/free-agent-engine/tree/v2-plugins/python/fae-plugin-py/examples)。
83
+ 项目使用 Apache-2.0 许可证。
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "fae-plugin-py"
7
- version = "0.2.0"
7
+ version = "0.3.0"
8
8
  description = "Typed Python plugins for the FAE agent engine"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"
@@ -9,7 +9,7 @@ PROTOCOL_VERSION = 4
9
9
 
10
10
  PLUGIN_PATHS = {
11
11
  "worker/hello", "inspect", "invoke", "next", "context/get", "context/export",
12
- "context/fork", "context/cancel", "context/stacks", "output/send", "stream/next", "stream/close",
12
+ "context/fork", "context/cancel", "context/complete_query", "context/stacks", "output/send", "stream/next", "stream/close",
13
13
  "call/release", "host/get_engine", "host/get_session",
14
14
  }
15
15
  SESSION_PATHS = {"execution/steer", "execution/stop", "execution/get"}
@@ -101,6 +101,7 @@ def _payload(suffix: str, payload: dict[str, Any]) -> None:
101
101
  "plugin/context/stacks": ({"access", "query"}, set()),
102
102
  "plugin/context/fork": ({"access", "spec"}, set()),
103
103
  "plugin/context/cancel": ({"access"}, {"reason"}),
104
+ "plugin/context/complete_query": ({"access", "text"}, set()),
104
105
  "plugin/output/send": ({"access", "content"}, set()),
105
106
  "plugin/stream/next": ({"call_id", "stream_id"}, {"access"}),
106
107
  "plugin/stream/close": ({"call_id", "stream_id"}, {"access"}),
@@ -118,6 +119,9 @@ def _payload(suffix: str, payload: dict[str, Any]) -> None:
118
119
  _access(payload["access"])
119
120
  if suffix == "plugin/context/fork":
120
121
  _object(payload["spec"], {"operation"})
122
+ if suffix == "plugin/context/complete_query":
123
+ if not isinstance(payload["text"], str) or not payload["text"].strip():
124
+ raise ValueError("Query result must be nonempty text")
121
125
  if suffix == "plugin/context/stacks":
122
126
  from .data import ContextStackQuery
123
127
  query = ContextStackQuery.from_dict(payload["query"])
@@ -14,7 +14,7 @@ from typing import Any
14
14
  from ._host import BoundHost, Host
15
15
  from ._protocol import Writer, read_frame, reader, request, response, hook_value
16
16
  from .chain import HookNext
17
- from .context import Context
17
+ from .context import Context, _QueryCompleted
18
18
  from .errors import HookCancelled, MissingChainHandler, PluginHostError
19
19
  from .registration import register
20
20
  from .types import API_VERSION, ModelRequest, ModelResponse, NativeObject, ToolRequest, ToolResponse, SessionMessage, UserMemory, encode, json_value
@@ -29,6 +29,7 @@ class PluginCall:
29
29
  deadline: float
30
30
  group: str
31
31
  terminal: bool = False
32
+ query_completed: bool = False
32
33
  released: bool = False
33
34
  task: asyncio.Task[Any] | None = None
34
35
  streams: set[str] = field(default_factory=set)
@@ -334,6 +335,8 @@ class Worker:
334
335
 
335
336
  async def layer(index: int, value: Any) -> Any:
336
337
  invocation.check()
338
+ if invocation.query_completed:
339
+ raise _QueryCompleted()
337
340
  check_value(point, method, value, output=False)
338
341
  if index == len(matching):
339
342
  if point != "SingleAgentHook":
@@ -358,6 +361,8 @@ class Worker:
358
361
  await host.call("/request/plugin/next", {
359
362
  "access": host.access(), "point": point, "method": method,
360
363
  "argument": self.next_wire(next_value, record.key)})
364
+ if invocation.query_completed:
365
+ raise _QueryCompleted()
361
366
  return slot["result"]
362
367
  finally:
363
368
  invocation.next_slots.pop(record.key, None)
@@ -367,6 +372,8 @@ class Worker:
367
372
  else:
368
373
  result = await self.method(getattr(record.object, method), ctx, value)
369
374
  invocation.check()
375
+ if invocation.query_completed:
376
+ raise _QueryCompleted()
370
377
  check_value(point, method, result, output=True)
371
378
  if isinstance(result, ModelResponse) and result.is_streaming:
372
379
  if not hasattr(result, "_member"):
@@ -386,6 +393,8 @@ class Worker:
386
393
  if record.mode == "direct" and index + 1 < len(matching):
387
394
  result = await layer(index + 1, result)
388
395
  return result
396
+ except _QueryCompleted:
397
+ raise
389
398
  except BaseException as error:
390
399
  if not getattr(error, "details", {}).get("plugin_id"):
391
400
  setattr(error, "details", {**getattr(error, "details", {}),
@@ -428,6 +437,8 @@ class Worker:
428
437
  else:
429
438
  result = encode(output)
430
439
  await self.result(invocation.id, result=result)
440
+ except _QueryCompleted:
441
+ await self.result(invocation.id, result=invocation.params["argument"])
431
442
  except asyncio.CancelledError:
432
443
  await self.result(invocation.id, error=HookCancelled("Plugin call cancelled"), control=True)
433
444
  except BaseException as error:
@@ -592,6 +603,9 @@ class Worker:
592
603
  wire = self.next_wire(slot["result"], access["member"])
593
604
  hook_value(invocation.params["point"], invocation.params["method"], wire, output=True)
594
605
  await self.result(frame["request_id"], result=wire)
606
+ except _QueryCompleted:
607
+ slot["result"] = slot["input"]
608
+ await self.result(frame["request_id"], result=self.next_wire(slot["result"], access["member"]))
595
609
  except BaseException as error:
596
610
  await self.result(frame["request_id"], error=error, control=True)
597
611
 
@@ -14,10 +14,12 @@ def normalize(raw: Any, plugin_id: str, source: Path) -> dict[str, Any]:
14
14
  raw = json.loads(json.dumps(json_value(raw), allow_nan=False))
15
15
  if not re.fullmatch(r"[a-z][a-z0-9_]{0,63}", plugin_id):
16
16
  raise ValueError("Invalid plugin ID")
17
- allowed = {"registration_mode", "plugin_version", "fae_plugin_api_version",
17
+ allowed = {"id", "registration_mode", "plugin_version", "fae_plugin_api_version",
18
18
  "description", "engine", "mounts"}
19
19
  if set(raw) - allowed:
20
20
  raise ValueError("Unknown configuration fields")
21
+ if "id" in raw and raw["id"] != plugin_id:
22
+ raise ValueError("Plugin ID does not match configuration")
21
23
  raw.setdefault("registration_mode", "direct")
22
24
  raw.setdefault("fae_plugin_api_version", API_VERSION)
23
25
  RegistrationMode(raw["registration_mode"])
@@ -1,11 +1,15 @@
1
1
  """Capabilities belong to one PluginCall; public DTOs contain no capability handles."""
2
2
  from __future__ import annotations
3
- from typing import Any
3
+ from typing import Any, NoReturn
4
4
  from .engine import Engine
5
5
  from .session import Session
6
6
  from .types import ContextChildSpec, ContextData, SessionSummary, ContextStack, ContextStackQuery, encode
7
7
 
8
8
 
9
+ class _QueryCompleted(BaseException):
10
+ """Unwind the current query hook after the host accepts its final result."""
11
+
12
+
9
13
  class Context:
10
14
  __slots__ = ("_host", "_binding", "_session_id", "_summary")
11
15
 
@@ -59,6 +63,14 @@ class Context:
59
63
  async def cancel_local(self, reason: str = "Cancelled by plugin") -> None:
60
64
  await self._call("/request/plugin/context/cancel", reason=reason)
61
65
 
66
+ async def complete_query(self, text: str) -> NoReturn:
67
+ """Send final text and successfully end on_query; this call does not return."""
68
+ if not isinstance(text, str) or not text.strip():
69
+ raise ValueError("Query result must be nonempty text")
70
+ await self._call("/request/plugin/context/complete_query", text=text)
71
+ self._host.call_owner.query_completed = True
72
+ raise _QueryCompleted()
73
+
62
74
  async def cancel_execution(self, request_id: str) -> Any:
63
75
  if self.session is None:
64
76
  raise ValueError("Context has no execution")
@@ -0,0 +1,102 @@
1
+ Metadata-Version: 2.4
2
+ Name: fae-plugin-py
3
+ Version: 0.3.0
4
+ Summary: Typed Python plugins for the FAE agent engine
5
+ Author-email: Teshin <1443965173@qq.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Repository, https://github.com/woshihaoren4/free-agent-engine
8
+ Project-URL: Documentation, https://github.com/woshihaoren4/free-agent-engine/tree/v2-plugins/python/fae-plugin-py
9
+ Project-URL: Issues, https://github.com/woshihaoren4/free-agent-engine/issues
10
+ Keywords: fae,agent,plugins,sdk
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Dynamic: license-file
19
+
20
+ # fae-plugin-py
21
+
22
+ FAE Agent Engine 的类型化 Python 插件 SDK,支持 Agent、工具和模型钩子,
23
+ 以及执行上下文读取、Session 输出和子调用。
24
+
25
+ 需要 Python 3.10 或更新版本。SDK 的发行版本与插件 API 版本分别管理;
26
+ 当前插件 API 为 `0.2.0`,使用公共 v4 协议,需要对应版本的 FAE 宿主。
27
+
28
+ ## 安装
29
+
30
+ ```bash
31
+ python3 -m pip install fae-plugin-py
32
+ ```
33
+
34
+ 在仓库根目录进行本地开发:
35
+
36
+ ```bash
37
+ python3 -m pip install -e ./python/fae-plugin-py
38
+ ```
39
+
40
+ 将 SDK 安装到宿主使用的 Python 解释器中。若使用虚拟环境,在启动 FAE 服务前
41
+ 设置 `FAE_PLUGIN_PYTHON` 为该环境的 Python 路径。
42
+
43
+ ## 最小 Agent 插件
44
+
45
+ 保存为 `project_context.py`:
46
+
47
+ ```python
48
+ from fae_plugin import Context, SingleAgentHook, TextContent
49
+
50
+
51
+ def plugin_config() -> dict:
52
+ return {
53
+ "plugin_version": "1.0.0",
54
+ "fae_plugin_api_version": "0.2.0",
55
+ "description": "清理输入并补充项目规范",
56
+ "mounts": [{
57
+ "point": "SingleAgentHook",
58
+ "implementation": "ProjectContext",
59
+ "agent_id": "fae",
60
+ }],
61
+ }
62
+
63
+
64
+ class ProjectContext(SingleAgentHook):
65
+ async def on_query(self, ctx: Context, query: str) -> str:
66
+ if ctx.session is not None:
67
+ await ctx.session.send([TextContent("开始处理请求。")])
68
+ return query.strip()
69
+
70
+ async def on_prompt(self, ctx: Context, prompt: str) -> str:
71
+ return prompt + "\n遵守当前项目的代码规范。"
72
+ ```
73
+
74
+ 安装插件并使用已配置的 `fae` Agent:
75
+
76
+ ```bash
77
+ fae plugin install ./project_context.py
78
+ fae agent --agent-id fae
79
+ ```
80
+
81
+ 目录插件通过 `plugin.config` 声明挂载点,`implementation` 使用
82
+ `plugin.py:ClassName` 格式;单文件插件通过同步的 `plugin_config()` 返回配置。
83
+
84
+ ## 主要接口
85
+
86
+ - `SingleAgentHook`:处理输入、提示词、记忆、历史、模型请求与响应、工具请求与响应。
87
+ - `ToolsHook`:实现 `desc` 和 `exec`,提供工具描述和执行结果。
88
+ - `ModelHook`:实现 `match_model` 和 `exec`,提供模型响应。
89
+ - `ChainSingleAgentHook`、`ChainToolsHook`、`ChainModelHook`:通过 `HookNext`
90
+ 将调用传给后续插件,配置 `registration_mode: "chain"`。
91
+ - `Context`:通过 `read_summary()` 和 `export_context()` 读取公共上下文;
92
+ `execution_id` 和 `invocation_id` 标识当前调用。
93
+ - `Session.send()`:发送由 `TextContent`、`JsonContent` 或 `ResourceContent`
94
+ 组成的内容,并返回输出回执;Session 可能为空,使用前需检查。
95
+ - `Context.complete_query(text)`:在 `on_query` 的原始上下文中发送最终回答并结束执行;
96
+ 此方法不返回,后续查询钩子和模型任务不会继续执行。
97
+
98
+ ## 示例与源码
99
+
100
+ 完整示例见 [插件示例](https://github.com/woshihaoren4/free-agent-engine/tree/v2-plugins/examples/plugin)
101
+ 和 [SDK 示例](https://github.com/woshihaoren4/free-agent-engine/tree/v2-plugins/python/fae-plugin-py/examples)。
102
+ 项目使用 Apache-2.0 许可证。
@@ -21,6 +21,19 @@ from fae_plugin.types import encode
21
21
 
22
22
 
23
23
  class TypesTest(unittest.TestCase):
24
+ def test_directory_declaration_id_is_independent_of_folder_name(self):
25
+ with tempfile.TemporaryDirectory(prefix="Release-") as directory:
26
+ source = Path(directory)
27
+ (source / "plugin.py").write_text("class Demo: pass\n")
28
+ raw = {"id": "demo", "plugin_version": "1.0.0", "description": "Demo",
29
+ "engine": "py", "mounts": [{"point": "ToolsHook",
30
+ "implementation": "plugin.py:Demo"}]}
31
+ result = normalize(raw, "demo", source)
32
+ self.assertEqual(result["id"], "demo")
33
+ self.assertEqual(result["mounts"][0]["channel"], "fae_demo")
34
+ with self.assertRaisesRegex(ValueError, "ID does not match"):
35
+ normalize(raw, "other", source)
36
+
24
37
  def test_memory_and_history_use_registered_business_fields(self):
25
38
  from fae_plugin import MemoryView, SessionMessageRole, UserMemoryCategory
26
39
  value = MemoryView.from_dict({