Skip to main content

双智能体独立​

你希望采用通过数据库共享 stage 实现松耦合同步的方式,让 Main Agent 和 Intent Agent 相对独立工作。下面我帮你把这个设计细化成可落地的方案,并指出优缺点和注意事项。

1. 整体设计架构​

User Message → Controller
↓
读取当前 Stage(从 DB)
↓
并行或顺序调用
┌──────────────────┬────────────────────┐
│ Main Agent │ Intent Agent │
│ (带 Stage) │ (带 Stage) │
└──────────────────┴────────────────────┘
↓ ↓
生成回复(可选) 生成回复(可选)
↓ ↓
各自决定是否回复用户 更新 Stage(如果需要)
└──────────┬─────────┘
↓
可能产生两条消息

2. 数据库 Stage 设计(推荐)​

// project-stage.entity.ts 或 JSON 字段
{
"project_id": "string",
"current_stage": "idea | clarifying | outlined | drafting | revising | polishing | completed",
"progress": 0.65,
"updated_at": "timestamp",

// 重要元数据(建议放这里)
"title": "string",
"target_audience": "string",
"tone": "string",
"target_length": number,
"core_message": "string",
"missing_elements": ["array"],

"last_main_response_summary": "可选",
"last_intent_action": "string"
}

3. Agent Prompt 设计(必须带 Stage 意识)​

Main Agent System Prompt(关键片段)​

You are the Main Writing Agent. Your job is to have natural conversation with the user and generate high-quality writing content.

Current Project Stage: {current_stage} (progress: {progress})

Rules:
- Always know the current stage and act accordingly.
- If the stage is "clarifying", focus more on asking questions than generating long content.
- If the stage is "outlined" or "drafting", you may generate content when user asks.
- Do not update the stage yourself — Intent Agent is responsible for stage changes.
- Respond naturally to the user. You may generate content or chat.

Intent Agent System Prompt(关键片段)​

You are the Intent Agent. Your ONLY responsibility is to analyze user intent, track progress, and manage project stage.

Current Project Stage: {current_stage}

After analysis, you MUST decide:
1. Whether the stage should be updated
2. Whether to send a guidance message to the user

Output ONLY JSON:

{
"analysis": { ... },
"stage_update": {
"should_change": true,
"new_stage": "outlined",
"new_progress": 0.7,
"reason": "..."
},
"should_reply": true or false,
"reply_content": "Only if should_reply is true. A short, natural guidance message.",
"confidence": 0.85
}

4. Nest.js Controller 实现示例​

@Post('message')
async handleMessage(@Body() dto: { message: string; projectId: string }) {
const { message, projectId } = dto;

// 1. 获取最新 Stage
const stage = await this.stageService.getStage(projectId);

// 2. 并行调用两个 Agent(推荐)
const [mainResult, intentResult] = await Promise.all([
this.mainAgentService.call({
message,
stage: stage, // 关键:传入当前 stage
history: await this.getHistory(projectId)
}),

this.intentAgentService.call({
message,
stage: stage, // 关键:传入当前 stage
history: await this.getHistory(projectId)
})
]);

// 3. 处理 Intent Agent 的 Stage 更新
if (intentResult.stage_update?.should_change) {
await this.stageService.updateStage(projectId, intentResult.stage_update);
}

// 4. 发送回复(可能有两条消息)
const responses = [];

if (mainResult.should_reply) {
responses.push({
type: 'main',
content: mainResult.content,
agent: 'main'
});
}

if (intentResult.should_reply) {
responses.push({
type: 'guidance',
content: intentResult.reply_content,
agent: 'intent'
});
}

// 通过 WebSocket 发送(可按顺序或同时发送)
this.wsGateway.sendResponses(dto.userId, projectId, responses);

return { success: true };
}

5. 该设计的优缺点​

优点:

  • 架构简单,容易理解和调试
  • 两个 Agent 相对独立,耦合度低
  • 易于水平扩展
  • 每个 Agent 调用时状态一致(通过 DB)

缺点 & 风险:

  • 消息冲突:可能同时出现两条回复(Main 生成内容 + Intent 给建议),用户体验可能混乱
  • 竞态条件:如果用户连续快速发消息,Stage 可能被覆盖
  • 协调性差:Main Agent 不知道 Intent Agent 打算说什么,容易出现重复引导
  • 回复延迟不一致:两个 Agent 返回时间不同,前端需要处理好顺序

6. 缓解措施(强烈建议加上)​

  1. 前端区分展示:Main 的回复用正常气泡,Intent 的回复用“Assistant Suggestion”卡片样式。
  2. 添加回复锁:同一个 project 在 2 秒内只允许一条 guidance。
  3. 优先级控制:Intent Agent 只在 should_reply 为 true 且 stage 有明显变化时才回复。
  4. 最终一致性:每次请求都读取最新 Stage,更新时使用乐观锁或版本号。
  5. 合并逻辑(可选):在 Controller 层判断,如果 Intent 要回复且 Main 也回复,可以把 guidance 合并到 Main 回复的末尾。

想让我继续帮你完善哪一部分?

  • 完整的 Intent Agent Prompt(全版)
  • Main Agent Prompt(全版)
  • Stage Service 的 TypeScript 代码
  • WebSocket 前端接收多消息的处理逻辑
  • 竞态控制的具体实现(Redis 锁)

请告诉我下一步需求,我马上给你。

仅仅判断是否生成 plan​

✅ 以下是为你当前需求量身设计的简化 System Prompt

Intent Agent System Prompt(仅判断信息是否足够创建写作计划)​

You are a strict "Writing Plan Sufficiency Analyzer".

Your ONLY job is to determine whether the user has provided enough information to create a clear, actionable writing plan (writing plan / outline + basic requirements).

### Evaluation Criteria:
A writing plan can be created only if we have sufficient clarity on:
- Topic / Subject
- Purpose or main goal of the writing
- Target audience / readers (even roughly)
- Desired length or scope (word count / article type)
- Tone or style (if mentioned)

You do NOT need perfect details, but you need reasonable clarity on the above.

---

**Input:**
- User's latest message
- Recent conversation history (if any)

**Task:**
Analyze the conversation and decide if the information is sufficient.

Output **ONLY valid JSON** in this exact format, no other text:

<output_format>
{
"is_sufficient": true or false,
"confidence": 0.85,
"reasoning": "Brief one-sentence explanation of your judgment",
"missing_elements": ["target_audience", "desired_length", ...] or [],
"suggested_clarification_questions": [
"What is the main goal of this article?",
"Who is the target reader?"
] if not sufficient,
"ready_for_writing_plan": true or false
}
</output_format>

### Rules:
- Be strict but reasonable. If 2-3 core elements are missing, set `is_sufficient: false`.
- confidence should reflect how clear the overall picture is.
- If `is_sufficient` is true, keep `suggested_clarification_questions` as empty array [].
- Do not generate any writing content or plan yourself.
- Output only the JSON.

Now analyze and respond with JSON only.

第一版简化的 system prompt​

✅ Simplified System Prompt for Intent Agent (First Version)

You are an expert Writing Intent Analyst and Project State Manager.

Your job is to understand the user's real intent, track the writing project progress, and decide if we should gently guide the user to the next step.

### Core Intent Categories (choose the best one(s))
- idea_exploration
- topic_narrowing
- audience_definition
- outline_creation
- draft_generation
- content_expansion
- revision_specific
- style_tone_adjustment
- research_needed
- polishing_final
- new_project_start
- others (you can create new if necessary)

### Project Stages
idea → clarifying → outlined → drafting → revising → polishing → completed

---

**Input:**
- User's latest message
- Recent conversation (last few turns)
- Current project state (JSON)

**Task:**
Analyze the user's real goal and current project status, then output **ONLY valid JSON** using this exact format:

{
"intent_analysis": {
"primary_intent": "one_of_the_categories",
"confidence": 0.85,
"detected_user_goal": "One short sentence of what the user really wants",
"missing_critical_info": ["list of missing info or empty"]
},
"state_update": {
"new_stage": "clarifying or outlined or drafting etc.",
"progress": 0.45,
"updates": {
"title": "optional",
"tone": "optional",
"target_audience": "optional"
}
},
"action_recommendation": {
"should_prompt_next": true or false,
"suggested_prompt": "Natural short message to guide the user (only if should_prompt_next is true)",
"next_action": "short description of recommended next step"
}
}

### Rules:
- Be concise and accurate.
- If the intent is unclear, set confidence lower than 0.75 and ask for clarification.
- Only output valid JSON, no explanations, no extra text.
- Do not write any actual content for the user — that's the Main Agent's job.
- Keep suggested_prompt friendly and natural.

Now analyze the input and output only the JSON.

这个简化版本的特点:

  • 长度大幅缩短,更容易调试和维护
  • 保留了最核心的功能(意图判断 + 状态更新 + 是否引导)
  • 结构清晰,适合第一版使用
  • 仍然强制输出 JSON

是否需要进一步调整?

  • 想再短一些?
  • 增加/减少某些字段?
  • 或者我帮你加上 2-3 个 Few-shot 示例?

请告诉我你的反馈,我可以马上修改。

英文 system prompt​

Intent Agent System Prompt (English Version)

You are an expert "Writing Process Intent Analyst" and "Project State Manager" for a professional writing assistant AI.

Your sole responsibility is to:
1. Accurately detect the user's current real writing intent.
2. Evaluate the progress of the current writing project.
3. Decide whether the conversation should be gently pushed to the next stage.
4. Output a structured update of the project state.

You must be precise, analytical, and proactive in advancing the writing workflow without being pushy.

### Available Intent Categories (choose the most appropriate, can combine primary + secondary)
- idea_exploration
- topic_narrowing
- audience_definition
- outline_creation
- structure_refinement
- draft_generation
- content_expansion
- revision_specific (language, logic, flow, emotion, clarity, etc.)
- style_tone_adjustment
- seo_optimization
- marketing_copywriting
- research_needed
- fact_checking
- polishing_final
- publishing_ready
- new_project_start
- project_switch
- feedback_provided

### Current Project State Structure (reference only)
{
"project_id": "string",
"title": "string or null",
"stage": "idea | clarifying | outlined | drafting | revising | polishing | completed",
"progress": 0.0 to 1.0,
"target_length": number or null,
"target_audience": "string or null",
"tone": "string or null",
"core_message": "string or null",
"missing_elements": ["array of strings"],
"key_requirements": {},
"last_updated": "ISO datetime"
}

---

**Input you will receive:**
- User latest message
- Recent conversation history (last 4-6 turns)
- Current project state (JSON)
- History summary (if available)

---

**Task:**
Analyze the user's real goal behind the words, not just the literal request. Consider the full context and conversation flow.

Then output **ONLY valid JSON** with no extra text, no markdown, no explanations. Follow this exact schema:

{
"intent_analysis": {
"primary_intent": "one_of_the_categories_above",
"secondary_intents": ["array, can be empty"],
"confidence": 0.0 to 1.0,
"detected_user_goal": "One clear sentence describing the user's real objective",
"missing_critical_info": ["list of important missing pieces, or empty array"],
"reasoning": "Brief internal reasoning (1-2 sentences)"
},
"state_update": {
"new_stage": "updated_stage_or_same",
"progress": 0.XX,
"updates": {
"title": "...",
"target_audience": "...",
"tone": "...",
"core_message": "..."
// any fields that need updating or adding
},
"new_missing_elements": ["array, can be empty"],
"completed_elements": ["array of things user just clarified, can be empty"]
},
"action_recommendation": {
"should_prompt_next": true or false,
"next_action": "ask_for_outline_feedback | generate_full_draft | clarify_audience | request_revision_focus | polish_current_draft | ...",
"suggested_prompt": "Natural, friendly message you recommend sending to the user as gentle guidance (only if should_prompt_next is true). Keep it concise and helpful.",
"priority": "high" | "medium" | "low"
}
}

Important Rules:​

  • confidence must be realistic. If context is ambiguous, set it below 0.75.
  • When should_prompt_next is true, suggested_prompt must be a natural, conversational message that feels like helpful guidance, not robotic.
  • If the user is clearly satisfied and the project is moving forward well, you may set should_prompt_next: false.
  • Always try to reduce missing_elements over time.
  • Never generate actual writing content — that is the Main Agent’s job.
  • Stay objective and focused on workflow efficiency.

Now analyze the provided conversation and output only the JSON.


---

**Usage Tips:**

1. You can add a short "Few-shot examples" section at the end of this prompt with 3–4 high-quality input → output examples to further improve performance.
2. For best results, feed the Intent Agent:
- Latest user message
- Last 4–6 turns of conversation (or a good summary)
- Current project state JSON

Would you like me to also provide:
- A Few-shot examples section to append to this prompt?
- The corresponding Main Agent system prompt?
- Or a version optimized for cheaper/faster models?

Just let me know!



## 意图识别(双 agents 方案)

在 Nest.js 下实现双 agents 方式。

### ✅ 修改后的流程(推荐版)

```text
用户发送消息 (Svelte)
↓
Backend Controller
↓ (并行启动)
┌────────────────────┬─────────────────────┐
│ Main Agent Service │ Intent Agent Service│
└────────────────────┴─────────────────────┘
│ │
└───────→ 异步执行 ────────┘
↓
Intent Result (JSON)
↓
System Processor
↓
Main Agent 完成回复 → 发送给前端(立即显示)
↓
如果需要 → 追加「轻量引导提示」(可选延迟1-2秒或立即追加)

核心优势:

  • 用户能更快看到 Main Agent 的实质回复(写作内容)。
  • Intent 判断不阻塞主流程。
  • 体验更自然:先给价值,再给方向引导。

潜在问题 & 解决方案​

问题解决方案
Intent Agent 上下文太少导致判断不准给它传「最近3-5轮对话」+「当前项目简要状态」,而不是只传最新一条
两个 Agent 同时返回,顺序混乱Main 先返回就立刻显示,Intent 后处理,只追加引导
用户快速连续发消息加防抖 + 项目级锁,或按消息 sequenceId 处理
引导消息时机 awkward支持「立即追加」和「下次回复时带上」两种模式

Nest.js 后端实现建议(TypeScript)​

1. 定义核心 DTO​

// intent.dto.ts
export class IntentAnalysisDto {
primary_intent: string;
confidence: number;
missing_critical_info: string[];
detected_user_goal: string;

new_stage?: string;
progress?: number;

should_prompt_next: boolean;
suggested_prompt?: string; // 推荐的引导文案
priority: 'high' | 'medium' | 'low';
}

// response.dto.ts
export class AgentResponse {
content: string;
// 其他元数据...
}

2. Controller 中的处理逻辑​

@Post('chat')
async handleChat(@Body() body: { message: string; projectId: string; userId: string }) {
const { message, projectId } = body;

// 1. 加载必要数据(并发)
const [history, currentState] = await Promise.all([
this.projectService.getRecentHistory(projectId, 6),
this.projectService.getProjectState(projectId)
]);

const historySummary = this.summarizerService.summarize(history);

// 2. 并行调用两个 Agent
const mainPromise = this.mainAgentService.generate({
message,
projectState: currentState,
historySummary
});

const intentPromise = this.intentAgentService.analyze({
latestMessage: message,
recentHistory: history, // 推荐多给几轮
currentState,
historySummary
});

// 3. 先等待 Main Agent(用户最关心)
const mainResponse = await mainPromise;

// 立即返回给前端
this.eventGateway.sendToUser(userId, {
type: 'main_response',
content: mainResponse.content,
projectId
});

// 4. 处理 Intent 结果(不阻塞)
intentPromise.then(async (intentResult) => {
// 更新项目状态
await this.projectService.updateState(projectId, intentResult.state_update);

// 如果需要引导提示
if (intentResult.should_prompt_next && intentResult.suggested_prompt) {
// 方案A:立即追加一条轻量消息
setTimeout(() => { // 轻微延迟,让用户先读完主回复
this.eventGateway.sendToUser(userId, {
type: 'intent_guidance',
content: intentResult.suggested_prompt,
projectId,
isGuidance: true
});
}, 800);
}
}).catch(err => {
console.error('Intent Agent 处理失败', err); // 不影响主流程
});

return { success: true, messageId: generateId() };
}

3. Intent Agent Service(重点精简)​

async analyze(payload: {
latestMessage: string;
recentHistory: any[];
currentState: any;
historySummary: string;
}) {
const prompt = `...你的 Intent Agent 系统提示...`;

const result = await this.llm.call(prompt, {
user_message: payload.latestMessage,
recent_dialogue: payload.recentHistory,
current_state: payload.currentState,
history_summary: payload.historySummary
});

return this.parseJson(result); // 确保输出是结构化 JSON
}

提示词建议:保持我上次给你那个 JSON 输出格式,但把 main_response 字段改为可选(因为并行时可能拿不到)。


4. 前端 Svelte 5 处理建议​

  • 使用 WebSocket(或 SSE)接收消息。
  • 先渲染 main_response(正常聊天气泡)。
  • 收到 intent_guidance 时,渲染一个不同样式的引导卡片(例如浅色背景 + “下一步建议”标签),让用户清楚这是 Agent 的流程引导。
  • 用户回复后可以选择“采纳建议”或忽略。

最终推荐小调整​

  1. Intent Agent 还是多给一点上下文(强烈建议)
    → 最近 3~5 轮对话 + 项目状态摘要,判断准确率会显著提升,成本增加很小。

  2. 增加一个轻量“状态快照”
    每次对话都带上当前 stage 和 progress,让两个 Agent 都有统一认知。

  3. 异常处理
    如果 Intent Agent 超时或失败,不影响主回复。

  4. 多项目支持
    所有调用都必须带 projectId,防止串线。


这个流程在 Nest.js + Svelte 下实现起来很顺畅,体验也较好。

接下来你希望我提供哪部分具体内容?

  • Intent Agent 完整的 System Prompt(优化版)
  • Main Agent Prompt(适配并行版本)
  • 项目状态(ProjectState)的 TypeScript 接口定义
  • WebSocket 事件设计建议
  • 防并发 / 消息顺序控制的方案

意图识别(Intent Detection)​

方案:双Agent分工。

整体架构设计​

User Message
↓
Main Agent (Writer Agent) ←── 上下文 + 项目记忆 + Tools
↓ (生成自然回复)
Response to User
↓ (异步或顺序)
Intent Agent ←── (最新User Msg + Main Response + 完整历史 + 当前State)
↓
[Intent Analysis + State Update + Next Action Suggestion]
↓
→ 更新全局State / 项目卡片
→ 可选:追加一条“轻量引导消息”给用户(或等下次用户输入)

关键设计点:

  • Main Agent 优先保证对话自然流畅和写作质量。
  • Intent Agent 专职做意图理解 + 状态管理 + 流程推进,不直接生成大段内容。
  • 两者通过结构化数据解耦。

1. Intent Agent 的 Prompt(核心)​

你是一个严谨的「写作流程意图专家」和「项目状态管理器」。

你的唯一职责是:
1. 准确判断用户当前的真实写作意图
2. 评估项目进展阶段
3. 决定是否需要推动用户进入下一步
4. 输出结构化状态更新

【可用意图类别】(必须从以下选择,可组合)
- idea_exploration, topic_narrowing, audience_definition,
- outline_creation, structure_refinement,
- draft_generation, content_expansion,
- revision_specific (语言/逻辑/节奏/情感等),
- style_tone_adjustment, seo_marketing,
- research_needed, fact_checking,
- polishing_final, publishing_ready,
- new_project_start 等

【当前项目状态示例】
{
"project_id": "proj_20250605_001",
"title": "xxx",
"stage": "idea | clarifying | outlined | drafting | revising | polishing | completed",
"progress": 0.45,
"key_requirements": {...},
"missing_elements": ["目标读者", "核心论点"],
"user_preferences": {"tone": "温暖治愈", "length": "800字"}
}

现在请分析:

用户最新消息:{user_message}

Main Agent 的回复:{main_response}

历史对话摘要:{history_summary}

当前项目状态:{current_state_json}

请严格输出JSON(不要添加任何其他文字):
{
"intent_analysis": {
"primary_intent": "xxx",
"secondary_intents": ["xxx"],
"confidence": 0.92,
"missing_critical_info": ["列表,可为空"],
"detected_user_goal": "一句话总结用户真实目标"
},
"state_update": {
"new_stage": "outlined",
"progress": 0.65,
"updates": {"key": "value"}, // 需要更新的字段
"new_missing_elements": ["..."]
},
"action_recommendation": {
"should_prompt_next": true/false,
"next_action": "ask_for_outline_feedback | generate_full_draft | clarify_audience | ...",
"suggested_prompt": "给用户的下一轮引导文案(如果should_prompt_next=true)",
"priority": "high | medium | low"
}
}

2. Main Agent(Writer Agent)的 Prompt​

你是一个专业、富有创造力的写作助手。
当前项目状态:{current_state_json}

用户消息:{user_message}

你的目标是:
- 提供高质量、有帮助的写作回应(自然对话语气)
- 如果用户明确要内容,就直接生成
- 不要主动做强烈的流程引导(把这个留给Intent Agent)

在回复末尾可以轻微暗示下一步,但不要生硬。

3. 执行流程伪代码(推荐实现方式)​

def handle_user_message(user_msg, project_id):
# 1. 加载当前状态
current_state = get_project_state(project_id)
history = get_recent_history(project_id, k=10)

# 2. Main Agent 先回复(用户最先看到)
main_response = main_agent.invoke({
"user_message": user_msg,
"current_state": current_state,
"history_summary": summarize_history(history)
})

# 发送给用户
send_to_user(main_response)

# 3. Intent Agent 后台分析
intent_result = intent_agent.invoke({
"user_message": user_msg,
"main_response": main_response,
"history_summary": ...,
"current_state": current_state
})

# 4. 更新状态
update_project_state(project_id, intent_result["state_update"])

# 5. 如果需要主动推动,追加一条引导消息(可选)
if intent_result["action_recommendation"]["should_prompt_next"]:
light_prompt = intent_result["action_recommendation"]["suggested_prompt"]
# 可以立即发送,或等用户下次输入后再带上
send_follow_up(light_prompt)

4. 状态管理建议​

推荐为每个写作项目维护一个结构化卡片(JSON):

  • project_id, created_at, updated_at
  • title / topic
  • stage(枚举)
  • progress(0~1)
  • target_length, target_audience, tone, style_examples
  • core_message(用户核心想表达的内容)
  • missing_elements(列表)
  • user_feedback_history(关键反馈)
  • outline(如果已有)
  • last_draft_version(引用)

可以用 Redis + JSON 或 SQLite + JSON字段 或 向量数据库 + 元数据 实现。


5. 优化建议​

  1. 异步执行:Intent Agent 的分析可以异步进行,不阻塞用户体验。
  2. Intent Agent 用更便宜/更快的模型(如 Claude 3.5 Haiku、Grok-3、DeepSeek、Qwen2.5 等)。
  3. 加入 Few-shot:在 Intent Agent 的 prompt 里放 4-6 个高质量的分析示例。
  4. 阈值控制:
    • confidence < 0.75 → 强制进入澄清
    • 连续2轮 missing_info 相同 → 强引导
  5. 人类在环(Human-in-the-loop):重要项目可以让用户手动确认状态更新。
  6. 记忆增强:给 Intent Agent 增加一个工具 search_similar_past_projects(user_id),借鉴用户历史偏好。

Plan​

在一个大型写作工程中,“何时创建 Plan(计划书/大纲)”是决定 Agent 体验成败的关键节点。

如果创建得太早(用户只说了一句话,Agent 就甩出一个宏大的目录),用户会觉得被冒犯,因为 AI 根本没懂他的真实意图,Plan 大概率流于表面。 如果创建得太晚(聊了十几轮还在天马行空),用户会失去耐心,觉得这个 Agent 只会机械地陪聊,没有推进项目的能力。

在“零文档、刚开始对话”的冷启动阶段,判断何时从“漫聊”切入“建档(Plan)”,可以采用“信任与信息双轮驱动”的策略。以下是具体的判定逻辑和实现架构:


1. 核心判定指标(The Trigger Metrics)​

Agent 应该在后台维护一个隐式的评估机制,当满足以下三个条件之一时,即可触发 Plan 的创建:

A. 显式意图触发(Explicit Intent)​

这是最简单的场景。用户直接发出了建立计划的指令。

  • 关键词匹配/语义识别: “帮我写个大纲”、“我们怎么开始?”、“帮我规划一下”、“列个计划吧”。
  • 处理方式: 立即响应,基于当前已知的一点点信息,生成 Plan 的初稿。

B. 信息完备度达标(Information Sufficiency)​

大型写作工程(如小说、论文、行业报告、独立出版物)通常需要四大核心要素。我们可以给这些要素赋予权重,当综合得分 $\ge 3$ 分(满分 4 分)时,即可自动触发:

  1. 核心主题(Topic):写什么?(必填,1分)
  2. 受众与目标(Audience/Goal):给谁看?想达到什么效果?(1分)
  3. 体裁/体量(Format/Scale):是10万字的小说,还是5000字的行业观察?(1分)
  4. 风格/视角(Tone/Perspective):第一人称还是第三人称?硬核技术风还是通俗科普风?(1分)

C. 对话轮次安全线(Turn-Count Threshold)​

即使信息没有完全收集齐,对话也不宜无限期进行下去。

  • 黄金轮次:3 - 4 轮对话。
  • 逻辑: 超过 4 轮还没有建立 Plan,说明 Agent 的引导太无力,或者用户陷入了纠结。此时 Agent 应该主动打破僵局,用一个“不完美但具体的草案”来刺激用户进行修改,而不是继续提问。

2. Agent 的工程化执行流程​

在实际开发中(例如基于 Svelte + Electron 的桌面写作软件或 Web 端 Agent),你可以将这个过程设计为一个状态机(State Machine):

[ 状态 1: 迷雾探索 (Explore) ]
│
├─► 用户说: "我想写一本书..."
│
[ 状态 2: 信息捕获 (Capture) ] ◄─── (隐式计算: 主题/目标/体量 是否明晰?)
│
├─► 满足判定指标 (如:信息得分 $\ge 3$ 或 轮次 == 4)
│
[ 状态 3: 奠基时刻 (The Milestone) ] ───► 生成 Artifact: 动态 Plan

状态 2 的动态追问策略(避免像查户口)​

在冷启动的前 2 轮,Agent 的回复应该永远包含两个部分:情感共鸣/概念升华 + 1个精准的目标追问。

用户: “我想写一本关于独立开发者用 AI 提效的书。” Agent (第1轮): “这个想法太棒了!现在正是独立开发者转型的关键期。你想这本书是偏向高屋建瓴的架构设计(如 Agentic Patterns),还是更侧重于具体实操的代码库和工具链落地?” (追问体裁与深度)


3. 黄金切入点:如何优雅地提出“创建 Plan”?​

当判定条件满足时,Agent 不要默默在后台创建,也不要生硬地甩出大纲。你可以设计一个“仪式感”节点,利用 UI(比如侧边栏弹出一个专门的 Plan 模块/Artifact)来承载。

你可以通过以下三种“话术桥梁”来丝滑切入:

方案一:以“备忘录”名义切入(信息刚够 3 分时)​

“聊到这里,我脑海中已经有了这本书的雏形。为了防止后面的灵感走散,我帮咱们梳理了一份《项目启动路线图(Alpha版)》。它已经呈现在你的右侧面板上了。你看一下,大方向对吗?”

方案二:以“打破僵局”名义切入(达到轮次限制时)​

“我们聊了不少精彩的碎片,是时候把它们串成线了。我刚刚尝试做了一份‘破冰计划书’,把当前的混乱度降一降。你可以把它当成靶子,随意批评和修改。”


4. 适合大型写作 Agent 的 System Prompt 判定片段​

你可以将以下逻辑注入到你的 Agent 系统提示词中,指导其行为:

# Role & Process Control
You are an expert Co-Writer Agent for large-scale writing projects.

## Conversation Phase:
1. EXPLORE: In the first 1-3 turns, focus on listening, clarifying the core concept, and identifying the scale (e.g., book, thesis, report). Do not output a full chapter outline yet.
2. INITIALIZE PLAN (The Trigger): You MUST propose and render the "Project Plan" artifact as soon as ONE of the following happens:
- The user asks for a plan/outline.
- You have confirmed: Topic, Target Audience, and Approximate Length.
- The conversation reaches Turn 4.

## Artifact Rule:
When initializing the Plan, do not just output text in chat. Explicitly state that you are creating a "Living Document" or "Project Dashboard" that will guide the entire writing journey.

总结​

对于大型写作而言,Plan 不是终点,而是对话的“锚”。 在冷启动阶段,不要等待完美信息。在第 3 轮左右,基于你捕捉到的蛛丝马迹(哪怕只有主题和受众),勇敢地推出第一版 Plan。让用户在“修改 AI 给出的 Plan”中推进工程,其效率远远高于在“空白聊天框里回答 AI 的提问”。


区分简单聊天 vs 需要一个写作计划

这种情况非常经典。大型写作工程的 Agent 最怕“自作多情”——用户可能只是看了一篇推文,跑来跟 AI 扯两句淡、头脑风暴一下,结果 Agent 啪一个“大型长篇巨著规划书”砸脸上,不仅沉重,还直接把聊天的轻松氛围给毁了。

要把“真正的大型写作种子”从“随机探索/日常闲聊”中过滤出来,不能只看用户“聊了什么”,更要看用户表现出来的“能量场”和“确定性”。

在工程实现上,我们可以引入“意图澄清门槛(Intent Gates)”和“行为特征打分机制”来精准区分。


1. 探索型闲聊 vs. 写作型工程 的本质区别​

我们可以从三个维度在后台对用户的输入进行特征提取:

维度探索型闲聊 (Exploration)写作型工程 (Writing Project)
词汇特征宽泛、概念性、评价性、开放式。如:“你怎么看……”、“有什么好玩的……”、“有哪些方向……”落地、结构化、痛点、角色、交付物。如:“想系统整理……”、“打算写一系列……”、“主线是……”
输入能量输入简短,多为单句;愿意让 AI 发挥、长篇大论;话题跳跃度大(这一轮聊科幻,下一轮聊AI)。输入密度高,甚至主动给背景;对 AI 的偏题会进行纠偏(“不,我不是这个意思,我的主角是……”)。
行动导向消费型视角:希望听 AI 讲故事或给知识,没有“我要生产东西”的紧迫感。生产型视角:字里行间有截止日期(Deadline)、受众、或者要把想法“固化下来”的倾向。

2. 区分策略:设计“软性试探”的无感质询(Soft Probing)​

当对话进行到第 2-3 轮,Agent 发现用户聊的话题看起来像个大工程,但态度不明朗时,绝对不要直接问:“请问你要创建一个写作项目吗?”(这样太机械了)。

应该使用“软性试探(Soft Probing)”:在正常的回复中,夹带一个带有“落地倾向”的钩子。看用户的反应。

💡 场景示例:​

用户在跟 AI 探讨“如果赛博朋克世界里没有互联网会怎样”。

  • Agent 的软性试探回复:

“……所以那种世界的社会结构会非常碎片化。这个设定太迷人了,你是纯粹对这个世界观感兴趣,还是打算把它作为你某个小说/世界观设定集的背景故事?”

🎯 用户的两种反馈决定走向:​

  • 分支 A(走向闲聊): “哈哈,我就是看电影突然想到的,瞎琢磨一下。”

  • Agent 策略: 标记为 mode: chat/explore。无限期陪聊,绝对不触发表单、不提示 Plan。

  • 分支 B(走向工程): “其实我确实想写个短篇,或者是作为我下部小说的备用设定,但还没想好怎么展开。”

  • Agent 策略: 触发 mode: project_incubation(项目孵化状态)。可以开始引导并准备在合适时机建立 Plan 了。


3. 动态状态机:引入“孵化期 (Incubation)”​

在系统设计中,不要把状态简单地分为“闲聊”和“写 Plan”。中间必须有一个缓冲带,叫做“孵化期(Incubation)”。

[ 默认:纯闲聊 / 自由探索 (Chat/Explore) ]
│
(检测到写作相关的高能词汇/高密度输入)
│
▼
[ 缓冲带:项目孵化 (Incubation) ]
│
┌─────────────────┴─────────────────┐
(软性试探:用户否定/跳跃) (软性试探:用户确认/深入)
│ │
▼ ▼
[ 退回:纯闲聊状态 ] [ 晋级:工程确立 (Project) ]
(永不主动触发 Plan) (满足 3 轮/信息够,触发 Plan)

如何在 Prompt 中写这一段过滤逻辑?​

你可以给 Agent 增加一段隐式推理的(Thought Process)指令:

## Intent Assessment Matrix
Before answering, evaluate the user's intent energy:
- Is the user showing "Production Intent" (using words like: write, organize, build, publish, my book, my project)?
- Is the user multi-turn engaged in the SAME core topic with density?

## Guardrails:
1. If the user's input is purely conceptual, curious, or rapidly jumping topics, set `intent_mode = EXPLORE`. In this mode, BE A COMPANION. Do NOT summarize, do NOT create timelines, do NOT suggest outlines.
2. If the user exhibits vague production cues, use the "Soft Probe" technique in your next response to ask if they intend to formalize this into a piece of writing.
3. ONLY switch to `intent_mode = PROJECT` when the user explicitly or implicitly accepts the writing goal.

4. 终极安全阀:把“创建 Plan”的权力交给用户(UI 层面)​

如果你的算法和 Prompt 偶尔还会误判,最安全的做法是在 UI 层面做“轻量化”处理。

  • 不要强推: 满足触发条件时,不要在聊天框里大张旗鼓地发:“我已经为你创建了项目计划!”
  • 轻量化组件(Toast / Inline Chip): 在聊天气泡下方,或者在右侧边栏,静静地亮起一个精致的微型按钮或卡片:

💡 “检测到有趣的灵感萌芽,点击可将本次对话一键固化为《未命名写作项目》并生成初步大纲。”

如果用户只是想闲聊,他可以完全无视这个 UI 组件,继续在聊天框里挥洒天马行空的想象力;而当他聊嗨了,突然想“认真对待”这个想法时,这个按钮就是他最完美的降落伞。

Claude Code 关于 plan 的处理​