代码修改
This commit is contained in:
1 parent
5a25dd08f6
commit
e8a31b5d37
9 files changed
+533
-417
No files matched your search
@@ -152,10 +152,12 @@ _CONTEXT_CONFIGURABLE_KEYS: frozenset[str] = frozenset(
|
||||
"model_name",
|
||||
"mode",
|
||||
"thinking_enabled",
|
||||
"reasoning_effort",
|
||||
"writing_mode",
|
||||
"writing_artifact_path",
|
||||
"is_plan_mode",
|
||||
"reasoning_effort",
|
||||
"writing_mode",
|
||||
"writing_artifact_path",
|
||||
"canvas_artifact_title",
|
||||
"canvas_artifact_type",
|
||||
"is_plan_mode",
|
||||
"subagent_enabled",
|
||||
"max_concurrent_subagents",
|
||||
"agent_name",
|
||||
|
||||
+15
-3
@@ -5,7 +5,7 @@ import logging
|
||||
from langchain.agents import create_agent
|
||||
from langchain_core.runnables import RunnableConfig
|
||||
|
||||
from deerflow.agents.canvas_agent.prompt import CANVAS_SYSTEM_PROMPT
|
||||
from deerflow.agents.canvas_agent.prompt import build_canvas_system_prompt
|
||||
from deerflow.agents.canvas_agent.tools import update_artifact_tool
|
||||
from deerflow.agents.middlewares.clarification_middleware import ClarificationMiddleware
|
||||
from deerflow.agents.middlewares.dangling_tool_call_middleware import DanglingToolCallMiddleware
|
||||
@@ -49,7 +49,19 @@ def make_canvas_agent(config: RunnableConfig):
|
||||
if thinking_enabled and model_config and not model_config.supports_thinking:
|
||||
thinking_enabled = False
|
||||
|
||||
logger.info("Create CanvasAgent -> model_name: %s, thinking_enabled: %s", model_name, thinking_enabled)
|
||||
canvas_artifact_title = cfg.get("canvas_artifact_title") or None
|
||||
canvas_artifact_type = cfg.get("canvas_artifact_type") or None
|
||||
system_prompt = build_canvas_system_prompt(
|
||||
artifact_title=canvas_artifact_title,
|
||||
artifact_type=canvas_artifact_type,
|
||||
)
|
||||
|
||||
logger.info(
|
||||
"Create CanvasAgent -> model_name: %s, thinking_enabled: %s, artifact_title: %s",
|
||||
model_name,
|
||||
thinking_enabled,
|
||||
canvas_artifact_title,
|
||||
)
|
||||
|
||||
middlewares = [
|
||||
DanglingToolCallMiddleware(),
|
||||
@@ -63,6 +75,6 @@ def make_canvas_agent(config: RunnableConfig):
|
||||
model=create_chat_model(name=model_name, thinking_enabled=thinking_enabled, app_config=app_config),
|
||||
tools=[update_artifact_tool, ask_clarification_tool],
|
||||
middleware=middlewares,
|
||||
system_prompt=CANVAS_SYSTEM_PROMPT,
|
||||
system_prompt=system_prompt,
|
||||
state_schema=ThreadState,
|
||||
)
|
||||
+20
-2
@@ -1,4 +1,18 @@
|
||||
CANVAS_SYSTEM_PROMPT = """You are a Canvas AI assistant that helps users create and edit documents and code.
|
||||
def build_canvas_system_prompt(
|
||||
artifact_title: str | None = None,
|
||||
artifact_type: str | None = None,
|
||||
) -> str:
|
||||
existing_artifact_block = ""
|
||||
if artifact_title:
|
||||
type_label = "代码" if artifact_type == "code" else "文档"
|
||||
existing_artifact_block = f"""
|
||||
<existing_artifact>
|
||||
用户当前有一个{type_label}制品,标题为 "{artifact_title}"。
|
||||
请继续编辑该制品——除非用户明确要求新建,否则不要创建新制品。
|
||||
</existing_artifact>
|
||||
"""
|
||||
|
||||
return f"""You are a Canvas AI assistant that helps users create and edit documents and code.
|
||||
|
||||
<canvas_behavior>
|
||||
You work with an **artifact** — a document or code file shown in the canvas panel on the right.
|
||||
@@ -14,7 +28,7 @@ Rules:
|
||||
The current artifact state is injected into your context. When editing, build on the existing content exactly.
|
||||
When creating from scratch, produce a complete, high-quality artifact in one shot.
|
||||
</artifact_context>
|
||||
|
||||
{existing_artifact_block}
|
||||
<selection_rewrite>
|
||||
When the user's message contains a <selection> block, you MUST:
|
||||
1. Identify the exact selection in the current artifact content.
|
||||
@@ -38,3 +52,7 @@ When the user triggers a quick action, apply it to the full artifact unless spec
|
||||
- optimize_code: Improve performance and readability
|
||||
</quick_actions>
|
||||
"""
|
||||
|
||||
|
||||
# Backward-compatible constant for callers that don't pass artifact context.
|
||||
CANVAS_SYSTEM_PROMPT = build_canvas_system_prompt()
|
||||
Reference in new issue
Block a user