feat(prompt): 为提示词组件提供注入目标上下文

为了让单个提示词组件在注入到不同目标时能够有不同的行为,现在向组件的执行上下文中传递当前注入的目标提示词名称 (`target_prompt_name`)。

这使得组件可以根据注入点动态调整其生成的内容。例如,一个工具列表组件在注入到 planner prompt 和 reflection prompt 时可以提供不同详尽程度的列表。

主要变更:
- `BasePrompt` 初始化时接收 `target_prompt_name`。
- `PromptComponentManager` 在应用注入规则时会传递此参数。
- `add_injection_rule` 方法现在支持批量添加规则,以简化注册流程。

BREAKING CHANGE: `PromptComponentManager.add_injection_rule` 中 `content_provider` 的函数签名已更改,现在需要接受第二个参数 `target_prompt_name: str`。

旧签名: `async def provider(params: PromptParameters) -> str`
新签名: `async def provider(params: PromptParameters, target_prompt_name: str) -> str
This commit is contained in:
minecraft1024a
2025-11-13 18:18:15 +08:00
parent ce2d1acc7c
commit 69f132a12e
3 changed files with 23 additions and 16 deletions

View File

@@ -194,6 +194,7 @@ class WeatherPrompt(BasePrompt):
async def execute(self) -> str:
# 在实际应用中这里可以调用天气API
# 为了演示,我们返回一个固定的天气信息
logger.info(self.target_prompt_name)
return "当前天气晴朗温度25°C。"
@@ -202,7 +203,7 @@ class HelloWorldPlugin(BasePlugin):
"""一个包含四大核心组件和高级配置功能的入门示例插件。"""
plugin_name = "hello_world_plugin"
enable_plugin = False
enable_plugin = True
dependencies: ClassVar = []
python_dependencies: ClassVar = []
config_file_name = "config.toml"