Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .claude/skills/connectors/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ binding grants, and `sandbox: true` is refused beside it (`session/connector_app
Beside a sensitive connector (Nessy), a binding's write tool needs `require_approval`: the
config is refused unless each tool it grants only reads (`read_only_tools`) or is held, and a
`tool_patterns` binding needs an entry such as `*` that matches each pattern as written
(`api/configs.go`, `sensitiveBindingsComplaint`). In agent.yaml it is `require_approval:` on
(`connectors/sensitive`, `ConfigComplaint`; across a parent and its child agents, `GraphComplaint`). In agent.yaml it is `require_approval:` on
the connector entry. Tools a caller declares at createSession are not checked. The caller runs
them, or a person's device does (`executor: client`). The router sends a client tool's
arguments to the caller on the events socket (`api/sessionws.go`). Every channel member can
Expand Down
197 changes: 197 additions & 0 deletions acceleration/internal/api/child_agents_sensitive_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
//go:build integration

package api

import (
"encoding/json"
"net/http"
"strconv"
"strings"

"github.com/GetStream/Vision-Agents/acceleration/internal/harness"
"github.com/GetStream/Vision-Agents/acceleration/internal/store"
)

// The graphs below are wired through the config store, past the API's checks, as a graph
// saved before the rule held across agents, or changed since, is stored.

func (s *ChildAgentsSuite) TestADelegationIsRefusedWhenTheParentIsSensitiveAndAChildSendsOut() {
s.useInternalApp()
parent := s.agentWith("fanning/fanning-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")}})
s.delegate(parent, map[string]AgentConfig{"ask_a": writer})

run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"})

s.refusedAll(run)
s.Contains(s.refusals(parent), strconv.Quote(parent.Name)+
`'s connector binding "customers" binds "nessy", whose tools read private data, and connector binding "code" `+
"of the agent "+strconv.Quote(writer.Name)+" can send data out with no person's approval")
}

func (s *ChildAgentsSuite) TestADelegationIsRefusedWhenAChildIsSensitiveAndTheParentSendsOut() {
s.useInternalApp()
parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}})
reader := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}})
s.delegate(parent, map[string]AgentConfig{"ask_b": reader})

run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"})

s.refusedAll(run)
s.Contains(s.refusals(parent), strconv.Quote(reader.Name)+`'s connector binding "customers" binds "nessy"`)
s.Contains(s.refusals(parent), `and connector binding "code" of the agent `+strconv.Quote(parent.Name)+" can send data out")
}

// Neither child alone breaks the rule, nor does the parent: the parent hands one child's
// answer to the other.
func (s *ChildAgentsSuite) TestADelegationIsRefusedWhenOneChildIsSensitiveAndASiblingSendsOut() {
s.useInternalApp()
parent := s.agentWith("fanning/fanning-model", nil)
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")}})
s.delegate(parent, map[string]AgentConfig{"ask_a": reader, "ask_b": writer})

run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"})

s.refusedAll(run)
s.Contains(s.refusals(reader), strconv.Quote(reader.Name)+
`'s connector binding "customers" binds "nessy", whose tools read private data, and connector binding "code" `+
"of the agent "+strconv.Quote(writer.Name)+" can send data out")
}

func (s *ChildAgentsSuite) TestADelegationIsRefusedWhenAChildsSandboxReachesTheNetworkBesideASensitiveParent() {
s.useInternalApp()
parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}})
coder := s.agentWith("echo/echo-model", map[string]any{"sandbox": "daytona", "sandbox_options": map[string]any{"network": true}})
s.delegate(parent, map[string]AgentConfig{"ask_c": coder})

run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"})

s.refusedAll(run)
s.Contains(s.refusals(coder), strconv.Quote(parent.Name)+
`'s connector binding "customers" binds "nessy", whose tools read private data, and the sandbox's network `+
"access of the agent "+strconv.Quote(coder.Name)+" can send data out")
s.NotContains(s.refusals(coder), "require_approval", "a sandbox has no tool a require_approval could hold")
}

// The parent's own sandbox is part of the graph: it can send out what a sensitive child answered.
func (s *ChildAgentsSuite) TestADelegationIsRefusedWhenTheParentsSandboxReachesTheNetworkBesideASensitiveChild() {
s.useInternalApp()
parent := s.agentWith("fanning/fanning-model", map[string]any{"sandbox": "daytona", "sandbox_options": map[string]any{"network": true}})
reader := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}})
s.delegate(parent, map[string]AgentConfig{"ask_a": reader})

run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"})

s.refusedAll(run)
s.Contains(s.refusals(parent), strconv.Quote(reader.Name)+
`'s connector binding "customers" binds "nessy", whose tools read private data, and the sandbox's network `+
"access of the agent "+strconv.Quote(parent.Name)+" can send data out")
}

// The false-positive side: a write tool a person must allow first sends nothing out unasked.
// A sibling deleted since the parent was saved is skipped, as its own call is refused.
func (s *ChildAgentsSuite) TestADelegationBesideASensitiveConnectorRunsWhenEachOutboundToolNeedsApproval() {
s.useInternalApp()
parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}})
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}})
deleted := s.agentWith("echo/echo-model", nil)
s.delegate(parent, map[string]AgentConfig{"ask_a": writer, "ask_c": deleted})
s.Require().NoError(s.store.AgentConfigs.Delete(s.T().Context(), s.customerID(), deleted.Id))

run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"})

s.NotContains(run.FinalText, "was not run")
s.Contains(run.FinalText, "tool: be brief", "the held child answered")
s.Contains(run.FinalText, "tool: That did not work: the agent "+strconv.Quote(deleted.Name)+" behind ask_c no longer exists")
}

// A child whose tool has the name of another tool is not offered, so it runs nothing a
// sibling could read.
func (s *ChildAgentsSuite) TestADelegationRunsBesideASensitiveChildTheParentDoesNotOffer() {
s.useInternalApp()
parent := s.agentWith("fanning/fanning-model", nil)
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")}})
s.delegate(parent, map[string]AgentConfig{"ask_a": writer})
s.change(parent.Id, func(config *store.AgentConfig) {
config.Agents = append(config.Agents, store.ChildAgent{Config: reader.Name, Tool: harness.LoadSkillTool})
})

run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"})

s.NotContains(run.FinalText, "was not run")
s.Contains(run.FinalText, "tool: be brief")
}

// TestADelegationWithNoSensitiveConnectorRuns is the control: on the base, dca845c2e, the
// same graph answered the same (author-1.md, «Control probe»).
func (s *ChildAgentsSuite) TestADelegationWithNoSensitiveConnectorRuns() {
parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}})
writer := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}})
s.delegate(parent, map[string]AgentConfig{"ask_a": writer})

run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"})

s.NotContains(run.FinalText, "That did not work")
s.Contains(run.FinalText, "tool: be brief")
}

// useInternalApp gives the test an app Stream marks internal, the only kind that sees nessy.
func (s *ChildAgentsSuite) useInternalApp() {
s.useApp(s.data.createAppAdmitting(store.AppSettings{InternalConnectors: new(true)}))
}

// agentWith is a text agent config of the app answered by model, with fields.
func (s *ChildAgentsSuite) agentWith(model string, fields map[string]any) AgentConfig {
request := map[string]any{"name": "agent-" + s.utils.uuid(), "mode": "text", "llm": model, "instructions": "be brief"}
for key, value := range fields {
request[key] = value
}
status, payload := s.serverClient.call(http.MethodPost, "/v1/agents/configs", request)
s.Require().Equal(http.StatusCreated, status, string(payload))
var created AgentConfig
s.Require().NoError(json.Unmarshal(payload, &created))
return created
}

// delegate makes parent call each of fanned: the config children names for it, or else an
// agent with no connector.
func (s *ChildAgentsSuite) delegate(parent AgentConfig, children map[string]AgentConfig) {
var agents []store.ChildAgent
for _, tool := range fanned {
child, ok := children[tool]
if !ok {
child = s.agentWith("echo/echo-model", nil)
}
agents = append(agents, store.ChildAgent{Config: child.Name, Tool: tool})
}
s.change(parent.Id, func(config *store.AgentConfig) { config.Agents = agents })
}

// refusals is the log's lines about a refused delegation that name config, with what the tool error leaves out.
func (s *ChildAgentsSuite) refusals(config AgentConfig) string {
var lines []string
for line := range strings.SplitSeq(s.logged.String(), "\n") {
if strings.Contains(line, "a delegation was refused") && strings.Contains(line, config.Name) {
lines = append(lines, line)
}
}
// The text handler quotes the complaint, and its own quotes with it.
return strings.ReplaceAll(strings.Join(lines, "\n"), `\`, "")
}

// refusedAll requires every delegation of the run refused, and the parent to have answered. What
// the model and the end user read names no binding, connector or tool: the log has the complaint.
func (s *ChildAgentsSuite) refusedAll(run Run) {
for _, tool := range fanned {
s.Contains(run.FinalText, "tool: That did not work: "+tool+" was not run: the agents it works with together read private data and can send data out",
"the graph breaks the rule whichever child is called")
}
s.NotContains(run.FinalText, "tool: be brief", "no child ran")
for _, name := range []string{"nessy", "customers", "create_issue", "binding", "connector", "sandbox", "require_approval"} {
s.NotContains(run.FinalText, name, "the tool error names nothing of a server-side config")
}
}
9 changes: 9 additions & 0 deletions acceleration/internal/api/child_agents_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import (
"testing"
"time"

"github.com/GetStream/Vision-Agents/acceleration/internal/connectors/providers"
"github.com/GetStream/Vision-Agents/acceleration/internal/harness"
"github.com/GetStream/Vision-Agents/acceleration/internal/llm"
"github.com/GetStream/Vision-Agents/acceleration/internal/llmrouter"
"github.com/GetStream/Vision-Agents/acceleration/internal/routing"
"github.com/GetStream/Vision-Agents/acceleration/internal/sandbox/daytona/daytonatest"
"github.com/GetStream/Vision-Agents/acceleration/internal/store"
)

Expand All @@ -39,6 +41,8 @@ type ChildAgentsSuite struct {
// offeredMu guards offered, the tools each request of offering was offered, by name.
offeredMu sync.Mutex
offered [][]string
// logged is what the router logs, for the tests about what a refused delegation logs.
logged *lockedLog
}

func TestChildAgentsSuite(t *testing.T) {
Expand Down Expand Up @@ -81,7 +85,12 @@ func (s *ChildAgentsSuite) SetupSuite() {
return &chainingLLM{}, nil
})
}
s.logged = &lockedLog{}
s.logs = s.logged
s.daytona = daytonatest.Start(s.T())
s.RouterSuite.SetupSuite()
// The catalog, for the children that bind its connectors (child_agents_sensitive_test.go).
s.Require().NoError(s.store.ConnectorDefinitions.Seed(context.Background(), providers.FS))
}

func (s *ChildAgentsSuite) SetupTest() {
Expand Down
107 changes: 3 additions & 104 deletions acceleration/internal/api/configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"

"github.com/GetStream/Vision-Agents/acceleration/internal/connectors/core"
"github.com/GetStream/Vision-Agents/acceleration/internal/connectors/sensitive"
"github.com/GetStream/Vision-Agents/acceleration/internal/conversation"
"github.com/GetStream/Vision-Agents/acceleration/internal/egress"
"github.com/GetStream/Vision-Agents/acceleration/internal/guardrail"
Expand Down Expand Up @@ -1046,111 +1047,9 @@ func sandboxOfConfig(config store.AgentConfig) *savedSandbox {
Granted: slices.ContainsFunc(config.Connectors, func(binding store.ConnectorBinding) bool { return binding.Sandbox })}}
}

// sensitiveBindingsComplaint refuses a config that binds a sensitive connector, one whose
// manifest says its tools read private data, together with a tool that sends data out: a
// model that reads untrusted text could be steered into sending out what it read («Nessy as
// a connector» on AI-1538, change 13). These send data out:
// - a binding whose connector has a source that does not say outbound: false, as one of its
// tools may write, unless each tool it grants is in the source's read_only_tools or its
// require_approval, which holds every call for a person to allow, and a binding with
// sandbox set, whose code calls the connector's whole API;
// - a sandbox that may reach the network.
//
// Only a binding's require_approval asks a person before a call is sent; the others ask
// nobody. It reads the config as it is about to be stored.
func SensitiveBindingsComplaint(ctx context.Context, definitions store.Definitions, customerID string, config store.AgentConfig) (string, bool, error) {
var sensitive *store.ConnectorBinding
var outbound, unheld []string
for i, binding := range config.Connectors {
definition, err := definitions.Latest(ctx, customerID, binding.ConnectorID)
// A forced connector delete leaves its bindings behind (store.refuseUndefined), and
// a binding to a connector with no definition opens nothing.
if errors.Is(err, store.ErrNoConnectorDefinition) {
continue
}
if err != nil {
return "", false, err
}
if definition.Manifest.Sensitive {
sensitive = &config.Connectors[i]
}
if tools, sends := bindingSendsOut(binding, definition.Manifest); sends {
outbound = append(outbound, fmt.Sprintf("connector binding %q", binding.Name))
if len(tools) > 0 {
unheld = append(unheld, fmt.Sprintf("%q %s", binding.Name, strings.Join(tools, ", ")))
}
}
}
if sensitive == nil {
return "", true, nil
}
if config.Sandbox.Provider != "" && !config.Sandbox.Options.Isolated() {
outbound = append(outbound, "the sandbox's network access")
}
if len(outbound) == 0 {
return "", true, nil
}
message := fmt.Sprintf("connector binding %q binds %q, whose tools read private data, and %s can send data out "+
"with no person's approval: take them out of this config", sensitive.Name, sensitive.ConnectorID,
strings.Join(outbound, ", "))
if len(unheld) > 0 {
message += ", or add to each binding's require_approval its tools that do not only read: " +
strings.Join(unheld, "; ")
}
return message, false, nil
}

// sensitiveBindingsComplaint is SensitiveBindingsComplaint over the server's store.
// sensitiveBindingsComplaint is sensitive.ConfigComplaint over the server's store.
func (s *Server) sensitiveBindingsComplaint(ctx context.Context, customerID string, config store.AgentConfig) (string, bool, error) {
return SensitiveBindingsComplaint(ctx, s.store.ConnectorDefinitions, customerID, config)
}

// bindingSendsOut reports whether a binding offers a tool that may send data out with nobody
// asked, and the names or patterns it grants such tools by: one of a source that does not say
// outbound: false, unless the binding grants it by name and the source lists it in
// read_only_tools, or its require_approval holds it, or the connector's API to sandbox code,
// which names none. A tool pattern matches tools only a session lists, so it sends out if any
// source may and its require_approval does not hold all it matches. A binding does not say
// which source a granted name comes from, so it sends out if any source may send it. A
// connector with no source offers no tool, and neither does a binding that grants none.
func bindingSendsOut(binding store.ConnectorBinding, manifest core.Manifest) ([]string, bool) {
if binding.Sandbox {
return nil, true
}
var unheld []string
if binding.ToolPatterns != nil {
if !slices.ContainsFunc(manifest.Sources, core.SourceRule.SendsOut) {
return nil, false
}
for _, pattern := range *binding.ToolPatterns {
if !holdsPattern(binding, pattern) {
unheld = append(unheld, pattern)
}
}
return unheld, len(unheld) > 0
}
for _, tool := range binding.Tools {
if manifest.SendsOutTool(tool.Name) && !binding.RequiresApproval(tool.Name) {
unheld = append(unheld, tool.Name)
}
}
return unheld, len(unheld) > 0
}

// holdsPattern reports whether the binding's require_approval holds every tool a tool pattern
// matches: an entry does when it matches the pattern as written and has no wildcard or escape
// but *, such as * or create_* for create_*, as each * then also matches what the pattern's
// wildcards stand for. An entry's ? or class matches one character where the pattern's * may
// stand for several, an escaped \* only the pattern's own *, and the pattern's class may stand
// for a / that no * matches, so none of them is taken to hold the pattern.
func holdsPattern(binding store.ConnectorBinding, pattern string) bool {
if strings.Contains(pattern, "[") {
return false
}
return slices.ContainsFunc(binding.RequireApproval, func(entry string) bool {
matched, _ := path.Match(entry, pattern)
return matched && !strings.ContainsAny(entry, `?[\`)
})
return sensitive.ConfigComplaint(ctx, s.store.ConnectorDefinitions, customerID, config)
}

// storedBindings turns the bindings a caller sent into what a config stores, as written.
Expand Down
3 changes: 2 additions & 1 deletion acceleration/internal/api/configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2392,7 +2392,7 @@ func (s *ConfigsSuite) TestABindingBesideNessyMayGrantExactlyTheToolsFlaggedRead
}

// read_only is read from the connector's latest revision, as a config save beside nessy reads
// it (SensitiveBindingsComplaint), not from the revision the connection pins: a connection
// it (sensitive.ConfigComplaint), not from the revision the connection pins: a connection
// pinned to revision 1, which leaves search_documentation out of read_only_tools, flags it
// read_only once revision 2 lists it, and a binding granting it sits beside nessy.
func (s *ConfigsSuite) TestReadOnlyIsTheConnectorsLatestRevisionsAsAConfigSaveChecks() {
Expand Down Expand Up @@ -2677,6 +2677,7 @@ func (s *ConfigsSuite) TestNessyBesideASandboxIsRefusedOnlyWhenItReachesTheNetwo

s.Equal(http.StatusBadRequest, status, name)
s.Contains(failure, "and the sandbox's network access can send data out", name)
s.NotContains(failure, "require_approval", "a sandbox has no tool a require_approval could hold")
}
}

Expand Down
2 changes: 1 addition & 1 deletion acceleration/internal/api/connection_tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ func (s *Server) listConnectionTools(ctx context.Context, request *connectionReq
return nil, err
}
// The latest revision, not the one the connection pins: it is what a config save checks a
// binding beside a sensitive connector against (SensitiveBindingsComplaint).
// binding beside a sensitive connector against (sensitive.ConfigComplaint).
// A connector the app can no longer see has no definition: a save skips such a binding, so
// no tool of it is a read (read_only false) and the tools are still listed.
definition, err := s.store.ConnectorDefinitions.Latest(ctx, connection.CustomerID, connection.ConnectorID)
Expand Down
Loading
Loading