From 023ec7373ba6df9664ec6211b8c01a04d397bbd1 Mon Sep 17 00:00:00 2001 From: mlogclub Date: Sat, 18 Apr 2026 11:05:41 +0800 Subject: [PATCH] refactor(instruction): remove default governance instruction and update related tests --- docs | 2 +- internal/ai/runtime/instruction/assembler.go | 18 ++---------------- .../ai/runtime/instruction/assembler_test.go | 17 +++++------------ internal/ai/runtime/instruction/providers.go | 9 +++++++++ 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/docs b/docs index 16c8145..de9b3d3 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 16c8145f78bcf4daa0af1f412d777ace1eb8b8b6 +Subproject commit de9b3d336bd0466a56ceeefaf305f7d89d2de19d diff --git a/internal/ai/runtime/instruction/assembler.go b/internal/ai/runtime/instruction/assembler.go index 778e8ad..8b29966 100644 --- a/internal/ai/runtime/instruction/assembler.go +++ b/internal/ai/runtime/instruction/assembler.go @@ -2,18 +2,7 @@ package instruction import "strings" -const defaultGovernanceInstruction = ` -你正在一个有明确工程约束的客服系统中工作。 -执行时必须严格遵守当前注入的项目规则、Agent 规则和技能规则。 -如果存在工具白名单限制,只能调用当前允许的工具;信息不足时优先追问,不要伪造事实或跳过必要确认。 -禁止承诺未经系统确认的处理时效、完成时间、回访时间或联系时间。 -禁止代表人工团队、技术团队、售后团队承诺后续动作,除非当前上下文已有明确的工具结果、人工确认或知识库事实支持。 -当用户只表示已发送资料、邮件、截图或附件时,只能确认已收到当前消息或建议等待人工确认,不能自行补充内部处理流程、SLA 或跟进安排。 -` - -type Assembler struct { - governanceInstruction string -} +type Assembler struct{} type AssemblerInput struct { AgentInstruction string @@ -36,7 +25,7 @@ type AssemblyResult struct { } func NewAssembler() *Assembler { - return &Assembler{governanceInstruction: strings.TrimSpace(defaultGovernanceInstruction)} + return &Assembler{} } func (a *Assembler) Build(input AssemblerInput) string { @@ -47,9 +36,6 @@ func (a *Assembler) Assemble(input AssemblerInput) AssemblyResult { parts := make([]string, 0, 4) summary := AssemblySummary{SectionTitles: make([]string, 0, 4)} governanceInstruction := strings.TrimSpace(input.GovernanceInstruction) - if governanceInstruction == "" && a != nil { - governanceInstruction = strings.TrimSpace(a.governanceInstruction) - } if governanceInstruction != "" { parts = append(parts, buildInstructionSection("系统治理规则", governanceInstruction)) summary.HasGovernanceRule = true diff --git a/internal/ai/runtime/instruction/assembler_test.go b/internal/ai/runtime/instruction/assembler_test.go index 38979d2..107f470 100644 --- a/internal/ai/runtime/instruction/assembler_test.go +++ b/internal/ai/runtime/instruction/assembler_test.go @@ -26,19 +26,12 @@ func TestAssemblerRespectsProvidedSources(t *testing.T) { } } -func TestAssemblerUsesDefaultGovernanceInstruction(t *testing.T) { +func TestAssemblerDoesNotInjectGovernanceInstructionWhenInputIsEmpty(t *testing.T) { result := NewAssembler().Assemble(AssemblerInput{}) - expectedSnippets := []string{ - "禁止承诺未经系统确认的处理时效、完成时间、回访时间或联系时间。", - "禁止代表人工团队、技术团队、售后团队承诺后续动作", - "不能自行补充内部处理流程、SLA 或跟进安排。", + if result.Text != "" { + t.Fatalf("expected empty assembled text, got: %s", result.Text) } - for _, snippet := range expectedSnippets { - if !strings.Contains(result.Text, snippet) { - t.Fatalf("missing governance snippet %q in assembled text: %s", snippet, result.Text) - } - } - if !result.Summary.HasGovernanceRule { - t.Fatalf("expected governance rule summary, got %#v", result.Summary) + if result.Summary.HasGovernanceRule { + t.Fatalf("expected no governance rule summary, got %#v", result.Summary) } } diff --git a/internal/ai/runtime/instruction/providers.go b/internal/ai/runtime/instruction/providers.go index 2c0cd59..0c3af6d 100644 --- a/internal/ai/runtime/instruction/providers.go +++ b/internal/ai/runtime/instruction/providers.go @@ -8,6 +8,15 @@ import ( "cs-agent/internal/pkg/toolx" ) +const defaultGovernanceInstruction = ` +你正在一个有明确工程约束的客服系统中工作。 +执行时必须严格遵守当前注入的 Agent 规则和技能规则。 +如果存在工具白名单限制,只能调用当前允许的工具;信息不足时优先追问,不要伪造事实或跳过必要确认。 +禁止承诺未经系统确认的处理时效、完成时间、回访时间或联系时间。 +禁止代表人工团队、技术团队、售后团队承诺后续动作,除非当前上下文已有明确的工具结果、人工确认或知识库事实支持。 +当用户只表示已发送资料、邮件、截图或附件时,只能确认已收到当前消息或建议等待人工确认,不能自行补充内部处理流程、SLA 或跟进安排。 +` + type ToolAppendixProvider struct{} func NewToolAppendixProvider() *ToolAppendixProvider {