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:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user