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.
This commit is contained in:
wizardchen
2026-03-25 16:27:41 +08:00
committed by lyingbug
parent ae89871ac5
commit 1416217a0a
5 changed files with 29 additions and 9 deletions
@@ -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"
@@ -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"
+6
View File
@@ -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)
+19
View File
@@ -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)
}
}
+1 -1
View File
@@ -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",