feat: enhance prompt variable resolver with agent_react scene support [AC-IDMP-PROMPT]
This commit is contained in:
parent
f823e8fb86
commit
9198f4dfb3
|
|
@ -85,6 +85,7 @@ export const SCENE_OPTIONS = [
|
|||
{ value: 'summary', label: '摘要场景' },
|
||||
{ value: 'translation', label: '翻译场景' },
|
||||
{ value: 'code', label: '代码场景' },
|
||||
{ value: 'agent_react', label: 'Agent ReAct 场景' },
|
||||
{ value: 'custom', label: '自定义场景' }
|
||||
]
|
||||
|
||||
|
|
@ -98,5 +99,6 @@ export const BUILTIN_VARIABLES: PromptVariable[] = [
|
|||
{ name: 'user_name', description: '用户名称' },
|
||||
{ name: 'context', description: '检索上下文' },
|
||||
{ name: 'query', description: '用户问题' },
|
||||
{ name: 'history', description: '对话历史' }
|
||||
{ name: 'history', description: '对话历史' },
|
||||
{ name: 'available_tools', description: '可用工具列表(Agent ReAct 场景专用,自动注入已注册工具的名称、描述和参数)' }
|
||||
]
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import re
|
|||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from app.core.middleware import PROMPT_PROTECTED_VARIABLES
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
VARIABLE_PATTERN = re.compile(r"\{\{(\w+)\}\}")
|
||||
|
|
@ -18,6 +20,11 @@ BUILTIN_VARIABLES = {
|
|||
"channel_type": "default",
|
||||
"tenant_name": "平台",
|
||||
"session_id": "",
|
||||
"available_tools": "",
|
||||
"query": "",
|
||||
"history": "",
|
||||
"internal_protocol": "",
|
||||
"output_contract": "",
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -92,10 +99,18 @@ class VariableResolver:
|
|||
for var in variables:
|
||||
name = var.get("name")
|
||||
default = var.get("default", "")
|
||||
if name:
|
||||
if not name:
|
||||
continue
|
||||
if name in PROMPT_PROTECTED_VARIABLES:
|
||||
logger.warning(
|
||||
"Protected prompt variable '%s' cannot be overridden by template defaults",
|
||||
name,
|
||||
)
|
||||
continue
|
||||
context[name] = default
|
||||
|
||||
if extra_context:
|
||||
# Runtime/system context has the highest priority, including protected vars.
|
||||
context.update(extra_context)
|
||||
|
||||
return context
|
||||
|
|
|
|||
Loading…
Reference in New Issue