Add env-based feature flags (intent_v2_shadow/decision, multi_intent, workflow_intents), V1/V2 shadow diff reporting, expectation_plus_new plan building, ranked-frame L2 conflict gate, and coordinator sequential query plan execution with confirm-step deferral. Co-authored-by: Cursor <cursoragent@cursor.com>
197 lines
10 KiB
Go
197 lines
10 KiB
Go
package intent
|
||
|
||
import (
|
||
"time"
|
||
)
|
||
|
||
// IntentType 核心意图类别定义
|
||
type IntentType string
|
||
|
||
const (
|
||
IntentQueryProgress IntentType = "QUERY_PROGRESS" // 查询进度、成熟度、风险研判或沟通话术
|
||
IntentSupplementInfo IntentType = "SUPPLEMENT_INFO" // 补充/修改材料、事实信息或参数
|
||
IntentAdvanceStage IntentType = "ADVANCE_STAGE" // 确认推进到下一成熟度阶段 (如 V0.1 -> V0.5)
|
||
IntentTriggerTask IntentType = "TRIGGER_TASK" // 显式生成或重新执行特定交付物任务 (如 intake, quote)
|
||
IntentTriggerAdhocTask IntentType = "TRIGGER_ADHOC_TASK" // 将对话中的复杂自由任务升级为小队受控执行(路由层 R1 升级建议兑现)
|
||
IntentCasualChat IntentType = "CASUAL_CHAT" // 问候、闲聊或通用帮助引导
|
||
IntentDeclineExpectation IntentType = "DECLINE_EXPECTATION" // 用户明确暂缓/不采纳上轮建议 (非阻塞放弃)
|
||
|
||
// 法定文档治理流转
|
||
IntentDocGovClaim IntentType = "DOCGOV_CLAIM"
|
||
IntentDocGovSubmitReview IntentType = "DOCGOV_SUBMIT_REVIEW"
|
||
IntentDocGovReviewApprove IntentType = "DOCGOV_REVIEW_APPROVE"
|
||
IntentDocGovReviewReject IntentType = "DOCGOV_REVIEW_REJECT"
|
||
IntentDocGovFinalApprove IntentType = "DOCGOV_FINAL_APPROVE"
|
||
IntentDocGovFinalReject IntentType = "DOCGOV_FINAL_REJECT"
|
||
IntentDocGovProposalDecide IntentType = "DOCGOV_PROPOSAL_DECIDE"
|
||
|
||
// 决策与合规查询
|
||
IntentQueryRegulations IntentType = "QUERY_REGULATIONS"
|
||
IntentQuerySimilarCases IntentType = "QUERY_SIMILAR_CASES"
|
||
IntentQueryUserRights IntentType = "QUERY_USER_RIGHTS"
|
||
IntentQueryRejectReason IntentType = "QUERY_REJECT_REASON" // 查询受控文档驳回/退回原因
|
||
|
||
// 协同拍板与阶段执行动作
|
||
IntentConfirmAction IntentType = "CONFIRM_ACTION" // 用户拍板确认交互卡片
|
||
IntentExecuteStageAdvance IntentType = "EXECUTE_STAGE_ADVANCE" // 推进工作流阶段执行
|
||
|
||
// 安全与权限红线拦截
|
||
IntentSecurityForbidden IntentType = "SECURITY_FORBIDDEN"
|
||
|
||
// 工作流控制(Phase 3 产品能力对齐)
|
||
IntentSwitchWorkflow IntentType = "SWITCH_WORKFLOW"
|
||
IntentTriggerWorkflow IntentType = "TRIGGER_WORKFLOW"
|
||
IntentQueryWorkflowStatus IntentType = "QUERY_WORKFLOW_STATUS"
|
||
|
||
// 文档/运行态只读查询
|
||
IntentQueryDocStatus IntentType = "QUERY_DOC_STATUS"
|
||
|
||
// 对话修复:帮助 / 暂不支持
|
||
IntentHelpCapabilities IntentType = "HELP_CAPABILITIES"
|
||
IntentUnsupportedAction IntentType = "UNSUPPORTED_ACTION"
|
||
|
||
// 长任务运行控制(Phase 4)
|
||
IntentRunStatusQuery IntentType = "RUN_STATUS_QUERY"
|
||
IntentRunResume IntentType = "RUN_RESUME"
|
||
IntentRunRestart IntentType = "RUN_RESTART"
|
||
)
|
||
|
||
// ResolutionBranch 三分支意图消解类别
|
||
type ResolutionBranch string
|
||
|
||
const (
|
||
BranchExpectationHit ResolutionBranch = "EXPECTATION_HIT" // 分支 1: 命中历史轮次挂起预期 (肯定/选择/带补丁/取消)
|
||
BranchNewIntentPreempt ResolutionBranch = "NEW_INTENT_PREEMPT" // 分支 2: 独立新意图抢占 (用户意图最高优先级)
|
||
BranchAmbiguousFallback ResolutionBranch = "AMBIGUOUS_FALLBACK" // 分支 3: 模糊/无实际意义兜底 (参谋主动分析引导)
|
||
)
|
||
|
||
// ExpectationOption 供用户挑选或单字快速兑现的具体选项
|
||
type ExpectationOption struct {
|
||
OptionID string `json:"option_id"` // 选项代号 (如 "1", "2", "advance_v05")
|
||
Title string `json:"title"` // 选项简述 (如 "推进到 V0.5 方案成型与法规对齐")
|
||
Description string `json:"description,omitempty"` // 参谋为用户做的工作说明与收益分析
|
||
Intent IntentType `json:"intent"` // 对应绑定的业务意图
|
||
Slots map[string]string `json:"slots,omitempty"` // 预设槽位键值对
|
||
}
|
||
|
||
// PendingExpectation 挂起预期草稿(非阻塞桌角备忘贴纸)
|
||
type PendingExpectation struct {
|
||
ExpectationID string `json:"expectation_id,omitempty"`
|
||
ExpectedIntent IntentType `json:"expected_intent,omitempty"`
|
||
TargetAction string `json:"target_action,omitempty"`
|
||
Prompt string `json:"prompt,omitempty"`
|
||
AffirmativeWord string `json:"affirmative_word,omitempty"`
|
||
DeclineWord string `json:"decline_word,omitempty"`
|
||
ExpiresAt time.Time `json:"expires_at,omitempty"`
|
||
Payload map[string]string `json:"payload,omitempty"`
|
||
ContextSnippet string `json:"context_snippet,omitempty"` // 上一轮建议的业务背景简述
|
||
DefaultOption *ExpectationOption `json:"default_option,omitempty"` // 参谋最推荐的基准选项(用户说“好/行”时默认执行)
|
||
Options []ExpectationOption `json:"options,omitempty"` // 供用户挑选的备选选项列表
|
||
AllowAffirmative bool `json:"allow_affirmative"` // 是否允许用单字肯定(好/行/可以)触发
|
||
CreatedAt time.Time `json:"created_at"` // 挂起时间
|
||
}
|
||
|
||
// CandidateIntent 候选意图提案(L1 对话层输出,由 L2 协调层终审)
|
||
type CandidateIntent struct {
|
||
Intent IntentType `json:"intent"`
|
||
Confidence float64 `json:"confidence"` // 置信度 0.0 - 1.0
|
||
Branch ResolutionBranch `json:"branch"` // 归属的三分支判定
|
||
FilledSlots map[string]string `json:"filled_slots"`
|
||
MissingSlots []string `json:"missing_slots,omitempty"`
|
||
Reasoning string `json:"reasoning"` // 判断依据与文本佐证
|
||
ClarificationQuestion string `json:"clarification_question,omitempty"` // 槽位缺失时的澄清追问
|
||
MatchedOption *ExpectationOption `json:"matched_option,omitempty"` // 分支 1 命中的具体选项
|
||
PatchSlots map[string]string `json:"patch_slots,omitempty"` // 分支 1 复合输入的增量槽位补丁
|
||
IsDecline bool `json:"is_decline,omitempty"` // 是否为明确暂缓/放弃
|
||
}
|
||
|
||
// IntentRecognitionResult 意图识别完整输出(多输出策略)
|
||
type IntentRecognitionResult struct {
|
||
RawInput string `json:"raw_input"`
|
||
TopIntent *CandidateIntent `json:"top_intent"`
|
||
Candidates []CandidateIntent `json:"candidates"`
|
||
ContextSnapshotID string `json:"context_snapshot_id,omitempty"`
|
||
RequiresClarifying bool `json:"requires_clarifying"`
|
||
Branch ResolutionBranch `json:"branch"` // 顶层分支标记
|
||
|
||
// Shadow* 观测字段:只记录、不参与 Router/Coordinator 路由裁决。
|
||
ShadowScore float64 `json:"shadow_score,omitempty"`
|
||
ShadowMargin float64 `json:"shadow_margin,omitempty"`
|
||
ShadowDialogueAct string `json:"shadow_dialogue_act,omitempty"`
|
||
ShadowDecisionHint string `json:"shadow_decision_hint,omitempty"`
|
||
|
||
// V2 双写:迁移期与 TopIntent 并存,Router/Coordinator 默认仍消费 TopIntent。
|
||
IntentFrameV2 *IntentFrameV2 `json:"intent_frame_v2,omitempty"`
|
||
RankedFrames *RankedIntentSet `json:"ranked_frames,omitempty"`
|
||
IntentPlan *IntentPlan `json:"intent_plan,omitempty"`
|
||
|
||
// V2Shadow Phase 5 影子比对(intent_v2_shadow / intent_v2_decision 开启时填充)
|
||
V2Shadow *V2ShadowReport `json:"v2_shadow,omitempty"`
|
||
}
|
||
|
||
// 常见槽位 Key 常量定义
|
||
const (
|
||
SlotTargetStage = "target_stage" // 目标阶段 (如 V0.1_triage, V0.5_feasibility, V1.0_quoting)
|
||
SlotTargetTask = "target_task" // 目标任务 (如 intake, research, cdo_quote)
|
||
SlotFactKey = "fact_key" // 事实键 (如 target_market, device_type)
|
||
SlotFactValue = "fact_value" // 事实值
|
||
SlotSupplementDoc = "supplement_doc" // 补充内容文本
|
||
SlotQueryTopic = "query_topic" // 查询主题 (如 progress, risk, talk_script, quotation)
|
||
|
||
// 法定文档治理与权限槽位
|
||
SlotTargetDoc = "target_doc"
|
||
SlotRejectReason = "reject_reason"
|
||
SlotTargetSection = "target_section"
|
||
SlotProposalAction = "proposal_action"
|
||
SlotForbiddenTarget = "forbidden_target"
|
||
|
||
// 路由层槽位
|
||
SlotTaskBrief = "task_brief" // 自由任务简报(升级建议携带的用户原始诉求)
|
||
|
||
// 工作流槽位
|
||
SlotTargetWorkflow = "target_workflow" // product_manager | test_manager | main
|
||
|
||
// 长任务/运行槽位
|
||
SlotWorkDir = "work_dir"
|
||
SlotRunAction = "run_action" // status | resume | restart
|
||
SlotSupplementAction = "supplement_action" // add | correct | attach
|
||
)
|
||
|
||
// CardAction 交互卡片按钮动作
|
||
type CardAction struct {
|
||
ActionID string `json:"action_id"`
|
||
Label string `json:"label"`
|
||
Style string `json:"style"` // primary, danger, subtle
|
||
Payload map[string]string `json:"payload,omitempty"`
|
||
IsAffirmativeDefault bool `json:"is_affirmative_default,omitempty"`
|
||
}
|
||
|
||
// InteractiveCardPayload 对话交互卡片载荷
|
||
type InteractiveCardPayload struct {
|
||
CardID string `json:"card_id"`
|
||
CardType string `json:"card_type"` // CONFIRMATION, SLOT_FILLING, DIFF_PROPOSAL, REMINDER_NOTICE
|
||
Title string `json:"title"`
|
||
TargetDocID string `json:"target_doc_id,omitempty"`
|
||
TargetDocTitle string `json:"target_doc_title,omitempty"`
|
||
TargetSectionID string `json:"target_section_id,omitempty"`
|
||
SectionTitle string `json:"section_title,omitempty"`
|
||
ProposedContent string `json:"proposed_content,omitempty"`
|
||
ImpactRisk string `json:"impact_risk,omitempty"`
|
||
CurrentStatus string `json:"current_status"` // active, executing, resolved, cancelled, outdated, expired
|
||
TTLTurns int `json:"ttl_turns"`
|
||
CreatedAt time.Time `json:"created_at"`
|
||
Actions []CardAction `json:"actions,omitempty"`
|
||
}
|
||
|
||
// ContextSnapshot 传递给 L1 意图识别器的轻量上下文快照
|
||
type ContextSnapshot struct {
|
||
SnapshotID string `json:"snapshot_id,omitempty"`
|
||
ProjectName string `json:"project_name,omitempty"`
|
||
CurrentStage string `json:"current_stage,omitempty"`
|
||
ActiveDocID string `json:"active_doc_id,omitempty"`
|
||
DocLifecycleState string `json:"doc_lifecycle_state,omitempty"`
|
||
UserDocRole string `json:"user_doc_role,omitempty"`
|
||
AvailableActions []string `json:"available_actions,omitempty"`
|
||
PendingExpectation *PendingExpectation `json:"pending_expectation,omitempty"`
|
||
}
|