mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-11-23 04:41:41 +01:00
fix(pi): omit empty required lists in tool schemas (#4)
Prevent a parameterless TaskList schema from rejecting a plain chat request. Add a regression test through the Pi worker and an HTTP fixture.
This commit is contained in:
1 parent
4b4b623524
commit
ecedd32c97
2 files changed
+58
-1
No files matched your search
@@ -114,6 +114,58 @@ func piTestAgent(cfg *config.Config, handler mcp.ToolHandler) *agent.Agent {
|
||||
return agent.NewAgent(&cfg.OpenAI, &cfg.Agent, srv, nil, zap.NewNop(), 8)
|
||||
}
|
||||
|
||||
func TestPiSingleChatAcceptsParameterlessTaskListSchema(t *testing.T) {
|
||||
cfg := piTestConfig(t)
|
||||
cfg.SkillsDir = t.TempDir()
|
||||
cfg.MultiAgent.Runtime.PlantaskEnable = true
|
||||
cfg.MultiAgent.Skills = config.AgentSkillsConfig{FilesystemTools: new(bool)}
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var body struct {
|
||||
Tools []struct {
|
||||
Function struct {
|
||||
Name string `json:"name"`
|
||||
Parameters map[string]any `json:"parameters"`
|
||||
} `json:"function"`
|
||||
} `json:"tools"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
t.Error(err)
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
for _, tool := range body.Tools {
|
||||
if tool.Function.Name != "TaskList" {
|
||||
continue
|
||||
}
|
||||
if required, exists := tool.Function.Parameters["required"]; exists {
|
||||
if names, ok := required.([]any); !ok || len(names) != 0 {
|
||||
http.Error(w, "Invalid schema for function 'TaskList': expected an array of required parameters", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
piReply(w, "", "", nil, "hello")
|
||||
return
|
||||
}
|
||||
t.Error("TaskList is missing from the request")
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
}))
|
||||
defer server.Close()
|
||||
cfg.OpenAI.BaseURL = server.URL + "/v1"
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
ag := piTestAgent(cfg, func(context.Context, map[string]any) (*mcp.ToolResult, error) {
|
||||
t.Error("plain chat must not execute the fixture tool")
|
||||
return nil, fmt.Errorf("unexpected tool call")
|
||||
})
|
||||
res, err := RunSingleAgent(ctx, cfg, &cfg.MultiAgent, ag, nil, zap.NewNop(), "schema-fixture", "", "say hello", nil, []string{"echo"}, nil, nil, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if res.RuntimeStatus != "completed" || res.Response != "hello" {
|
||||
t.Fatalf("expected a chat reply, got %+v", res)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPiSinglePreservesHITLAndExecutionEvidence(t *testing.T) {
|
||||
cfg := piTestConfig(t)
|
||||
var calls atomic.Int32
|
||||
|
||||
@@ -55,7 +55,12 @@ func runPiSingle(ctx context.Context, cfg *config.Config, ag *agent.Agent, db *d
|
||||
}
|
||||
|
||||
func piToolSchema(properties map[string]any, required ...string) map[string]any {
|
||||
return map[string]any{"type": "object", "properties": properties, "required": required}
|
||||
schema := map[string]any{"type": "object", "properties": properties}
|
||||
// A nil slice would encode as null, which is not a valid required list.
|
||||
if len(required) > 0 {
|
||||
schema["required"] = required
|
||||
}
|
||||
return schema
|
||||
}
|
||||
|
||||
func runPiMulti(ctx context.Context, cfg *config.Config, ma *config.MultiAgentConfig, ag *agent.Agent, db *database.DB, logger *zap.Logger,
|
||||
|
||||
Reference in new issue
Block a user