diff --git a/acceleration/internal/api/child_agents.go b/acceleration/internal/api/child_agents.go index c44e6d83b3..6762b23d19 100644 --- a/acceleration/internal/api/child_agents.go +++ b/acceleration/internal/api/child_agents.go @@ -7,6 +7,7 @@ import ( "regexp" "slices" + "github.com/GetStream/Vision-Agents/acceleration/internal/connectors/sensitive" "github.com/GetStream/Vision-Agents/acceleration/internal/store" "github.com/danielgtaylor/huma/v2" ) @@ -64,7 +65,9 @@ func renderedChildAgents(stored []store.ChildAgent) *[]ChildAgent { // child is another of the app's text agents with no agents of its own. That is held from both // sides, so an agent another one calls can neither gain agents nor stop being a text agent. // existing is the config before this save, nil for a new one. A list the save leaves as it was -// is not asked about again, as llmFallbacksComplaint leaves a list. +// is not asked about again, as llmFallbacksComplaint leaves a list. Every save, whatever it +// changes, is also held to the sensitive-connector rule over each set of agents the config is +// part of (sensitiveGraphComplaint). func (s *Server) childAgentsComplaint(ctx context.Context, customerID string, config *store.AgentConfig, existing *store.AgentConfig) (string, bool, error) { var was []store.ChildAgent wasText := false @@ -100,27 +103,64 @@ func (s *Server) childAgentsComplaint(ctx context.Context, customerID string, co config.Agents[i].Config = found.Name } } - renamed := existing != nil && existing.Name != config.Name - // Only a save that could break a parent reads the app's other configs. - if len(config.Agents) == 0 && !renamed && !(wasText && config.Mode != store.AgentModeText) { - return "", true, nil - } - name := config.Name - if renamed { - name = existing.Name + if existing != nil && existing.Name != config.Name { + if parent, err := s.parentOf(ctx, customerID, existing.Name, config.ID); err != nil { + return "", false, err + } else if parent != "" { + return fmt.Sprintf("%q hands work to this agent by its name, so it keeps it: take it out of %q's agents first", parent, parent), false, nil + } } - parent, err := s.parentOf(ctx, customerID, name, config.ID) - switch { - case err != nil: + // Every save reads the configs that call it by the name it is about to have: it runs as + // their child, beside their other children. + parents, err := s.store.AgentConfigs.Calling(ctx, customerID, config.Name, config.ID) + if err != nil { return "", false, err - case parent == "": - return "", true, nil - case renamed: - return fmt.Sprintf("%q hands work to this agent by its name, so it keeps it: take it out of %q's agents first", parent, parent), false, nil - case len(config.Agents) > 0: - return fmt.Sprintf("%q hands work to this agent, so it cannot have agents of its own: agents are one level deep", parent), false, nil - } - return fmt.Sprintf("%q hands work to this agent, so it stays a text agent", parent), false, nil + } + if len(parents) > 0 { + parent := parents[0].Name + switch { + case len(config.Agents) > 0: + return fmt.Sprintf("%q hands work to this agent, so it cannot have agents of its own: agents are one level deep", parent), false, nil + case wasText && config.Mode != store.AgentModeText: + return fmt.Sprintf("%q hands work to this agent, so it stays a text agent", parent), false, nil + } + } + return s.sensitiveGraphComplaint(ctx, customerID, *config, parents) +} + +// sensitiveGraphComplaint is sensitive.GraphComplaint over each set of agents the config is +// about to be part of: itself with its children, and each of parents with all of its children. +// The config is weighed as it is about to be stored, each other one as stored, so a save that +// leaves the agents as they were still refuses a set that breaks the rule. +func (s *Server) sensitiveGraphComplaint(ctx context.Context, customerID string, config store.AgentConfig, parents []store.AgentConfig) (string, bool, error) { + if len(config.Agents) > 0 { + parents = append([]store.AgentConfig{config}, parents...) + } + for _, parent := range parents { + configs := []store.AgentConfig{parent} + for _, child := range parent.Agents { + if child.Config == config.Name { + configs = append(configs, config) + continue + } + found, err := s.store.AgentConfigs.GetByName(ctx, customerID, child.Config) + // A child deleted since runs nothing (childRunner.Run). + if errors.Is(err, store.ErrNoAgentConfig) { + continue + } + if err != nil { + return "", false, err + } + configs = append(configs, found) + } + if message, ok, err := sensitive.GraphComplaint(ctx, s.store.ConnectorDefinitions, customerID, configs); err != nil || !ok { + if !ok { + message += ". The other agents in these are weighed as stored: if you mean to change them too, change them first and save this one after" + } + return message, ok, err + } + } + return "", true, nil } // childConfig is the app's config named, by name or else by id, that the caller may see. @@ -150,7 +190,11 @@ func (s *Server) childConfig(ctx context.Context, customerID, named string) (sto // parentOf is the name of a config of the app, other than self, that hands work to the // config called name, and empty when none does. func (s *Server) parentOf(ctx context.Context, customerID, name, self string) (string, error) { - return s.store.AgentConfigs.NameCalling(ctx, customerID, name, self) + parents, err := s.store.AgentConfigs.Calling(ctx, customerID, name, self) + if err != nil || len(parents) == 0 { + return "", err + } + return parents[0].Name, nil } func (*ChildAgent) TransformSchema(_ huma.Registry, schema *huma.Schema) *huma.Schema { diff --git a/acceleration/internal/api/child_agents_writes_test.go b/acceleration/internal/api/child_agents_writes_test.go new file mode 100644 index 0000000000..0722a788b7 --- /dev/null +++ b/acceleration/internal/api/child_agents_writes_test.go @@ -0,0 +1,247 @@ +//go:build integration + +package api + +import ( + "encoding/json" + "maps" + "net/http" + "strconv" + "strings" + + "github.com/GetStream/Vision-Agents/acceleration/internal/store" +) + +// configWrite is one of the ways a config is written: written names it, with its id when it is +// stored, which it is before an update, a patch or a sync, and fields are what the write sends +// besides its name, mode and model. +type configWrite struct { + name string + stored bool + write func(s *ChildAgentsSuite, written AgentConfig, fields map[string]any) (int, string) +} + +var configWrites = []configWrite{ + {name: "create", write: func(s *ChildAgentsSuite, written AgentConfig, fields map[string]any) (int, string) { + return s.writeConfig(http.MethodPost, "/v1/agents/configs", written.Name, fields) + }}, + {name: "update", stored: true, write: func(s *ChildAgentsSuite, written AgentConfig, fields map[string]any) (int, string) { + return s.writeConfig(http.MethodPut, "/v1/agents/configs/"+written.Id, written.Name, fields) + }}, + {name: "patch", stored: true, write: func(s *ChildAgentsSuite, written AgentConfig, fields map[string]any) (int, string) { + status, payload := s.serverClient.call(http.MethodPatch, "/v1/agents/configs/"+written.Id, fields) + return status, string(payload) + }}, + {name: "sync", stored: true, write: func(s *ChildAgentsSuite, written AgentConfig, fields map[string]any) (int, string) { + synced := maps.Clone(fields) + synced["hash"] = s.utils.uuid() + return s.writeConfig(http.MethodPost, "/v1/agents/sync", written.Name, synced) + }}, +} + +// graphWrite is a set of agents around the written config, which holds before when it is stored, +// built by around once the written config has its name, and what writing fields into it is +// answered: a 400 saying each of says, or a success when says is empty. +type graphWrite struct { + name string + before map[string]any + around func(s *ChildAgentsSuite, written string) (fields map[string]any, says []string) +} + +var graphWrites = []graphWrite{ + {name: "a sensitive parent beside a child that sends out", around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + writer := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}) + return map[string]any{"connectors": []map[string]any{sessionNessy("customers")}, "agents": []ChildAgent{{Config: writer.Name, Tool: "ask"}}}, + []string{strconv.Quote(written) + `'s connector binding "customers" binds "nessy", whose tools read private data`, + `connector binding "code" of the agent ` + strconv.Quote(writer.Name) + " can send data out"} + }}, + {name: "a parent that sends out beside a sensitive child", around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + reader := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + return map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}, "agents": []ChildAgent{{Config: reader.Name, Tool: "ask"}}}, + []string{strconv.Quote(reader.Name) + `'s connector binding "customers" binds "nessy"`, + `connector binding "code" of the agent ` + strconv.Quote(written) + " can send data out"} + }}, + {name: "a parent of a sensitive child and of a child that sends out", around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + reader := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + writer := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}) + return map[string]any{"agents": []ChildAgent{{Config: reader.Name, Tool: "ask_a"}, {Config: writer.Name, Tool: "ask_b"}}}, + []string{strconv.Quote(reader.Name) + `'s connector binding "customers" binds "nessy"`, + `connector binding "code" of the agent ` + strconv.Quote(writer.Name) + " can send data out"} + }}, + {name: "a child gaining a tool that sends out under a sensitive parent", around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + s.calls(parent, written) + return map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}, + []string{strconv.Quote(parent.Name) + `'s connector binding "customers" binds "nessy"`, + `connector binding "code" of the agent ` + strconv.Quote(written) + " can send data out"} + }}, + // A child the parent still names but that is gone runs nothing: it is left out, and the + // children after it are still weighed. + {name: "a child gaining a tool that sends out under a sensitive parent that names a gone child first", around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + s.calls(parent, "gone-"+s.utils.uuid(), written) + return map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}, + []string{strconv.Quote(parent.Name) + `'s connector binding "customers" binds "nessy"`, + `connector binding "code" of the agent ` + strconv.Quote(written) + " can send data out"} + }}, + // The parent that is not sensitive is the older one, which is the one a single lookup finds. + {name: "a child gaining a tool that sends out under the second of two parents", around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + s.calls(s.agentWith("fanning/fanning-model", nil), written) + parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + s.calls(parent, written) + return map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}, + []string{strconv.Quote(parent.Name) + `'s connector binding "customers" binds "nessy"`, + `connector binding "code" of the agent ` + strconv.Quote(written) + " can send data out"} + }}, + {name: "a child gaining a tool that sends out beside a sensitive sibling", around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + reader := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + s.calls(s.agentWith("fanning/fanning-model", nil), reader.Name, written) + return map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}, + []string{strconv.Quote(reader.Name) + `'s connector binding "customers" binds "nessy"`, + `connector binding "code" of the agent ` + strconv.Quote(written) + " can send data out"} + }}, + {name: "a child gaining a sensitive binding under a parent whose sandbox reaches the network", around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + parent := s.agentWith("fanning/fanning-model", map[string]any{"sandbox": "daytona", "sandbox_options": map[string]any{"network": true}}) + s.calls(parent, written) + return map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}, + []string{strconv.Quote(written) + `'s connector binding "customers" binds "nessy"`, + "the sandbox's network access of the agent " + strconv.Quote(parent.Name) + " can send data out"} + }}, + // The set broke the rule before this save, which changes nothing the rule reads. + {name: "a save of another field of a child in a set that breaks the rule", before: map[string]any{ + "connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}, + }, around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + s.calls(parent, written) + return map[string]any{"instructions": "be terse"}, + []string{strconv.Quote(parent.Name) + `'s connector binding "customers" binds "nessy"`, + `connector binding "code" of the agent ` + strconv.Quote(written) + " can send data out"} + }}, + // Children are one level deep, so no set holds a grandchild. + {name: "a child gaining agents of its own", around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + s.calls(s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}), written) + writer := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}) + return map[string]any{"agents": []ChildAgent{{Config: writer.Name, Tool: "ask"}}}, []string{"agents are one level deep"} + }}, + // The false-positive side: a tool a person must allow first sends nothing out unasked. A + // child the parent still names but that is gone runs nothing, so it is left out. + {name: "a child gaining a tool a person allows under a sensitive parent", around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + s.calls(parent, written, "gone-"+s.utils.uuid()) + held := sessionGitHubGranting("code", "create_issue") + held["require_approval"] = []string{"create_issue"} + return map[string]any{"connectors": []map[string]any{held}}, nil + }}, + {name: "a sensitive parent beside a child whose tool a person allows", around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + held := sessionGitHubGranting("code", "create_issue") + held["require_approval"] = []string{"create_issue"} + writer := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{held}}) + return map[string]any{"connectors": []map[string]any{sessionNessy("customers")}, "agents": []ChildAgent{{Config: writer.Name, Tool: "ask"}}}, nil + }}, + // Taking out what breaks the rule is how a set stored before it held is mended: the config's + // stored copy is not weighed beside what is about to replace it. + {name: "a child taking out its tool that sends out under a sensitive parent", before: map[string]any{ + "connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}, + }, around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + s.calls(s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}), written) + return map[string]any{"connectors": []map[string]any{}}, nil + }}, + // The controls: on the base, 4a6dd1132, each of the four writes answered these the same + // (author-1.md, «Base probe»). + {name: "a child gaining a tool that sends out with nothing sensitive in the set", around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + s.calls(s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}), written) + return map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}, nil + }}, + {name: "a parent that sends out beside a child that sends out", around: func(s *ChildAgentsSuite, written string) (map[string]any, []string) { + writer := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}) + return map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}, "agents": []ChildAgent{{Config: writer.Name, Tool: "ask"}}}, nil + }}, +} + +func (s *ChildAgentsSuite) TestAWriteIsHeldToTheSensitiveConnectorRuleOverTheAgentsItWorksWith() { + for _, path := range configWrites { + for _, row := range graphWrites { + s.Run(path.name+"/"+row.name, func() { + s.useInternalApp() + written := AgentConfig{Name: "agent-" + s.utils.uuid()} + fields := map[string]any{} + if path.stored { + written = s.agentWith("echo/echo-model", row.before) + } else { + maps.Copy(fields, row.before) + } + sent, says := row.around(s, written.Name) + maps.Copy(fields, sent) + + status, answered := path.write(s, written, fields) + + if len(says) == 0 { + s.Contains([]int{http.StatusOK, http.StatusCreated}, status, answered) + return + } + s.Equal(http.StatusBadRequest, status, answered) + for _, said := range says { + s.Contains(s.failureMessage(answered), said) + } + if !strings.Contains(says[0], "one level deep") { + s.Contains(s.failureMessage(answered), "change them first and save this one after") + } + }) + } + } +} + +// A config renamed to the name a parent calls becomes that parent's child. +func (s *ChildAgentsSuite) TestARenameIntoTheNameASensitiveParentCallsIsRefused() { + s.useInternalApp() + written := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}) + parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + slot := "agent-" + s.utils.uuid() + s.calls(parent, slot) + + for _, method := range []string{http.MethodPut, http.MethodPatch} { + status, answered := s.writeConfig(method, "/v1/agents/configs/"+written.Id, slot, nil) + + s.Equal(http.StatusBadRequest, status, answered) + s.Contains(s.failureMessage(answered), `of the agent `+strconv.Quote(slot)+" can send data out") + } +} + +// A child with two parents names the older one when it is refused for having one. +func (s *ChildAgentsSuite) TestAChildWithTwoParentsNamesTheOlderOne() { + child := s.textConfig("echo/echo-model") + older, newer := s.agentWith("fanning/fanning-model", nil), s.agentWith("fanning/fanning-model", nil) + s.calls(older, child.Name) + s.calls(newer, child.Name) + + status, payload := s.serverClient.call(http.MethodDelete, "/v1/agents/configs/"+child.Id, nil) + + s.Equal(http.StatusConflict, status, string(payload)) + s.Contains(s.failureMessage(string(payload)), strconv.Quote(older.Name)+" hands work to this agent") +} + +// calls makes parent hand work to each of children by name, past the API's checks, as a set +// saved before the rule held across agents is stored, and one named before it exists. +func (s *ChildAgentsSuite) calls(parent AgentConfig, children ...string) { + s.change(parent.Id, func(config *store.AgentConfig) { + for i, child := range children { + config.Agents = append(config.Agents, store.ChildAgent{Config: child, Tool: "ask_" + strconv.Itoa(i)}) + } + }) +} + +// writeConfig sends a text agent on echo called name, with fields, and answers the status and +// the body. +func (s *ChildAgentsSuite) writeConfig(method, path, name string, fields map[string]any) (int, string) { + request := map[string]any{"name": name, "mode": "text", "llm": "echo/echo-model"} + maps.Copy(request, fields) + status, payload := s.serverClient.call(method, path, request) + return status, string(payload) +} + +// failureMessage is the message of the failure answered. +func (s *ChildAgentsSuite) failureMessage(answered string) string { + var failure ErrorResponse + s.Require().NoError(json.Unmarshal([]byte(answered), &failure), answered) + return failure.Error.Message +} diff --git a/acceleration/internal/connectors/providers/AGENTS.md b/acceleration/internal/connectors/providers/AGENTS.md index e84bda8576..2b9325ff9d 100644 --- a/acceleration/internal/connectors/providers/AGENTS.md +++ b/acceleration/internal/connectors/providers/AGENTS.md @@ -15,7 +15,7 @@ The built-in connector manifests: one `.yaml` per connector, in the schema ` - **Every vendor fact carries its source** in a comment beside it: a vendor page (with the date it was opened), a line of the prototype `internal/mcp/connectors.yaml` on `codex/connector-support` at `cf62af0d`, a row of the architecture doc (`acceleration/docs/connectors/architecture.md` on `connectors/planning`), or a fixture in `internal/connectors/core/testdata/manifests/`. A value with no source is marked `# unverified` and listed in the PR. - **`internal: true` hides a built-in from every app but Stream's own**: the lists, lookups, connections and OAuth clients of an app whose `apps.settings.internal_connectors` is `true` see it, any other app and any customer with no app row does not. A built-in takes `internal` from its latest revision at every revision, so making one internal (or public) later changes what every earlier revision shows; a custom definition is internal revision by revision. Check: `go test -tags integration -run 'TestStoreSuite/.*(Internal|Flag|Public)' ./internal/store`. - **`owner_email: true` makes a user-owned connection's first consent sign in as its owner** (`nessy.yaml` revision 4, AI-1543): the `email` captured from the `id_token` must be the one the app's backend last sent for that user in `X-Stream-User-Email`, compared without case; otherwise the consent ends `account_mismatch` and nothing is stored. It needs a required `email` capture from the `id_token`, so the scheme checks the token's `iss`, `aud` and `exp`; an `email_verified` capture, which refuses the consent when not `true`, must come from the `id_token` too, never the browser's `callback_query`. Check: `go test -tags integration -run 'TestAuthorizationsSuite/(TestAnOwners|TestAnotherPerson|TestAConsentIsRefusedWhen|TestAChatConsentIsChecked)' ./internal/api`, and `go test -run 'TestManifestSuite/TestOwnerEmail' ./internal/connectors/core`. -- **`sensitive: true` keeps outbound tools away from a connector that reads private data** (AI-1545, `nessy.yaml` revision 2). A config that binds one is refused with a 400 naming each tool that sends data out: a binding whose connector has a source that does not say `outbound: false`, a binding with `sandbox` set, and a sandbox that reaches the network (`ConfigComplaint`, `internal/connectors/sensitive`). `sources[].outbound: false` says the server offers only tools that read, with a vendor source beside it; `sources[].read_only_tools` names the tools that only read on a server that also offers tools that write (`bigquery.yaml`, `google_docs.yaml`, `google_drive.yaml`), and a binding granting only those by name is not outbound; `tool_patterns` stay outbound. Left out, a tool may write, so it sends data out. Tools a caller declares at createSession are the caller's and are not checked (AI-1642): one that sends data on to others should carry `approval`. On a voice call the router asks the user; in text the caller's client must wait for `tool_approval` before it runs the tool. Check: `go test -tags integration -run 'TestConfigsSuite/(TestNessy|TestAConfigWithoutASensitive|TestAnUpdateOrAPatch|TestAnUpdateKeepingABindingToAForceDeleted)|TestSyncSuite/TestASyncedNessy' ./internal/api`. +- **`sensitive: true` keeps outbound tools away from a connector that reads private data** (AI-1545, `nessy.yaml` revision 2). A config that binds one is refused with a 400 naming each tool that sends data out: a binding whose connector has a source that does not say `outbound: false`, a binding with `sandbox` set, and a sandbox that reaches the network (`ConfigComplaint`, `internal/connectors/sensitive`). The rule holds across child agents too: a parent and the agents it hands work to are one config to it, siblings included, so a write that leaves such a set breaking it is a 400 as well (`GraphComplaint`), and so is a delegation at run time. `sources[].outbound: false` says the server offers only tools that read, with a vendor source beside it; `sources[].read_only_tools` names the tools that only read on a server that also offers tools that write (`bigquery.yaml`, `google_docs.yaml`, `google_drive.yaml`), and a binding granting only those by name is not outbound; `tool_patterns` stay outbound. Left out, a tool may write, so it sends data out. Tools a caller declares at createSession are the caller's and are not checked (AI-1642): one that sends data on to others should carry `approval`. On a voice call the router asks the user; in text the caller's client must wait for `tool_approval` before it runs the tool. Check: `go test -tags integration -run 'TestConfigsSuite/(TestNessy|TestAConfigWithoutASensitive|TestAnUpdateOrAPatch|TestAnUpdateKeepingABindingToAForceDeleted)|TestSyncSuite/TestASyncedNessy|TestChildAgentsSuite/(TestADelegation|TestAWrite)' ./internal/api`. - **`scopes.covered_by` names, for a scope a tool needs, the broader scopes that meet it**, each with the vendor page saying the broader scope gives all the needed one gives (`google_drive.yaml` revision 6 and `google_docs.yaml` revision 5: `drive` covers `drive.file` and `documents`). Validate takes a grant holding one as holding the need, and a tool whose need an asked scope covers is offered (`core.ScopePolicy.Meets`). A scope a tool's page takes that gives less, such as Drive's `drive.appdata`, is not listed. A connection on an earlier revision gets it at its next consent. Check: `go test -run 'TestToolsetSuite/TestAGrantOfDrive' ./internal/connectors/providers`. - **Every id here is a provider name the core may not spell.** `TestCoreNamesNoProvider` (`internal/connectors/core/guard_test.go`) reads the ids from this directory into its deny list. - **No Go here beyond the embed and its tests** for now. A provider's hook (`hooks:` in a manifest) is the only Go a provider may need, and it is added with the hook registry, not before. diff --git a/acceleration/internal/connectors/sensitive/AGENTS.md b/acceleration/internal/connectors/sensitive/AGENTS.md index d0ded8c82b..e35fa50f64 100644 --- a/acceleration/internal/connectors/sensitive/AGENTS.md +++ b/acceleration/internal/connectors/sensitive/AGENTS.md @@ -3,8 +3,8 @@ The rule that keeps a connector whose manifest says `sensitive: true` (its tools read private data) away from what may send data out with no person's approval: a binding to a source that does not say `outbound: false` (unless each tool it grants is in `read_only_tools` or its `require_approval`), a binding with `sandbox` set, and a sandbox that reaches the network. - `ConfigComplaint` checks one agent config. Config writes call it (`internal/api`: create, update, patch, sync), so a config that breaks it is a 400. -- `GraphComplaint` checks a parent and its child agents as one config. A parent hands its input to each child and reads each answer, so what one reads may reach any other, a sibling's tools included. `childRunner.Run` (`internal/session/child_agents.go`) calls it on every delegation, with the parent as it runs and each child as stored now, and refuses a delegation that breaks it with a tool error the model reads. +- `GraphComplaint` checks a parent and its child agents as one config. A parent hands its input to each child and reads each answer, so what one reads may reach any other, a sibling's tools included. Config writes call it (`sensitiveGraphComplaint`, `internal/api/child_agents.go`) over the config with its children and over each parent that calls the config with all of that parent's children, so a set that breaks it is a 400 naming the agents, the bindings and the connector, even for a save that changes another field. `childRunner.Run` (`internal/session/child_agents.go`) calls it on every delegation, with the parent as it runs and each child as stored now, and refuses a delegation that breaks it with a tool error the model reads: it covers a set stored before the writes checked it. It lives here, not in `internal/api`, because `internal/api` imports `internal/session`, and both need it. It reads only the store and the manifest model. -Check: `go test -tags integration -run 'TestChildAgentsSuite/TestADelegation|TestConfigsSuite/TestNessy' ./internal/api`. +Check: `go test -tags integration -run 'TestChildAgentsSuite/(TestADelegation|TestAWrite)|TestConfigsSuite/TestNessy' ./internal/api`. diff --git a/acceleration/internal/store/agent_config.go b/acceleration/internal/store/agent_config.go index e512c01110..9cb6c5d111 100644 --- a/acceleration/internal/store/agent_config.go +++ b/acceleration/internal/store/agent_config.go @@ -655,28 +655,25 @@ func (r *AgentConfigs) GetByChatChannel(ctx context.Context, customerID, channel return config, nil } -// NameCalling is the name of a live config the customer holds, other than except, whose agents -// name the config called child, and empty when none does. -func (r *AgentConfigs) NameCalling(ctx context.Context, customerID, child, except string) (string, error) { +// Calling is every live config the customer holds, other than except, whose agents name the +// config called child, oldest first, and none when none does. +func (r *AgentConfigs) Calling(ctx context.Context, customerID, child, except string) ([]AgentConfig, error) { named, err := json.Marshal([]map[string]string{{"config": child}}) if err != nil { - return "", stack.Wrap(err) + return nil, stack.Wrap(err) } - var parent string - err = r.store.global.NewSelect().Model((*AgentConfig)(nil)).Column("name"). + var parents []AgentConfig + err = r.store.global.NewSelect().Model(&parents). Where("customer_id = ?", customerID). Where("id <> ?", except). Where("agents @> ?::jsonb", string(named)). Where("deleted_at IS NULL"). - Limit(1). - Scan(ctx, &parent) - if errors.Is(err, sql.ErrNoRows) { - return "", nil - } + Order("created_at", "id"). + Scan(ctx) if err != nil { - return "", stack.Wrap(fmt.Errorf("store: agent config calling: %w", err)) + return nil, stack.Wrap(fmt.Errorf("store: agent configs calling: %w", err)) } - return parent, nil + return parents, nil } // Select returns every live config a customer holds, newest first. It is not paged: a diff --git a/acceleration/internal/store/agent_config_test.go b/acceleration/internal/store/agent_config_test.go index dc28d21442..1e05160ec5 100644 --- a/acceleration/internal/store/agent_config_test.go +++ b/acceleration/internal/store/agent_config_test.go @@ -303,6 +303,34 @@ func (s *StoreSuite) TestADeleteARequestGaveUpOnIsNotCachedAgainByAReadBeforeItC s.NoError(err, "the delete outlives the request that asked for it") } +// Calling is every parent of a child, oldest first, and leaves out the one excepted, a deleted +// one and another customer's. +func (s *StoreSuite) TestCallingIsEveryLiveParentOfAChildOldestFirst() { + customer := "calling-" + newID() + child := "child-" + newID() + parent := func(customerID string) AgentConfig { + config := &AgentConfig{CustomerID: customerID, Name: "parent-" + newID(), Mode: AgentModeText, + Agents: []ChildAgent{{Config: "other-" + newID(), Tool: "other"}, {Config: child, Tool: "ask"}}} + s.Require().NoError(s.store.AgentConfigs.Insert(s.ctx, config)) + return *config + } + older, excepted, deleted, newer := parent(customer), parent(customer), parent(customer), parent(customer) + parent("other-" + customer) + s.Require().NoError(s.store.AgentConfigs.Delete(s.ctx, customer, deleted.ID)) + + parents, err := s.store.AgentConfigs.Calling(s.ctx, customer, child, excepted.ID) + + s.Require().NoError(err) + var called []string + for _, found := range parents { + called = append(called, found.Name) + } + s.Equal([]string{older.Name, newer.Name}, called) + none, err := s.store.AgentConfigs.Calling(s.ctx, customer, "nobody-"+newID(), "") + s.Require().NoError(err) + s.Empty(none) +} + func (s *StoreSuite) TestAgentConfigQueryBudgets() { for range 20 { s.boundConfig("acme-app") @@ -326,9 +354,10 @@ func (s *StoreSuite) TestAgentConfigQueryBudgets() { s.Require().NoError(err) })) s.Equal(1, s.countQueries(func() { - parent, err := s.store.AgentConfigs.NameCalling(s.ctx, "acme-app", "child", "") + parents, err := s.store.AgentConfigs.Calling(s.ctx, "acme-app", "child", "") s.Require().NoError(err) - s.Equal("moderator", parent) + s.Require().Len(parents, 1) + s.Equal("moderator", parents[0].Name) })) s.Equal(1, s.countQueries(func() { _, err := s.store.AgentConfigs.GetUnscoped(s.ctx, config.ID)