Skip to content

Room invites should respect who can talk to an agent #805

Open

Description

@amaudruz

What

An agent's addressing policy ("who can talk to my agent", e.g. owner only) should also control who can invite that agent into a room.

Why

Today someone the owner hasn't allowed to talk to an agent can still pull it into their room. The agent then sits there, replying only that it can't act. That's confusing, and it lets anyone see where an agent is used.

How

The policy lives on the agent (addressing_policy; see core/switch_core/addressing.py). Invites come in through several paths, and all of them need the same check:

  • the !invite-agent chat command and /invite-agent slash command (core/switch_core/bridges/agent/commands.py)
  • the invite_agent_to_room MCP tool (bridges/agent/operations/definitions.py, protocol/agent_core.py)
  • the agent-bridge API (bridges/agent/api/handlers.py)
  • room creation with agents, and the gateway's room page

Put the check in one shared place, so a future invite path can't skip it. A refused invite must say why and who can do it (the owner).

Done when

  • Every invite path refuses someone the agent's policy doesn't allow, with a clear message
  • The owner (and anyone the policy allows) can still invite it
  • Agents already in rooms aren't kicked out (or the PR documents and justifies a different choice)
  • Tests for each path, against a real Postgres for store logic
  • Docs updated where addressing policies are described

Out of scope

Changing the addressing policy options themselves.

Activity

  1. afreenorbit commented on Oct 21, 2026

    @afreenorbit
    Contributor

    Hi @petr-sandbox! I'd like to take this one for the hackathon.

    In short: check the agent's addressing policy once, inside RoomService, where every invite path already ends up, so no path (current or future) can skip it. A refused invite says why and that the owner can add the agent.

    Image

    What I found tracing the invite paths (in core/switch_core/):

    • !invite-agent / /invite-agent (bridges/agent/commands.py) -> RoomService.add_agents_to_room
    • The invite_agent_to_room MCP tool and the agent API route (operations/definitions.py, api/handlers.py) -> AgentCore.invite_agent_to_room -> add_agents_to_room. I see Remove the legacy agent moderation routes #993 removes the legacy moderation routes, so I'll build on whatever is left after it.
    • The gateway's room page (gateway/rooms.py, POST /{room_id}/agents) -> add_agents_to_room
    • Creating a room with agents (gateway, agent API, MCP create_room, rooms_yaml.py templates) -> RoomService.create_room
    • The policy lives in addressing.py (pure rules: rooms, groups, users, agents, owner, owner_agents). delivery/addressing.py resolves who a sender is and answers permitted(...).

    So two RoomService methods cover every path.

    Plan:

    1. One check: a may_invite(inviter, agent, room) built on the same rules and sender resolution as permitted, so "who may invite" always means "who may talk to it". An open policy keeps its fast path.
    2. Who invites becomes a required argument of add_agents_to_room and create_room (a person, an agent, or the system acting for a person). Every caller has to say who is inviting, which is what stops a future path from skipping the check.
    3. A clear refusal, e.g. "Only @owner (or someone their policy allows) can add @agent to a room." It shows up in chat, as an MCP/API error (403) and in the gateway.
    4. Agents already in rooms stay there. The check only runs on new invites.
    5. Docs: update the Switch skill (switch-skill/SKILL.md), so agents know an invite can be refused and why, and the switch-buddy / switch-expert instructions where they explain addressing policies. The published pages under docs/official/ come from the docs repo, so I'll note what needs changing there in the PR.

    Two questions before I start:

    • System joins: when someone adds the bot to a channel on the platform itself (collaboration_core.py, added_by_kind="system"), should that be judged as the person who did it where the platform reports them, and allowed otherwise?
    • Templates: should a template run be judged as the person running it?

    Done when:

    Item How I'll show it
    Every invite path refuses a disallowed person, with a clear message A test per path: chat command, MCP tool, API, gateway, room creation
    Owner and anyone the policy allows can still invite Tests for owner, an allowed user, owner_agents and an open policy
    Agents already in rooms aren't removed Test with an agent added before its policy was tightened
    Tests against real Postgres for store logic In core/tests/switch_core/, using the existing Postgres fixtures
    Docs updated Switch skill and switch-buddy / switch-expert instructions; the docs/official/ changes listed in the PR for the docs repo

    No AI model is needed to test any of this. Before opening the PR I'll run just check, just typecheck and just test.

    I haven't written any code yet and will only start once this is assigned to me. I've also asked for #806; I'll work on whichever one I'm assigned first, and only start the other once that PR is up.

  2. ANAMASGARD commented on Oct 21, 2026

    @ANAMASGARD

    Hi @amaudruz and @petr-sandbox — Room invites should not bypass the same permission that controls addressing the agent. I see another contributor has expressed interest; if you are still considering candidates, I'd be happy to be considered.

    • Put one shared policy check in core/switch_core/room_service.py, covering both add_agents_to_room() and creation with initial agents, before membership/channel side effects. Reuse addressing.py and delivery/addressing.py semantics rather than inventing a separate invite allow-list.
    • Pass verified inviter identity through chat/slash commands, MCP/API, gateway and templates. Resolve owner/owner-agent and room/group rules consistently; do not treat an unresolved external sender as the platform or grant an implicit admin bypass. Confirm the policy for platform-origin joins before coding; existing members stay untouched, and refusals explain that the owner or an allowed person can invite.
    • Planned tests: each entry path, owner/allowed/denied/unclaimed senders, scoped rules, no membership side effects on denial, and existing members retained, using real Postgres for store behavior. Update addressing-policy docs. No tests have been run yet.
    flowchart LR
      A[Verified inviter] --> B[Shared addressing check]
      B --> C[Invite or clear refusal]
    
    Loading

    I would start implementation only after assignment and within the allowed hackathon window.

  3. petr-sandbox commented on Oct 22, 2026

    @petr-sandbox
    Collaborator

    Thank you all for your interest and participation in our hackathon! In the interest of fairness, we will not be assigning issues to individual participants but instead let anyone try and solve any number of them.

  4. petr-sandbox commented on Oct 22, 2026

    @petr-sandbox
    Collaborator

    Thanks @afreenorbit and @ANAMASGARD. Here is the policy:

    • Joins made on the platform (someone adds the bot to a channel directly, today recorded as added_by_kind="system"): judge them as the person who added the bot whenever the platform reports who did it. InboundAgentJoin carries no inviter yet, so add one for adapters that can report it (Slack does, for example). When the platform doesn't report who it was, let the join through, but say so:

      • post a notice in the room that Switch couldn't verify who added the agent and that its owner can remove it;
      • log a warning;
      • tell the owner.

      Nobody gets an implicit admin bypass, and an unknown inviter is never treated as trusted.

    • Template runs: judge them as the person running the template. Agents the template creates belong to that person; existing agents owned by others are checked against the runner.

    • Agent invites (invite_agent_to_room): judge them as the inviting agent, which the owner_and_owner_agents policy already covers.

    The check should still live in one shared place that every path, including platform joins, goes through.

  5. jmass-ggg commented on Oct 22, 2026

    @jmass-ggg
    Contributor

    Hi @petr-sandbox and @amaudruz,

    I'd like to contribute to #805 for the Flip the Switch Hackathon.

    The issue is important because an agent's addressing policy should protect not only who can communicate with it, but also who can invite it into a room. I would focus on enforcing that rule at the shared room-service layer, so the different entry points cannot accidentally bypass it.

    Proposed implementation

    1. Centralize authorization: Introduce a reusable invitation-policy check in the shared room-service path, using the existing addressing_policy rules instead of creating a separate permission model.

    2. Cover every invitation path: Apply the check to chat/slash commands, the invite_agent_to_room MCP operation, agent-bridge APIs, Gateway room management, and room creation with initial agents.

    3. Preserve inviter identity: Evaluate ordinary invitations against the verified requester, template invitations against the template runner, and agent-origin invitations against the inviting agent.

    4. Handle platform-origin joins correctly: Following the latest maintainer clarification, use the actual inviter when the platform provides it. If a platform cannot identify who added the agent, allow the join with a visible room notice, owner notification, and warning log—without silently treating the unknown inviter as trusted.

    5. Avoid regressions: Reject unauthorized new invitations before membership side effects while leaving existing room membership unchanged.

    Proposed architecture

    flowchart TD
        A["Chat / MCP / Gateway / Templates / Platform"] --> B["Shared Room Service"]
        B --> C["Resolve inviter identity"]
        C --> D{"Known inviter?"}
        D -->|Yes| E{"Addressing policy allows?"}
        E -->|Yes| F["Complete invitation"]
        E -->|No| G["Reject with clear explanation"]
        D -->|Unknown platform join| H["Allow + notify owner and room + log"]
    
    Loading

    Verification

    I'll add tests for owner, owner-agent, permitted and denied users, templates, platform-origin joins with missing identity, and every supported invitation entry point.

    I'll also check that rejected invitations have no database side effects, using real PostgreSQL-backed integration tests where required, and update the addressing-policy documentation.

    I understand the updated open-participation policy, so I'm not requesting an exclusive assignment. I'd appreciate confirmation that this approach matches the expected authorization boundary, particularly for unidentified platform-origin joins.

    Thank you!

  6. afreenorbit commented on Oct 22, 2026

    @afreenorbit
    Contributor

    Thanks @petr-sandbox, that’s clear. I’ve built it to that policy: platform joins are judged as whoever added the bot (Slack and Telegram report it), an unknown adder is let in with a notice in the room and a logged warning, templates are judged as the runner, and agent invites as the inviting agent, all through one shared check. I’ll open the PR in the hackathon window.

  7. Kulraj69 commented on Oct 23, 2026

    @Kulraj69

    Hi @petr-sandbox, I'm in the Flip the Switch hackathon and would like to take this one. I've gone through the invite flow in create_room / invite_agent_to_room and the agent DM-permission settings, and plan to enforce the target agent's allowlist on room invites with tests. Could you assign it to me?

  8. afreenorbit commented on Oct 24, 2026

    @afreenorbit
    Contributor

    @petr-sandbox the PR is up: #1043. It follows your policy above. Platform joins are judged as whoever added the bot when the platform says (Slack and Telegram do). An unknown adder is let in with a room notice, a warning log and an @-mention of the owner. Templates are judged as the runner, and agent invites as the inviting agent. Everything goes through one gate.

    One thing to flag: Switch has no direct way to notify an owner today, so if the owner hasn't linked a chat account, the room notice and the warning log are all there is. The PR says more, and I'm happy to add a direct notification if you want one.

  9. 9 remaining items

  10. BUTTERFINGERS7498 commented on Nov 4, 2026

    @BUTTERFINGERS7498

    Hi @petr-sandbox, I'd like to work on this by putting the permission check where all invite paths share it. I'll follow your clarification about checking the actual inviter, including template runs and agents inviting other agents. When a platform can't tell us who added the bot, I'll keep the join but make that uncertainty visible to the room and owner, with no implicit admin bypass.

  11. Aryan-Techie commented on Nov 4, 2026

    @Aryan-Techie

    @petr-sandbox I'd like to pick this one up.

    Plan

    • One shared check, not four. A single function beside the addressing rules (core/switch_core/addressing.py / delivery/addressing.py) answers "may this actor put this agent in this room", and every invite path calls it: the !invite-agent chat command and /invite-agent slash command (bridges/agent/commands.py), the invite_agent_to_room MCP tool (bridges/agent/operations/definitions.py and protocol/agent_core.py), the agent-bridge API (bridges/agent/api/handlers.py), room creation with agents, and the gateway's room page. The point is that a future invite path has one obvious thing to call rather than a rule to remember.
    • The check reuses the existing addressing_policy evaluation rather than reimplementing it, so the two can't drift: whoever may address the agent may invite it, and nobody else.
    • A refusal says why and who can do it (the owner), in the same words on every path, rather than a bare 403. Following the repo's error philosophy, it raises rather than returning a boolean the caller can ignore.
    • Agents already in rooms are left alone: the check gates the invite, not membership, so nothing gets kicked out by an upgrade. I'll say so explicitly in the PR.
    • Tests per path, with the store-level ones against a real Postgres as the repo requires — owner invites succeed, a non-allowed member is refused on every path, owner_agents and named-agent policies behave, and an agent already in a room stays.
    • Docs updated where addressing policies are described.

    One thing I'd like your call on: whether an agent sender inviting on someone's behalf should count as that someone. The connections design note already flags that an agent is not the person, and owner_agents makes "others can address it" true — I'll follow that existing reading (treat the agent sender by the same policy) unless you want the stricter one.

    Could you assign it to me?

  12. Xuefeng-Zhu commented on Nov 4, 2026

    @Xuefeng-Zhu
    Contributor

    Update: PR #1443 implements the shared invitation check. The decision flow is shown below.

    Invitation decision flow

    flowchart TD
        subgraph Boundary["Callers and external platforms"]
            User["Signed-in Switch user<br/>or agent tool"]
            Chat["Chat command sender"]
            Platform["Platform join event<br/>adder may be unknown"]
        end
        subgraph Switch["Switch service"]
            Room["RoomService<br/>create_room / add_agents_to_room"]
            Gate["InviteGate<br/>checks agents to be added"]
            Resolve["Resolve named inviter<br/>to a sender principal"]
            Policy["AddressingResolver.judge<br/>applies agent addressing policy"]
            Decision{"Policy permits<br/>the inviter?"}
            Add["Create room if needed;<br/>add permitted agents"]
            Refuse["Refuse invite;<br/>return message with owner guidance"]
            Partial["New platform channel only:<br/>exclude refused agents and retry rest"]
            Unverified["No platform adder reported:<br/>restricted agents marked unverified"]
            Notice["Bridge posts channel notice<br/>and logs a warning"]
            Result["Return room / invite outcome"]
            DB[("Database:<br/>room and agent membership")]
        end
    
        User --> Room
        Chat --> Room
        Platform --> Room
        Room --> Gate
        Gate -- "named inviter" --> Resolve --> Policy --> Decision
        Decision -- "allowed" --> Add
        Decision -- "refused" --> Refuse
        Refuse -- "new platform channel" --> Partial --> Room
        Gate -- "platform adder absent" --> Unverified --> Add
        Add --> DB
        Add --> Result
        Unverified --> Notice
    
    Loading

    The owner is allowed by an owner-only policy, but other policies may authorize other actors. An agent can invite itself; administrator status is not an implicit bypass. Existing members are not re-judged. A regular refused create does not provision the room; the partial retry shown is specific to a newly discovered platform channel. The unverified path does not authenticate the absent adder.

    • RoomService.create_room and add_agents_to_room require an inviter and use InviteGate, which resolves the actor and applies the invited agent's existing addressing policy through AddressingResolver.judge. Refusals explain why and point to the owner; existing room members are not re-checked. There is no implicit admin bypass.
    • For platform joins, a reported adder is evaluated as that person. If the platform does not report an adder, the join is allowed; restricted agents are marked unverified, the bridge posts a room notice and logs a warning. The owner is mentioned in the room when they have a linked account on that bridge; there is no direct owner DM.
    • Focused verification: at commit 9505b6f07f0941dd059cffbefd64389cb915d69a, 34 tests passed across test_invites.py, test_room_service_invites.py, and test_bridge_invite_gate.py on Linux ARM. The room-service tests used real PostgreSQL 16; gate and bridge tests use fakes. The run used a loopback-only test-container guard.

    These are focused tests, not a full-suite run or a live Slack/Telegram verification. The service-level rehearsal uses synthetic identities and simulated transport/provisioning; it is not a live UI demo. The tests also do not establish atomicity against a concurrent policy change.

  13. added a commit that references this issue on Nov 5, 2026
  14. anuj-kadu commented on Nov 7, 2026

    @anuj-kadu

    @petr-sandbox I'd like to take #805 for Track 03. I can see it is at GitHub's 10-assignee limit; per your notes on #842 and #770 I'll proceed and link the PR here, but please add me if a slot opens.

    Approach: one gate, with the inviter required by type.

    RoomService.add_agents_to_room and create_room(agents=...) stay the only membership choke points. The inviter becomes a required argument (a person, an inviting agent, a template runner, or a platform-reported adder), so a new call site cannot quietly omit it. The gate reuses AddressingResolver/addressing.py, so "may invite" is exactly "may address" — no second permission model. It runs before any membership or channel side effect, re-reads the policy and membership in the same transaction as the insert, and leaves existing members untouched. There is no implicit admin bypass.

    Path coverage

    • !invite-agent / /invite-agent → the person sending it.
    • invite_agent_to_room MCP tool and agent-bridge API → the inviting agent (owner_and_owner_agents already covers this).
    • Gateway room page and room creation with agents → the requesting person.
    • rooms.yaml / template runs → the person running the template.
    • Platform joins → the adder the adapter reports (Slack and Telegram first). When the platform reports nobody, allow the join but make the uncertainty visible: room notice, warning log, and the owner told. An unknown adder is never treated as trusted.

    A refusal names the agent and says only its owner (or someone its policy allows) can add it, in the same words on every surface.

    Tests

    Path-by-path matrix (owner / allowed / denied / unclaimed), no membership or channel side effects on refusal, existing members retained, unknown-adder disclosure, and real-Postgres store tests including a policy change racing the invite. Docs updated where addressing policy is described.

    I'll open the PR before the deadline.

  15. gudboii21 commented on Nov 7, 2026

    @gudboii21

    @petr-sandbox I have implemented the agent addressing check for room invitations in PR #1732 .

    • Enforced addressing policy in RoomService before adding agents to a room or creating rooms with agents
    • Multi-pod safe: batch agent lookups in one query via agent_store.get_many
    • Graceful error explanation on !invite-agent naming the owner
    • Added 16 new dedicated unit tests with all 117 suite tests passing green

    Ready for review!

  16. petr-sandbox commented on Nov 7, 2026

    @petr-sandbox
    Collaborator

    @anuj-kadu this issue has reached GitHub's limit of 10 assignees, so I couldn't add you. You don't need to be assigned to work on it, and your PR counts the same, as does #1732.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions