From 1416217a0a12c2c0a58330bee5f6b1437f948b04 Mon Sep 17 00:00:00 2001 From: wizardchen Date: Wed, 25 Mar 2026 16:27:41 +0800 Subject: [PATCH] refactor(prompt): streamline context handling in templates - Removed redundant instructions from the context template to simplify user guidance. - Added context retrieval information to the system prompt, ensuring consistency in how context is presented across templates. - Enhanced parameter casting to allow single strings to be treated as string arrays, improving flexibility in parameter handling. - Adjusted minimum thought requirements in sequential thinking to allow for more varied input scenarios. --- config/prompt_templates/context_template.yaml | 8 -------- config/prompt_templates/system_prompt.yaml | 3 +++ internal/agent/tools/param_cast.go | 6 ++++++ internal/agent/tools/param_cast_test.go | 19 +++++++++++++++++++ internal/agent/tools/sequentialthinking.go | 2 +- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/config/prompt_templates/context_template.yaml b/config/prompt_templates/context_template.yaml index ff5bea17..e43b0920 100644 --- a/config/prompt_templates/context_template.yaml +++ b/config/prompt_templates/context_template.yaml @@ -16,16 +16,8 @@ templates: default: true has_knowledge_base: true content: | - The following is retrieved information that may or may not be relevant: - {{contexts}} - User question: {{query}} - Instructions: - - If the retrieved information is relevant to the user's question, use it to provide an accurate answer. - - If the retrieved information is NOT relevant (e.g., the user is greeting, chatting, or asking something unrelated), ignore it and respond naturally as a helpful assistant. - - Do not mention "retrieved information" or "reference materials" in your response unless the user explicitly asks about sources. - - id: "detailed_context" name: "Detailed Template" description: "Context template with detailed instructions" diff --git a/config/prompt_templates/system_prompt.yaml b/config/prompt_templates/system_prompt.yaml index a777d874..6fccbdd7 100644 --- a/config/prompt_templates/system_prompt.yaml +++ b/config/prompt_templates/system_prompt.yaml @@ -34,6 +34,9 @@ templates: ## CRITICAL: Language Rule - ALWAYS respond in {{language}} + The following is retrieved information that may or may not be relevant: + {{contexts}} + - id: "expert_assistant" name: "Domain Expert" description: "Expert template for in-depth domain-specific answers" diff --git a/internal/agent/tools/param_cast.go b/internal/agent/tools/param_cast.go index f3da8afd..9b0cf4a9 100644 --- a/internal/agent/tools/param_cast.go +++ b/internal/agent/tools/param_cast.go @@ -68,6 +68,12 @@ func CastParams(args json.RawMessage, schema json.RawMessage) json.RawMessage { // Returns (newValue, true) if a conversion was made, (val, false) otherwise. func castValue(val interface{}, targetType string) (interface{}, bool) { switch targetType { + case "array": + // Allow a single string to satisfy string-array parameters used by tools. + if s, ok := val.(string); ok { + return []string{s}, true + } + case "boolean": if s, ok := val.(string); ok { lower := strings.ToLower(s) diff --git a/internal/agent/tools/param_cast_test.go b/internal/agent/tools/param_cast_test.go index 36d28251..611187ba 100644 --- a/internal/agent/tools/param_cast_test.go +++ b/internal/agent/tools/param_cast_test.go @@ -79,3 +79,22 @@ func TestCastParams_BoolFalseString(t *testing.T) { t.Errorf("expected false, got %v (%T)", parsed["flag"], parsed["flag"]) } } + +func TestCastParams_StringToStringArray(t *testing.T) { + schema := json.RawMessage(`{"type":"object","properties":{"patterns":{"type":"array","items":{"type":"string"}}}}`) + args := json.RawMessage(`{"patterns":"OpenClaw"}`) + result := CastParams(args, schema) + + var parsed map[string]interface{} + if err := json.Unmarshal(result, &parsed); err != nil { + t.Fatal(err) + } + + patterns, ok := parsed["patterns"].([]interface{}) + if !ok { + t.Fatalf("expected patterns to be array, got %T", parsed["patterns"]) + } + if len(patterns) != 1 || patterns[0] != "OpenClaw" { + t.Fatalf("expected [OpenClaw], got %v", patterns) + } +} diff --git a/internal/agent/tools/sequentialthinking.go b/internal/agent/tools/sequentialthinking.go index be4c7289..100d42b7 100644 --- a/internal/agent/tools/sequentialthinking.go +++ b/internal/agent/tools/sequentialthinking.go @@ -99,7 +99,7 @@ Each thought can build on, question, or revise previous insights as understandin "total_thoughts": { "type": "integer", "description": "Estimated total thoughts needed (numeric value, e.g., 5, 10)", - "minimum": 5 + "minimum": 1 }, "is_revision": { "type": "boolean",