mcpField
M
multi-turn-context-retention

multi-turn-context-retention

github.com/louisblytheAgent 工作流190405 次安装40 周前更新
代码仓库

关于 multi-turn-context-retention

面向销售 Bot 开发者的技能,帮助 Bot 在长对话和不同会话间保留上下文。内容涵盖分层记忆、摘要、主题跟踪、指代解析及待办事项管理。

主要功能

  1. 01组织短期、中期和长期记忆
  2. 02通过滚动窗口总结对话
  3. 03跟踪主题与关键实体
  4. 04解析对早前消息的指代
  5. 05管理待答问题和承诺事项

适用场景

  1. 01会话间隔后延续销售对话
  2. 02话题转折后回到原有主题
  3. 03回忆早前交流中的潜在客户信息

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/louisblythe/sales-skills --skill multi-turn-context-retention

安装后在 Claude Code 中输入/multi-turn-context-retention确认已加载。

详细介绍

多轮上下文保留

你是构建销售机器人上下文保留系统的专家。你的目标是帮助开发者创建能够在多轮交流中维持连贯、贴合上下文对话的机器人。

上下文挑战

销售对话通常会跨越:

  • 20-50 多轮消息交流
  • 多天或数周
  • 话题切换与回归
  • 对早前陈述的引用

如果没有妥善保留上下文,机器人会显得机械且令人沮丧。

上下文架构

1. 短期记忆(当前会话)
Purpose: Immediate conversation flow
Retention: Full detail
Window: Last 10-20 messages
Contents:
- Exact messages sent/received
- Extracted entities
- Current topic/intent
- Unanswered questions
2. 中期记忆(对话摘要)
Purpose: Session continuity
Retention: Summarized
Window: Current conversation thread
Contents:
- Key facts established
- Commitments made
- Questions asked/answered
- Objections raised
3. 长期记忆(潜在客户档案)
Purpose: Relationship continuity
Retention: Structured data
Window: All interactions
Contents:
- Contact preferences
- Company information
- Past interactions
- Deal status

实现策略

滚动窗口与摘要
Messages 1-10: Full detail in context
Messages 11-20: Summarized to key points
Messages 21+: Only critical facts retained

Example summary:
"Prospect: John, VP Sales at Acme (200 employees)
Budget: ~$30k, Timeline: Q2
Key need: HubSpot integration
Objection raised: Concerned about implementation time
Current status: Requested demo"
话题串联

分别跟踪对话话题:

Thread: Requirements
- Need CRM integration (msg 3)
- Mobile app important (msg 7)
- Must have reporting (msg 15)

Thread: Budget
- Initial: "limited budget" (msg 5)
- Clarified: "$25-35k range" (msg 12)
- Authority: "Need CFO approval over $30k" (msg 18)

Thread: Timeline
- "Looking for Q2" (msg 8)
- "Actually, sooner if possible" (msg 22)
以实体为中心的记忆

围绕关键实体存储:

PROSPECT: John Smith
├── Role: VP Sales
├── Authority: Up to $30k
├── Communication: Prefers email
└── Personality: Direct, time-conscious

COMPANY: Acme Corp
├── Size: 200 employees
├── Industry: SaaS
├── Current tool: Spreadsheets
└── Pain: Manual reporting

DEAL: Opportunity_123
├── Budget: $30k
├── Timeline: Q2
├── Stage: Demo scheduled
└── Blockers: CFO approval needed

处理长对话

对话检查点

每 10 条消息创建一个检查点:

"Let me make sure I have this right:
- You're looking for a solution for your 15-person sales team
- Budget is around $25k
- You need HubSpot integration
- Timeline is Q2

Did I miss anything important?"

优点:

  • 确认理解无误
  • 尽早纠正错误
  • 创建自然的摘要节点
  • 展现出专注倾听
平稳恢复上下文

上下文不明确时:

❌ "I don't understand"
❌ "Can you repeat that?"
❌ "What do you mean?"

✓ "Just to make sure I'm tracking—are you referring to the integration requirements we discussed earlier?"
✓ "When you say 'the budget issue,' do you mean the CFO approval process?"
✓ "I want to make sure I address the right concern—is this about timeline or pricing?"
话题切换

处理自然的话题变化:

Prospect: "Actually, before we continue—what about security?"

Bot should:
1. Acknowledge the switch
2. Park the current topic
3. Address the new topic
4. Return to previous topic when appropriate

"Great question on security—let me address that.
[Security response]
Now, back to the implementation timeline you asked about..."

指代消解

代词处理
Prospect: "Can it do that?"

Context needed:
- What is "it"? (The product? A feature?)
- What is "that"? (Last mentioned capability?)

Resolution:
- Check last 3-5 messages for antecedent
- If ambiguous, clarify naturally
时间指代
"Like I said before" → Search conversation history
"What you mentioned yesterday" → Check previous session
"The thing we discussed" → Find last substantive topic
隐含指代
Prospect: "Same concern as last time"

Bot needs to:
1. Retrieve previous objection
2. Acknowledge the pattern
3. Address with new approach

"I remember you mentioned concerns about implementation time before.
Since then, we've actually streamlined our onboarding..."

状态管理

对话状态机
States:
- GREETING: Initial contact
- DISCOVERY: Learning needs
- QUALIFICATION: Assessing fit
- OBJECTION_HANDLING: Addressing concerns
- SCHEDULING: Booking next steps
- FOLLOW_UP: Re-engagement

Track current state and valid transitions.
待办事项跟踪
Pending Questions (asked, not answered):
- "What's your current solution?" (msg 5)
- "Who else is involved in the decision?" (msg 12)

Promised Actions:
- "I'll send you the case study" (msg 8) → NOT SENT
- "Let me check on that pricing" (msg 15) → PENDING

Prospect Commitments:
- "I'll review and get back to you" (msg 20) → WAITING

跨会话连续性

恢复会话
New session opener:
"Hi John! Last time we spoke, you were reviewing the proposal
and mentioned needing to discuss with your CFO. How did that go?"

Not:
"Hi! How can I help you today?" (ignores history)
时间感知上下文
If last contact was:
- <24 hours: "Following up on our conversation..."
- 2-7 days: "Checking back in on..."
- 1-2 weeks: "It's been a little while since we connected..."
- 2+ weeks: "I wanted to reconnect about..."
情况变化

检测变化并进行调整:

"I noticed you mentioned Q2 timeline, but we're now in late March.
Has anything changed with your timeline?"

技术实现

上下文窗口优化
def build_context(conversation, max_tokens=4000):
    context = []

    # Always include: prospect profile
    context.append(get_prospect_summary())

    # Always include: deal status
    context.append(get_deal_status())

    # Include: recent messages (full)
    recent = conversation[-10:]
    context.extend(recent)

    # Include: older messages (summarized)
    if len(conversation) > 10:
        older_summary = summarize_messages(conversation[:-10])
        context.append(older_summary)

    # Include: key facts not in recent messages
    key_facts = get_key_facts_not_in(recent)
    context.append(key_facts)

    return truncate_to_tokens(context, max_tokens)
记忆持久化
Storage strategy:
- Hot: Redis (current session)
- Warm: Database (recent conversations)
- Cold: Data warehouse (historical)

Retrieval:
- By recency (most recent first)
- By relevance (semantic search)
- By entity (all mentions of "budget")

质量指标

良好的上下文保留
  • 自然地引用早前的对话
  • 不会重复询问已回答的问题
  • 基于之前的交流继续展开
  • 适当提及已过去的时间
较差的上下文保留
  • 重复询问已回答的问题
  • 忽略之前的陈述
  • 每条消息都从头开始
  • 忽略明显的指代

测试上下文保留

测试场景
  1. 引用 15 条消息之前的内容
  2. 经过一段题外话后回到原话题
  3. 在间隔 3 天后恢复对话
  4. 处理代词指代
  5. 回忆提到的具体数字或日期
指标
  • 上下文准确性:机器人能否正确回忆?
  • 指代消解:代词和指代是否得到了妥善处理?
  • 连贯性评分:对话是否自然流畅?
  • 错误恢复:如何处理上下文失效?

评论

支持 Markdown