Skip to content

Self-evolving Context Database for AI Agents. Unify Agent Memory, Knowledge RAG and Skills.

fix(sdk/go): stop sending empty args on AddResource (#2878)

Evoadb57bdcf378
diff --git a/sdk/go/client_test.go b/sdk/go/client_test.go
index 0193b2211..d5ac01c75 100644
--- a/sdk/go/client_test.go
+++ b/sdk/go/client_test.go
@@ -412,6 +412,10 @@ func TestAddResourceUploadsLocalFile(t *testing.T) {
if body["directly_upload_media"] != true {
t.Fatalf("directly_upload_media = %#v", body["directly_upload_media"])
}
+ // args must be omitted when the caller does not pass any, so the
+ // request is accepted by pre-#2549 instances whose resources route
+ // uses model_config=ConfigDict(extra="forbid").
+ requireBodyKeysAbsent(t, body, "args")
writeOK(t, w, map[string]any{"uri": "viking://resources/note.md"})
default:
t.Fatalf("unexpected path %s", r.URL.Path)
@@ -428,6 +432,78 @@ func TestAddResourceUploadsLocalFile(t *testing.T) {
}
}
+func TestAddResourceSendsArgsWhenProvided(t *testing.T) {
+ dir := t.TempDir()
+ filePath := filepath.Join(dir, "note.md")
+ if err := os.WriteFile(filePath, []byte("hello"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ client, closeServer := testClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ switch r.URL.Path {
+ case "/api/v1/resources/temp_upload":
+ if err := r.ParseMultipartForm(1 << 20); err != nil {
+ t.Fatal(err)
+ }
+ writeOK(t, w, map[string]any{"temp_file_id": "tmp-file"})
+ case "/api/v1/resources":
+ body := readJSONBody(t, r)
+ args, ok := body["args"].(map[string]any)
+ if !ok {
+ t.Fatalf("args = %#v, want map", body["args"])
+ }
+ if args["key"] != "value" {
+ t.Fatalf("args[key] = %#v", args["key"])
+ }
+ writeOK(t, w, map[string]any{"uri": "viking://resources/note.md"})
+ default:
+ t.Fatalf("unexpected path %s", r.URL.Path)
+ }
+ }))
+ defer closeServer()
+
+ if _, err := client.AddResource(context.Background(), filePath, &AddResourceOptions{
+ Args: map[string]any{"key": "value"},
+ }); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// An explicitly-provided but empty Args map is treated the same as no args: the
+// key is omitted so the request stays compatible with pre-#2549 instances. The
+// resources create route defaults args to {} server-side, so "absent" and
+// "present-but-empty" are equivalent here. Mirrors the Python SDK #2834.
+func TestAddResourceOmitsExplicitlyEmptyArgs(t *testing.T) {
+ dir := t.TempDir()
+ filePath := filepath.Join(dir, "note.md")
+ if err := os.WriteFile(filePath, []byte("hello"), 0o644); err != nil {
+ t.Fatal(err)
+ }
+
+ client, closeServer := testClient(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ switch r.URL.Path {
+ case "/api/v1/resources/temp_upload":
+ if err := r.ParseMultipartForm(1 << 20); err != nil {
+ t.Fatal(err)
+ }
+ writeOK(t, w, map[string]any{"temp_file_id": "tmp-file"})
+ case "/api/v1/resources":
+ body := readJSONBody(t, r)
+ requireBodyKeysAbsent(t, body, "args")
+ writeOK(t, w, map[string]any{"uri": "viking://resources/note.md"})
+ default:
+ t.Fatalf("unexpected path %s", r.URL.Path)
+ }
+ }))
+ defer closeServer()
+
+ if _, err := client.AddResource(context.Background(), filePath, &AddResourceOptions{
+ Args: map[string]any{},
+ }); err != nil {
+ t.Fatal(err)
+ }
+}
+
func TestAddSkillUploadsDirectoryZip(t *testing.T) {
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, "SKILL.md"), []byte("# Skill"), 0o644); err != nil {
diff --git a/sdk/go/resources.go b/sdk/go/resources.go
index 5c54b3a4a..3c61ab332 100644
--- a/sdk/go/resources.go
+++ b/sdk/go/resources.go
@@ -21,7 +21,6 @@ func (c *Client) AddResource(ctx context.Context, path string, opts *AddResource
"strict": opts.Strict,
"directly_upload_media": boolValue(opts.DirectlyUploadMedia, true),
"watch_interval": opts.WatchInterval,
- "args": map[string]any{},
}
setString(payload, "to", opts.To)
setString(payload, "parent", opts.Parent)
@@ -33,7 +32,12 @@ func (c *Client) AddResource(ctx context.Context, path string, opts *AddResource
payload["preserve_structure"] = *opts.PreserveStructure
}
setAny(payload, "telemetry", opts.Telemetry)
- if opts.Args != nil {
+ // Only attach args when arguments were actually provided. Instances that
+ // predate #2549 (which added the args field to the resources route under
+ // model_config=ConfigDict(extra="forbid")) reject an empty args object with
+ // "body.args: Extra inputs are not permitted". Mirrors the Python SDK
+ // _compact_request_body (#2834) and the Rust CLI compact_request_body (#2799).
+ if len(opts.Args) > 0 {
payload["args"] = opts.Args
}
if err := c.addLocalUpload(ctx, payload, path, true); err != nil {