feat: add public wiki embeds and ES query routing

This commit is contained in:
吉鑫升 committed 2026-08-24 15:21:28 +08:00
1 parent e818c24769
commit bc49df4561
16 files changed
+704 -52

No files matched your search

@@ -271,7 +271,42 @@ answers — and never create a skill silently without user confirmation.
"""
def _build_available_subagents_description(available_names: list[str], bash_available: bool, *, app_config: AppConfig | None = None) -> str:
def _build_es_query_routing_section(
*,
app_config: AppConfig | None = None,
available_skills: set[str] | None = None,
) -> str:
"""Return the configurable ``es_query`` routing rule for the system prompt.
A custom agent with an explicit skill allowlist only receives the rule when
``es_query`` is in that allowlist. The default lead agent has no allowlist,
so the operator-controlled config switch is authoritative there.
"""
if available_skills is not None and "es_query" not in available_skills:
return ""
config = app_config
if config is None:
try:
from deerflow.config import get_app_config
config = get_app_config()
except Exception:
logger.debug("Failed to load es_query routing config", exc_info=True)
return ""
routing = getattr(getattr(config, "skills", None), "es_query_routing", None)
if routing is None or not routing.enabled:
return ""
prompt = (routing.prompt or "").strip()
if not prompt:
return ""
return f'<skill_routing skill="es_query">\n{prompt}\n</skill_routing>'
def _build_available_subagents_description(available_names: list[str], bash_available: bool, *, app_config: AppConfig | None = None) -> str:
"""Dynamically build subagent type descriptions from registry.
Mirrors Codex's pattern where agent_type_description is dynamically generated
@@ -548,9 +583,11 @@ User: "staging"
You: "Deploying to staging..." [proceed]
</clarification_system>
{skills_section}
{bootstrap_section}
{skills_section}
{es_query_routing_section}
{bootstrap_section}
{deferred_tools_section}
@@ -663,10 +700,12 @@ combined with a FastAPI gateway for REST API access [citation:FastAPI](https://f
# style, clarification system, citation rules, response-style / critical-reminder
# defaults) and no personal memory injection. Only the mechanical sections an
# agent still needs to actually use its configured skills/tools are kept.
AGENT_ONLY_PROMPT_TEMPLATE = """{soul}
{network_policy_section}{skills_section}
{deferred_tools_section}
AGENT_ONLY_PROMPT_TEMPLATE = """{soul}
{network_policy_section}{skills_section}
{es_query_routing_section}
{deferred_tools_section}
{writing_mode_section}
@@ -719,12 +758,16 @@ def apply_agent_only_prompt_template(
soul = get_agent_soul(storage_agent_id)
skills_section = get_skills_prompt_section(
available_skills,
app_config=app_config,
display_enabled=rag_mode_enabled,
)
deferred_tools_section = get_deferred_tools_prompt_section(app_config=app_config)
skills_section = get_skills_prompt_section(
available_skills,
app_config=app_config,
display_enabled=rag_mode_enabled,
)
es_query_routing_section = _build_es_query_routing_section(
app_config=app_config,
available_skills=available_skills,
)
deferred_tools_section = get_deferred_tools_prompt_section(app_config=app_config)
n = max_concurrent_subagents
subagent_section = _build_subagent_section(n, app_config=app_config) if subagent_enabled else ""
@@ -766,9 +809,10 @@ RAG/reference display mode is enabled.
)
prompt = AGENT_ONLY_PROMPT_TEMPLATE.format(
soul=soul,
skills_section=skills_section,
deferred_tools_section=deferred_tools_section,
soul=soul,
skills_section=skills_section,
es_query_routing_section=es_query_routing_section,
deferred_tools_section=deferred_tools_section,
writing_mode_section=writing_mode_section,
subagent_section=subagent_section,
network_policy_section=network_policy_section,
@@ -1377,11 +1421,15 @@ def apply_prompt_template(
bootstrap_section = _build_bootstrap_section() if is_bootstrap else ""
# Get skills section
skills_section = get_skills_prompt_section(
available_skills,
app_config=app_config,
display_enabled=rag_mode_enabled,
)
skills_section = get_skills_prompt_section(
available_skills,
app_config=app_config,
display_enabled=rag_mode_enabled,
)
es_query_routing_section = _build_es_query_routing_section(
app_config=app_config,
available_skills=available_skills,
)
# Get deferred tools section (tool_search)
deferred_tools_section = get_deferred_tools_prompt_section(app_config=app_config)
@@ -1438,9 +1486,10 @@ When a search, knowledge, skill, or MCP tool returns a result list:
# Format the prompt with dynamic skills and memory
prompt = SYSTEM_PROMPT_TEMPLATE.format(
agent_name=agent_name or storage_agent_id or "CM 助手",
soul=get_agent_soul(storage_agent_id),
skills_section=skills_section,
bootstrap_section=bootstrap_section,
soul=get_agent_soul(storage_agent_id),
skills_section=skills_section,
es_query_routing_section=es_query_routing_section,
bootstrap_section=bootstrap_section,
deferred_tools_section=deferred_tools_section,
writing_mode_section=writing_mode_section,
memory_context=memory_context,
@@ -5,8 +5,26 @@ from pydantic import BaseModel, Field
from deerflow.config.runtime_paths import project_root, resolve_path
class SecurityScanConfig(BaseModel):
DEFAULT_ES_QUERY_ROUTING_PROMPT = """当用户的问题需要基于 Elasticsearch 查询语句(Query DSL)灵活构造、调整或执行查询时,必须优先使用 `es_query` 技能。
典型场景包括:根据用户条件动态组合 bool/must/filter/should、范围、聚合、排序或分页等 ES 查询;或者用户直接提供、要求修改 ES 语句并据此查询数据。
执行前先读取 `es_query` 技能的 SKILL.md,严格按照技能中的流程和参数调用;不要用通用搜索替代,也不要凭记忆臆测查询结果。
仅当问题确实需要 ES 数据查询时使用;纯概念解释、普通代码说明或与 ES 无关的问题不要调用。"""
class EsQueryRoutingConfig(BaseModel):
"""Prompt steering that routes flexible Elasticsearch queries to ``es_query``."""
enabled: bool = Field(
default=False,
description="Inject the es_query routing prompt into the agent system prompt.",
)
prompt: str = Field(
default=DEFAULT_ES_QUERY_ROUTING_PROMPT,
description="Editable system-prompt instructions for deciding when and how to use es_query.",
)
class SecurityScanConfig(BaseModel):
"""Toggle for the LLM-based skill security scanner."""
enabled: bool = Field(
@@ -33,10 +51,14 @@ class SkillsConfig(BaseModel):
default="/mnt/skills",
description="Path where skills are mounted in the sandbox container",
)
security_scan: SecurityScanConfig = Field(
default_factory=SecurityScanConfig,
description="LLM security-scan toggle for skill content.",
)
security_scan: SecurityScanConfig = Field(
default_factory=SecurityScanConfig,
description="LLM security-scan toggle for skill content.",
)
es_query_routing: EsQueryRoutingConfig = Field(
default_factory=EsQueryRoutingConfig,
description="Optional configurable routing prompt for the es_query skill.",
)
def get_skills_path(self) -> Path:
"""