Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
Let an agent say who can answer its request cards (#991)
Abel Dantas7709a4ef7378
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 9f901ea4d..d4073eb52 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -52,6 +52,12 @@ version of their own to them without also giving them a release of their own.before the room exists. A template never creates or changes a package.Capturing a room (`GET /rooms/{id}/yaml`) now lists its packages by `id`,so a room built again from its capture gets them back (#910).+- **An agent can read its own addressing policy.** `get_agent_detail` now+ returns `addressing`: the kind of policy (`owner_only`,+ `owner_and_owner_agents`, `anyone` or `custom`) and, when an agent looks+ itself up, its rules with the people, agents and rooms they name. So an+ agent can tell someone who may answer its questions and approvals instead+ of guessing. Another agent sees only the kind.#### Changed- **Following the conversation is described the same way everywhere, and the@@ -1892,6 +1898,10 @@ version of their own to them without also giving them a release of their own.starting Docker meanwhile left the setup skipping Mattermost until you wentback. It now checks again every few seconds, and when Console regains focus,while Docker isn't answering.+- **Agents say who can answer their questions and approvals.** The Switch+ skill said a request card needed the owner's linked identity and room+ membership. Its addressing policy decides, and agents now read theirs with+ `get_agent_detail` and name the people who can answer.### [0.40.1] - 2026-10-21diff --git a/console/packages/plugins/src/switch-skill/SKILL.md b/console/packages/plugins/src/switch-skill/SKILL.mdindex a6de5b001..aa424d60c 100644--- a/console/packages/plugins/src/switch-skill/SKILL.md+++ b/console/packages/plugins/src/switch-skill/SKILL.md@@ -313,10 +313,16 @@ generally do not. Without one, when you genuinely need a decision, ask in theroom with `send_targeted_message` and wait for the reply as an ordinary event.Request cards (your session's questions and approvals) use server authorization.-Room visibility alone does not permit an answer: only someone allowed to address-you in that room may answer, under your addressing policy. By default that is-your owner and your owner's own agents; your owner can narrow or widen it. A-pending answer is not an approval; wait for the confirmed result. Cancellation remains cancellation.+Who may answer one is decided by your addressing policy, the same rule as who+may address you, not by who can see or is in the room. Outside a room, only+your owner can. New agents start on `owner_and_owner_agents`, which for a+person means your owner alone, and your owner can narrow or widen it. Before+telling someone who can answer, or why their answer did not count, call+`get_agent_detail` on yourself, read `addressing`, and say it concretely with+names: "Only my owner, Ada, can approve this", or "Anyone who can address me+can answer this". Never answer+with just "it depends on my addressing policy". A pending answer is not an+approval; wait for the confirmed result. Cancellation remains cancellation.The server chooses request-card destinations. Ordinary session output stays insession details; use the Switch messaging tools for explicit room replies.@@ -422,6 +428,9 @@ none of it is needed to take part in a conversation.- **`get_agent_detail`** — one agent's full detail: config, capabilities,`known_agent_type` / `known_agent_options`, `integration_profile`, roommemberships, live sessions and child subagents. Readable by any agent.+ `addressing` says who may address it: on yourself, the policy and its rules+ with the people, agents and rooms they name; on another agent, the policy+ alone.- **`update_agent_detail`** — change an agent your owner owns; anyoneelse's is refused, and so is yourself: your own settings are your owner'sto change, in Switch Console. Pass only the fields to change.@@ -1054,7 +1063,8 @@ Every Switch tool you call in normal operation, one line each.- `update_template`: change a template you saved.- `delete_template`: delete a template you saved.- `list_agents` — every agent on the instance, with optional filters.-- `get_agent_detail` — one agent's config, capabilities and sessions.+- `get_agent_detail`: one agent's config, capabilities, sessions and who may+ address it.- `update_agent_detail` — change an agent you own.- `request_agent_deletion` — ask for an agent to be deleted; a person confirms.- `list_machines` — your owner's machines, where agent management runs.diff --git a/core/switch_core/addressing.py b/core/switch_core/addressing.pyindex b3b39711f..c4591d8dc 100644--- a/core/switch_core/addressing.py+++ b/core/switch_core/addressing.py@@ -306,6 +306,27 @@ def default_agent_policy() -> AddressingPolicy:return owner_and_owner_agents_policy()+AddressingKind = Literal["owner_only", "owner_and_owner_agents", "anyone", "custom"]+++def policy_kind(raw: dict | None) -> AddressingKind:+ """Which of the choices Switch Console offers a stored policy is.++ "owner_only", "owner_and_owner_agents" and "anyone" are the three+ shortcuts; "custom" is every other rule set, including owner-only with+ agents granted by id. "anyone" is an open policy, which still turns the+ platform's own messages away.+ """+ policy = parse_policy(raw)+ if policy.is_open():+ return "anyone"+ if policy == owner_only_policy([]):+ return "owner_only"+ if policy == owner_and_owner_agents_policy():+ return "owner_and_owner_agents"+ return "custom"++def platform_allowed_policy() -> AddressingPolicy:"""A policy that admits the platform sender.diff --git a/core/switch_core/bridges/agent/operations/definitions.py b/core/switch_core/bridges/agent/operations/definitions.pyindex 1fc69c033..6130fe1db 100644--- a/core/switch_core/bridges/agent/operations/definitions.py+++ b/core/switch_core/bridges/agent/operations/definitions.py@@ -47,7 +47,10 @@ from switch_core.bridges.agent.protocol.agent_core import (AgentExistsError,AgentRenameRefused,)-from switch_core.bridges.agent.protocol.agent_detail import AgentProfileUpdate+from switch_core.bridges.agent.protocol.agent_detail import (+ AgentProfileUpdate,+ agent_facing_detail,+)from switch_core.bridges.agent.protocol.agent_management import ManagedAgentChangesfrom switch_core.bridges.agent.protocol.instructions import build_room_instructionsfrom switch_core.bridges.agent.protocol.types import IntegrationProfile@@ -2157,17 +2160,33 @@ async def get_agent_detail(agent_id: str) -> dict[str, Any]:connection_model, tool_count, model_count, owner_id, owner_name,oauth_client_id, created_at, parent_agent_id, known_agent_type,known_agent_options, agent_type, can_manage_agents,- integration_profile, tools, models, rooms, sessions, children}.+ integration_profile, tools, models, rooms, sessions, children,+ addressing}.`icon_url` is null when the agent has no icon set. `display_name` isnull when the agent has no display name set; fall back to `name`.Address agents by `name`; `display_name` routes nothing.`can_manage_agents` is whether the agent's owner lets it list theirmachines and create agents on them, where agent management runs.+ `addressing` is who may address the agent, and so who may answer+ its questions and approvals in a room (outside one, only its owner):+ {policy} for another agent, {policy, rules} when you look yourself+ up. `policy` is "owner_only" (its owner alone),+ "owner_and_owner_agents" (its owner and any agent they own),+ "anyone" or "custom". `rules` are the policy's rules, empty for+ "anyone"; a sender is let in when any rule matches. Each is {rooms,+ room_groups, users, agents, owner, owner_agents, platform}: a+ dimension is "*" (any) or a list of {id, name}, empty meaning none,+ with `users` named by their chat username; `owner` admits the owner+ (`owner_name`), `owner_agents` their agents, `platform` Switch itself."""caller_id = get_agent_id()protocol = get_protocol()detail = await protocol.get_agent_detail(caller_id, agent_id)- return detail.model_dump()+ addressing = await protocol.get_agent_addressing(caller_id, agent_id)+ return {+ **agent_facing_detail(detail),+ "addressing": addressing.model_dump(exclude_none=True),+ }@operation@@ -2369,7 +2388,12 @@ async def update_agent_detail("templates_mentioning_old_name": result.templates_mentioning_old_name,}detail = await protocol.update_agent_detail(caller_id, agent_id, profile)- response = {**detail.model_dump(), "managed": managed}+ who_may_address = await protocol.get_agent_addressing(caller_id, agent_id)+ response = {+ **agent_facing_detail(detail),+ "addressing": who_may_address.model_dump(exclude_none=True),+ "managed": managed,+ }if renamed is not None:response["renamed"] = renamedreturn responsediff --git a/core/switch_core/bridges/agent/operations/my_context.py b/core/switch_core/bridges/agent/operations/my_context.pyindex 8de9cc008..b0091c7b0 100644--- a/core/switch_core/bridges/agent/operations/my_context.py+++ b/core/switch_core/bridges/agent/operations/my_context.py@@ -20,7 +20,7 @@ from typing import Anyfrom sqlalchemy import func, selectfrom switch_core import messaging_platforms-from switch_core.addressing import owner_and_owner_agents_policy, owner_only_policy+from switch_core.addressing import policy_kindfrom switch_core.bridges.agent.operations.agent_management import management_portfrom switch_core.bridges.agent.operations.context import get_agent_id, get_protocolfrom switch_core.bridges.agent.operations.registry import operation@@ -215,7 +215,7 @@ async def get_my_context() -> dict[str, Any]:"id": agent.id,"name": agent.name,"display_name": agent.display_name,- "who_can_talk": _who_can_talk(agent),+ "who_can_talk": policy_kind(agent.addressing_policy),"can_manage_agents": agent.can_manage_agents,"services": grants[agent.id],"managed": (@@ -300,14 +300,3 @@ def _services(})return entries---def _who_can_talk(agent: Agent) -> str:- policy = agent.addressing_policy- if policy is None:- return "anyone"- if policy == owner_only_policy([]).model_dump():- return "owner_only"- if policy == owner_and_owner_agents_policy().model_dump():- return "owner_and_owner_agents"- return "custom"diff --git a/core/switch_core/bridges/agent/protocol/agent_core.py b/core/switch_core/bridges/agent/protocol/agent_core.pyindex 875032961..640d56286 100644--- a/core/switch_core/bridges/agent/protocol/agent_core.py+++ b/core/switch_core/bridges/agent/protocol/agent_core.py@@ -41,7 +41,9 @@ from switch_core.bridges.agent.protocol.agent_connections import ()from switch_core.bridges.agent.protocol.agent_detail import (AgentProfileUpdate,+ agent_facing_summary,assemble_agent_detail,+ describe_addressing,list_agent_summaries,)from switch_core.bridges.agent.protocol.event_buffer import EventBuffer@@ -167,7 +169,7 @@ if TYPE_CHECKING:)from switch_core.db.stores.external_user_store import ExternalUserStorefrom switch_core.db.stores.room_store import RoomStore- from switch_core.gateway.schemas import AgentDetail+ from switch_core.gateway.schemas import AgentAddressing, AgentDetailfrom switch_core.room_service import RoomCreateResult, RoomServicefrom switch_core.rooms_yaml import RoomYamlServicefrom switch_core.session_activity.outcomes import ApprovalOutcomes@@ -3944,7 +3946,7 @@ class AgentCore:owner_name=owner_name,known_agent_type=known_agent_type,)- return [s.model_dump() for s in summaries]+ return [agent_facing_summary(s) for s in summaries]async def get_agent_detail(self, agent_id: str, target_agent_id: str@@ -3969,6 +3971,23 @@ class AgentCore:connections=self.connections,)+ async def get_agent_addressing(+ self, agent_id: str, target_agent_id: str+ ) -> AgentAddressing:+ """Who may address `target_agent_id`, as `agent_id` may see it: the+ rules with their names when an agent reads its own, the policy's kind+ alone otherwise.++ Raises ValueError if the target agent does not exist.+ """+ async with self.session_factory() as session:+ agent = await self.agent_store.get(session, target_agent_id)+ if agent is None:+ raise ValueError(f"Agent not found: {target_agent_id}")+ return await describe_addressing(+ session, agent=agent, with_rules=agent_id == target_agent_id+ )+async def require_same_owner(self, agent_id: str, target_agent_id: str) -> None:"""Refuse unless the calling agent's owner owns `target_agent_id`.diff --git a/core/switch_core/bridges/agent/protocol/agent_detail.py b/core/switch_core/bridges/agent/protocol/agent_detail.pyindex 7f8595d33..887f17d31 100644--- a/core/switch_core/bridges/agent/protocol/agent_detail.py+++ b/core/switch_core/bridges/agent/protocol/agent_detail.py@@ -13,20 +13,33 @@ from __future__ import annotationsfrom dataclasses import dataclassfrom datetime import UTC, datetime-from typing import Any, cast+from typing import Any, Literal, cast+from sqlalchemy import selectfrom sqlalchemy.ext.asyncio import AsyncSessionfrom switch_core.addressing import (+ ANY,AddressingPolicy,+ Dimension,owner_and_owner_agents_policy,owner_only_policy,+ parse_policy,+ policy_kind,)from switch_core.agent_display_name import normalise_display_namefrom switch_core.agent_icon import normalise_icon_url, refuse_third_party_avatarfrom switch_core.bridges.agent.protocol.agent_connections import AgentConnectionRegistryfrom switch_core.bridges.agent.protocol.statuses import agent_statuses_by_room-from switch_core.db.models import Agent, AgentSession+from switch_core.db.models import (+ Agent,+ AgentSession,+ Client,+ ExternalUser,+ Room,+ RoomGroup,+ User,+)from switch_core.db.stores.agent_session_store import AgentSessionStorefrom switch_core.db.stores.agent_store import AgentStorefrom switch_core.db.stores.room_role_store import RoomRoleStore@@ -34,12 +47,15 @@ from switch_core.db.stores.room_store import RoomStorefrom switch_core.db.stores.user_store import UserStorefrom switch_core.gateway.known_agents import known_agentfrom switch_core.gateway.schemas import (+ AddressingRuleView,+ AgentAddressing,AgentDetail,AgentModelSummary,AgentRoomMembership,AgentSessionDetail,AgentSummary,AgentToolSummary,+ NamedEntry,)@@ -323,6 +339,118 @@ async def assemble_agent_detail()+def agent_facing_summary(summary: AgentSummary) -> dict[str, Any]:+ """`summary` as an agent may read it: without the raw addressing policy,+ whose rules name the users, agents and rooms the owner let in. An agent+ learns who may address it from `describe_addressing` instead."""+ return summary.model_dump(exclude={"addressing_policy"})+++def agent_facing_detail(detail: AgentDetail) -> dict[str, Any]:+ """`detail` as an agent may read it, its children included; see+ `agent_facing_summary`."""+ return detail.model_dump(+ exclude={+ "addressing_policy": True,+ "children": {"__all__": {"addressing_policy"}},+ }+ )+++async def describe_addressing(+ session: AsyncSession, *, agent: Agent, with_rules: bool+) -> AgentAddressing:+ """Who may address `agent`, for an agent to read and repeat to a person.++ `with_rules` is for the agent reading its own policy: the rules come with+ every id they name resolved to the name people know it by, so the agent+ can say who may answer it rather than quote ids. Any other reader gets+ the policy's kind alone.+ """+ kind = policy_kind(agent.addressing_policy)+ if not with_rules:+ return AgentAddressing(policy=kind, rules=None)+ policy = parse_policy(agent.addressing_policy)+ names = await _addressing_names(session, policy)+ return AgentAddressing(+ policy=kind,+ rules=[+ AddressingRuleView(+ rooms=_named(rule.rooms, names.rooms),+ room_groups=_named(rule.room_groups, names.room_groups),+ users=_named(rule.users, names.users),+ agents=_named(rule.agents, names.agents),+ owner=rule.owner,+ owner_agents=rule.owner_agents,+ platform=rule.platform,+ )+ for rule in policy.rules+ ],+ )+++@dataclass(frozen=True)+class _AddressingNames:+ rooms: dict[str, str]+ room_groups: dict[str, str]+ users: dict[str, str]+ agents: dict[str, str]+++async def _addressing_names(+ session: AsyncSession, policy: AddressingPolicy+) -> _AddressingNames:+ """The names of everything `policy` lists by id, one query per kind.++ A `users` entry is a chat account (named by its username on the platform)+ or a person's own Switch member client (named by that person's name).+ """++ def ids(dimension: str) -> set[str]:+ return {+ value+ for rule in policy.rules+ for value in _listed(getattr(rule, dimension))+ }++ async def names_of(model: Any, column: Any, wanted: set[str]) -> dict[str, str]:+ if not wanted:+ return {}+ rows = await session.execute(+ select(model.id, column).where(model.id.in_(wanted))+ )+ return {row_id: name for row_id, name in rows.tuples()}++ user_ids = ids("users")+ users = await names_of(ExternalUser, ExternalUser.external_username, user_ids)+ member_ids = user_ids - users.keys()+ if member_ids:+ rows = await session.execute(+ select(Client.id, User.name)+ .join(User, User.id == Client.user_id)+ .where(Client.id.in_(member_ids))+ )+ users.update({row_id: name for row_id, name in rows.tuples()})+ return _AddressingNames(+ rooms=await names_of(Room, Room.name, ids("rooms")),+ room_groups=await names_of(RoomGroup, RoomGroup.name, ids("room_groups")),+ users=users,+ agents=await names_of(Agent, Agent.name, ids("agents")),+ )+++def _listed(dimension: Dimension) -> list[str]:+ return [] if dimension == ANY else list(dimension)+++def _named(+ dimension: Dimension, names: dict[str, str]+) -> Literal["*"] | list[NamedEntry]:+ if dimension == ANY:+ return "*"+ return [NamedEntry(id=value, name=names.get(value)) for value in dimension]++async def apply_agent_options(session: AsyncSession,agent_store: AgentStore,diff --git a/core/switch_core/gateway/schemas.py b/core/switch_core/gateway/schemas.pyindex 68b785e28..7a2c6c1af 100644--- a/core/switch_core/gateway/schemas.py+++ b/core/switch_core/gateway/schemas.py@@ -13,7 +13,7 @@ from pydantic import (model_validator,)-from switch_core.addressing import AddressingPolicy+from switch_core.addressing import AddressingKind, AddressingPolicyfrom switch_core.bridges.collaboration.models import (BridgeInstallLink,ChannelRetirement,@@ -354,6 +354,39 @@ class AgentDetail(AgentSummary):children: list[AgentSummary]+class NamedEntry(BaseModel):+ """An id a policy names, with the name a person would know it by.++ `name` is null when the id no longer resolves to anything (a deleted+ room, an agent or a chat account that is gone)."""++ id: str+ name: str | None+++class AddressingRuleView(BaseModel):+ """One addressing rule with its ids resolved to names. Each dimension is+ "*" (any) or the entries it lists; an empty list matches nobody."""++ rooms: Literal["*"] | list[NamedEntry]+ room_groups: Literal["*"] | list[NamedEntry]+ users: Literal["*"] | list[NamedEntry]+ agents: Literal["*"] | list[NamedEntry]+ owner: bool+ owner_agents: bool+ platform: bool+++class AgentAddressing(BaseModel):+ """Who may address an agent, as an agent reads it about itself.++ `rules` is null when the reader is not the agent itself: another agent+ sees which kind of policy it is, not who it names."""++ policy: AddressingKind+ rules: list[AddressingRuleView] | None++class UpdateAddressingPolicyRequest(BaseModel):"""Set (or clear) an agent's scoped addressing policy.diff --git a/core/tests/switch_core/bridges/agent/protocol/test_agent_detail_mcp_tools.py b/core/tests/switch_core/bridges/agent/protocol/test_agent_detail_mcp_tools.pyindex 02f066c2c..b99edffb4 100644--- a/core/tests/switch_core/bridges/agent/protocol/test_agent_detail_mcp_tools.py+++ b/core/tests/switch_core/bridges/agent/protocol/test_agent_detail_mcp_tools.py@@ -1,21 +1,49 @@from __future__ import annotations+import json+from collections.abc import AsyncIterator+from types import SimpleNamespace+import pytestfrom sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker-from switch_core.addressing import owner_and_owner_agents_policy, owner_only_policy+from switch_core.addressing import (+ AddressingPolicy,+ AddressingRule,+ owner_and_owner_agents_policy,+ owner_only_policy,+)from switch_core.agent_icon import InvalidIconUrl, generated_icon_url+from switch_core.bridges.agent.operations import agent_management+from switch_core.bridges.agent.operations import context as op_context+from switch_core.bridges.agent.operations import definitions as ops+from switch_core.bridges.agent.operations.callctx import (+ CallContext,+ reset_call_context,+ set_call_context,+)from switch_core.bridges.agent.protocol.agent_connections import AgentConnectionRegistryfrom switch_core.bridges.agent.protocol.agent_core import AgentCorefrom switch_core.bridges.agent.protocol.agent_detail import AgentProfileUpdatefrom switch_core.bridges.collaboration.adapter import AgentIdentity-from switch_core.db.models import Agent, ApiKey, Client, User+from switch_core.db.models import (+ Agent,+ ApiKey,+ Client,+ CollaborationBridge,+ ExternalUser,+ Room,+ User,+)from switch_core.db.stores.agent_session_store import AgentSessionStorefrom switch_core.db.stores.agent_store import AgentStorefrom switch_core.db.stores.room_role_store import RoomRoleStorefrom switch_core.db.stores.room_store import RoomStorefrom switch_core.db.stores.user_store import UserStorefrom switch_core.gateway.known_agents import known_agents+from switch_core.gateway.schemas import NamedEntry++SECRET_ID = "someone-the-owner-let-in"class _NoBridges:@@ -184,6 +212,138 @@ class TestGetAgentDetail:await svc.get_agent_detail("caller", "nope")+async def _chat_account(session: AsyncSession, username: str) -> ExternalUser:+ bridge_client = Client(+ transport_user_id=f"@bridge-{username}:test",+ display_name="bridge",+ type="collaboration_bridge",+ )+ account_client = Client(+ transport_user_id=f"@{username}-chat:test",+ display_name=username,+ type="external_user",+ )+ session.add_all([bridge_client, account_client])+ await session.flush()+ bridge = CollaborationBridge(+ type="slack",+ display_name="Slack",+ client_id=bridge_client.id,+ status="active",+ )+ session.add(bridge)+ await session.flush()+ account = ExternalUser(+ bridge_id=bridge.id,+ external_user_id=f"U-{username}",+ external_username=username,+ client_id=account_client.id,+ )+ session.add(account)+ await session.flush()+ return account+++def _entries(dimension: str | list[NamedEntry]) -> list[dict[str, str | None]]:+ assert isinstance(dimension, list)+ return [entry.model_dump() for entry in dimension]+++class TestGetAgentAddressing:+ async def test_an_agent_reads_its_own_rules_with_names(+ self, session_factory: async_sessionmaker[AsyncSession]+ ) -> None:+ svc = _service(session_factory)+ async with session_factory() as session:+ owner = await _make_user(session, "owner")+ helper = await _make_agent(session, "helper", owner_id=owner.id)+ bob = await _chat_account(session, "bob")+ room = Room(transport_room_id="!ops:test", name="ops", description="d")+ session.add(room)+ await session.flush()+ policy = AddressingPolicy(+ rules=[+ AddressingRule(users=[], agents=[], owner=True),+ AddressingRule(+ rooms=[room.id],+ users=[bob.id, "gone"],+ agents=[helper.id],+ ),+ ]+ )+ agent = await _make_agent(session, "me", owner_id=owner.id)+ agent.addressing_policy = policy.model_dump()+ await session.commit()+ ids = (agent.id, helper.id, bob.id, room.id)+ agent_id, helper_id, bob_id, room_id = ids++ addressing = await svc.get_agent_addressing(agent_id, agent_id)++ assert addressing.policy == "custom"+ assert addressing.rules is not None+ owner_rule, named_rule = addressing.rules+ assert owner_rule.owner is True+ assert owner_rule.users == []+ assert _entries(named_rule.rooms) == [{"id": room_id, "name": "ops"}]+ assert _entries(named_rule.users) == [+ {"id": bob_id, "name": "bob"},+ {"id": "gone", "name": None},+ ]+ assert _entries(named_rule.agents) == [{"id": helper_id, "name": "helper"}]+ assert named_rule.room_groups == "*"++ async def test_another_agent_sees_only_the_kind(+ self, session_factory: async_sessionmaker[AsyncSession]+ ) -> None:+ requester_id, target_id = await _owned_pair(session_factory)+ async with session_factory() as session:+ target = await session.get(Agent, target_id)+ assert target is not None+ target.addressing_policy = owner_only_policy(["someone"]).model_dump()+ await session.commit()+ svc = _service(session_factory)++ addressing = await svc.get_agent_addressing(requester_id, target_id)++ assert addressing.model_dump(exclude_none=True) == {"policy": "custom"}++ async def test_the_default_policy_reads_as_owner_and_owner_agents(+ self, session_factory: async_sessionmaker[AsyncSession]+ ) -> None:+ _, target_id = await _owned_pair(session_factory)+ async with session_factory() as session:+ target = await session.get(Agent, target_id)+ assert target is not None+ target.addressing_policy = owner_and_owner_agents_policy().model_dump()+ await session.commit()+ svc = _service(session_factory)++ addressing = await svc.get_agent_addressing(target_id, target_id)++ assert addressing.policy == "owner_and_owner_agents"+ assert addressing.rules is not None+ assert len(addressing.rules) == 1+ assert addressing.rules[0].owner is True+ assert addressing.rules[0].owner_agents is True++ async def test_an_open_agent_has_no_rules(+ self, session_factory: async_sessionmaker[AsyncSession]+ ) -> None:+ _, target_id = await _owned_pair(session_factory)+ svc = _service(session_factory)++ addressing = await svc.get_agent_addressing(target_id, target_id)++ assert addressing.model_dump() == {"policy": "anyone", "rules": []}++ async def test_missing_agent_raises(+ self, session_factory: async_sessionmaker[AsyncSession]+ ) -> None:+ svc = _service(session_factory)+ with pytest.raises(ValueError, match="Agent not found"):+ await svc.get_agent_addressing("caller", "nope")++def _profile(*,description: str | None = None,@@ -379,3 +539,85 @@ class TestUpdateAgentDetailReachesTheBridges:)assert adapter.updated == []+++def _keys(value: object) -> set[str]:+ """Every key in a JSON-shaped value, at any depth."""+ if isinstance(value, dict):+ return set(value) | {key for item in value.values() for key in _keys(item)}+ if isinstance(value, list):+ return {key for item in value for key in _keys(item)}+ return set()+++class TestAgentFacingResultsKeepPoliciesPrivate:+ """Who an agent's policy names is its owner's business: the operations+ agents call return `addressing` and never the raw policy, for the agent,+ its children, or a list of agents."""++ @pytest.fixture+ async def agents(+ self,+ monkeypatch: pytest.MonkeyPatch,+ session_factory: async_sessionmaker[AsyncSession],+ ) -> AsyncIterator[tuple[str, str, str]]:+ svc = _service(session_factory)+ svc.config = SimpleNamespace(third_party_avatars_enabled=True) # type: ignore[assignment]+ monkeypatch.setattr(op_context, "_protocol", svc)+ monkeypatch.setattr(agent_management, "_port", None)+ async with session_factory() as session:+ owner = await _make_user(session, "owner")+ caller = await _make_agent(session, "caller", owner_id=owner.id)+ target = await _make_agent(session, "target", owner_id=owner.id)+ child = await _make_agent(+ session, "child", owner_id=owner.id, parent_agent_id=target.id+ )+ for agent in (caller, target, child):+ agent.addressing_policy = owner_only_policy(+ [SECRET_ID, f"{agent.name}-friend"]+ ).model_dump()+ await session.commit()+ ids = (caller.id, target.id, child.id)+ token = set_call_context(+ CallContext(agent_id=ids[0], session_key=None, session=None)+ )+ yield ids+ reset_call_context(token)++ async def test_get_agent_detail_of_another_agent(+ self, agents: tuple[str, str, str]+ ) -> None:+ _, target_id, child_id = agents++ result = await ops.get_agent_detail(target_id)++ assert "addressing_policy" not in _keys(result)+ assert SECRET_ID not in json.dumps(result)+ assert [child["id"] for child in result["children"]] == [child_id]+ assert result["addressing"] == {"policy": "custom"}++ async def test_get_agent_detail_of_itself_names_its_rules_once(+ self, agents: tuple[str, str, str]+ ) -> None:+ caller_id, _, _ = agents++ result = await ops.get_agent_detail(caller_id)++ assert "addressing_policy" not in _keys(result)+ assert result["addressing"]["rules"]++ async def test_list_agents(self, agents: tuple[str, str, str]) -> None:+ result = await ops.list_agents()++ assert {agent["name"] for agent in result} == {"caller", "target", "child"}+ assert "addressing_policy" not in _keys(result)+ assert SECRET_ID not in json.dumps(result)++ async def test_update_agent_detail(self, agents: tuple[str, str, str]) -> None:+ _, target_id, _ = agents++ result = await ops.update_agent_detail(target_id, description="new")++ assert result["description"] == "new"+ assert "addressing_policy" not in _keys(result)+ assert SECRET_ID not in json.dumps(result)diff --git a/core/tests/switch_core/test_addressing.py b/core/tests/switch_core/test_addressing.pyindex 3de060d30..991afabbd 100644--- a/core/tests/switch_core/test_addressing.py+++ b/core/tests/switch_core/test_addressing.py@@ -12,6 +12,7 @@ from switch_core.addressing import (owner_only_policy,parse_policy,platform_allowed_policy,+ policy_kind,)@@ -610,6 +611,35 @@ class TestRequiresOwnerIdentity:assert owner_only_policy([]).requires_owner_identity() is True+class TestPolicyKind:+ """Which Console choice a stored policy is, as agents read it back."""++ def test_no_policy_is_anyone(self) -> None:+ assert policy_kind(None) == "anyone"++ def test_no_rules_is_anyone(self) -> None:+ assert policy_kind({"rules": []}) == "anyone"++ def test_owner_only(self) -> None:+ assert policy_kind(owner_only_policy([]).model_dump()) == "owner_only"++ def test_default_is_owner_and_owner_agents(self) -> None:+ assert (+ policy_kind(default_agent_policy().model_dump()) == "owner_and_owner_agents"+ )++ def test_a_rule_stored_without_its_defaults_still_matches(self) -> None:+ stored = {"rules": [{"users": [], "agents": [], "owner": True}]}+ assert policy_kind(stored) == "owner_only"++ def test_owner_only_with_granted_agents_is_custom(self) -> None:+ assert policy_kind(owner_only_policy(["a1"]).model_dump()) == "custom"++ def test_named_people_are_custom(self) -> None:+ policy = AddressingPolicy(rules=[AddressingRule(users=["u1"], agents=[])])+ assert policy_kind(policy.model_dump()) == "custom"++class TestAdmitsOthers:"""Whether anyone but the owner can address the agent."""