Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(bots): enable configured agents for mention dispatch (#9759)
Wolf Mermelstein2d8ba4a3d082
diff --git a/.sqlx/query-afb7e1ae4a7f9978085299a9473a9f8ddf77e2177d937fe6d18dd4ae0e3a1b6d.json b/.sqlx/query-0080bc761b88fe6e5813cfcb125771835bc31ee0650c53249b97255fadc98134.jsonsimilarity index 72%rename from .sqlx/query-afb7e1ae4a7f9978085299a9473a9f8ddf77e2177d937fe6d18dd4ae0e3a1b6d.jsonrename to .sqlx/query-0080bc761b88fe6e5813cfcb125771835bc31ee0650c53249b97255fadc98134.jsonindex 3af660c19b..4ae6d95d21 100644--- a/.sqlx/query-afb7e1ae4a7f9978085299a9473a9f8ddf77e2177d937fe6d18dd4ae0e3a1b6d.json+++ b/.sqlx/query-0080bc761b88fe6e5813cfcb125771835bc31ee0650c53249b97255fadc98134.json@@ -1,6 +1,6 @@{"db_name": "PostgreSQL",- "query": "\n UPDATE bots\n SET owner_user_id = $2,\n team_id = $3,\n name = $4,\n handle = $5,\n description = $6,\n avatar_url = $7,\n updated_at = now()\n WHERE id = $1\n AND deleted_at IS NULL\n AND EXISTS (SELECT 1 FROM agent_configs WHERE bot_id = $1)\n RETURNING\n id,\n kind,\n owner_user_id,\n team_id,\n name,\n handle,\n description,\n avatar_url,\n created_by,\n created_at,\n updated_at,\n deleted_at,\n has_agent\n ",+ "query": "\n UPDATE bots\n SET owner_user_id = $2,\n team_id = $3,\n name = $4,\n handle = $5,\n description = $6,\n avatar_url = $7,\n has_agent = true,\n updated_at = now()\n WHERE id = $1\n AND deleted_at IS NULL\n AND EXISTS (SELECT 1 FROM agent_configs WHERE bot_id = $1)\n RETURNING\n id,\n kind,\n owner_user_id,\n team_id,\n name,\n handle,\n description,\n avatar_url,\n created_by,\n created_at,\n updated_at,\n deleted_at,\n has_agent\n ","describe": {"columns": [{@@ -96,5 +96,5 @@false]},- "hash": "afb7e1ae4a7f9978085299a9473a9f8ddf77e2177d937fe6d18dd4ae0e3a1b6d"+ "hash": "0080bc761b88fe6e5813cfcb125771835bc31ee0650c53249b97255fadc98134"}diff --git a/apps/docs/AI/mcp/tools/configure-bot.mdx b/apps/docs/AI/mcp/tools/configure-bot.mdxindex 4fed403351..d4fab036f6 100644--- a/apps/docs/AI/mcp/tools/configure-bot.mdx+++ b/apps/docs/AI/mcp/tools/configure-bot.mdx@@ -17,4 +17,4 @@ Configure a manageable bot's profile. Provide only fields that should change. Us| `handle` | string | No | New stable handle using lowercase ASCII letters, digits, hyphens, and underscores. Omit to keep the current handle. || `description` | string | No | New bot description. Omit to keep the current value; pass an empty string to clear it. || `avatarUrl` | string | No | New profile-picture URL. Use a Macro static-file URL or another reachable image URL. Omit to keep the current picture; pass an empty string to clear it. |-| `hasAgent` | boolean | No | Set true if mentioning this bot should open a sandboxed coding-agent session. Omit to leave unchanged. |+| `hasAgent` | boolean | No | Set true to make this bot an AI agent: mentions and DMs start an agent session. Omit to leave unchanged. |diff --git a/apps/docs/AI/mcp/tools/create-bot.mdx b/apps/docs/AI/mcp/tools/create-bot.mdxindex ea1f27ae68..37e0ef785f 100644--- a/apps/docs/AI/mcp/tools/create-bot.mdx+++ b/apps/docs/AI/mcp/tools/create-bot.mdx@@ -20,4 +20,4 @@ Create a bot with a name, stable handle, and optional profile. Omit teamId for a| `channelId` | string | No | Channel id to grant the new bot access to. Requires current-user channel membership. When set, the tool also returns the channel webhook URL and a credential proposal the user can mint from the chat card. || `credentialLabel` | string | No | Optional label for the credential the user will mint when channelId is set, such as `github-webhook`. Requires channelId. || `credentialExpiresAt` | string | No | Optional RFC 3339 expiration for the credential the user will mint when channelId is set. Requires channelId. |-| `hasAgent` | boolean | No | Set true if mentioning this bot should open a sandboxed coding-agent session. Defaults to false. |+| `hasAgent` | boolean | No | Set true to make this bot an AI agent: mentions and DMs start an agent session. Defaults to false. |diff --git a/apps/web/src/features/channel/Bots/BotAgentSection.tsx b/apps/web/src/features/channel/Bots/BotAgentSection.tsxindex a0369d1d28..3487b8825d 100644--- a/apps/web/src/features/channel/Bots/BotAgentSection.tsx+++ b/apps/web/src/features/channel/Bots/BotAgentSection.tsx@@ -14,15 +14,14 @@ export function BotAgentSection(props: {<Show when={agentsEnabled()}><BotFormSectiontitle="Agent"- description="Make this bot available in the model selector when starting an AI chat."+ description="Make this bot available in the model selector and respond to mentions."><div class="flex items-center justify-between gap-4"><div class="min-w-0">- <div class="text-sm font-medium text-ink">- Show in model selector- </div>+ <div class="text-sm font-medium text-ink">Enable AI agent</div><p class="mt-0.5 text-xs text-ink-muted">- Connect an agent such as Codex or Hermes to handle requests.+ Use a chat agent or connect an external runtime to handle+ requests.</p></div><ToggleSwitch@@ -30,7 +29,7 @@ export function BotAgentSection(props: {checked={props.checked}disabled={props.disabled}onChange={props.onChange}- label={<span>Show in model selector</span>}+ label={<span>Enable AI agent</span>}labelClass="sr-only"/></div>diff --git a/apps/web/src/lib/service-clients/service-cognition/generated/tools/types.ts b/apps/web/src/lib/service-clients/service-cognition/generated/tools/types.tsindex 9c89ff6b55..c013367545 100644--- a/apps/web/src/lib/service-clients/service-cognition/generated/tools/types.ts+++ b/apps/web/src/lib/service-clients/service-cognition/generated/tools/types.ts@@ -6249,7 +6249,7 @@ export interface BotSummary {*/avatarUrl?: string | null;/**- * Whether mentioning this bot opens a sandboxed coding-agent session.+ * Whether this bot runs as an AI agent: mentions and DMs start an agent session.*/hasAgent: boolean;}@@ -6278,7 +6278,7 @@ export interface ConfigureBot {*/avatarUrl?: string | null;/**- * Set true if mentioning this bot should open a sandboxed coding-agent session. Omit to leave unchanged.+ * Set true to make this bot an AI agent: mentions and DMs start an agent session. Omit to leave unchanged.*/hasAgent?: boolean | null;}@@ -7270,7 +7270,7 @@ export interface CreateBot {*/credentialExpiresAt?: string | null;/**- * Set true if mentioning this bot should open a sandboxed coding-agent session. Defaults to false.+ * Set true to make this bot an AI agent: mentions and DMs start an agent session. Defaults to false.*/hasAgent?: boolean | null;}diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/bot.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/bot.tsindex ee94d8e2e6..54c0ff73b3 100644--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/bot.ts+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/bot.ts@@ -30,7 +30,7 @@ export interface Bot {description?: BotDescription;/** Stable handle. */handle: string;- /** Whether mentioning this bot opens a sandboxed coding-agent session. */+ /** Whether this bot runs as an AI agent: mentions and DMs start an agent session. */has_agent: boolean;/** Bot id. */id: BotId;diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/createBotRequest.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/createBotRequest.tsindex 32ee2c33c8..2d9a7d0b91 100644--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/createBotRequest.ts+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/createBotRequest.ts@@ -19,7 +19,7 @@ export interface CreateBotRequest {description?: CreateBotRequestDescription;/** Stable handle. */handle: string;- /** Whether mentioning this bot opens a sandboxed coding-agent session. Defaults to false. */+ /** Whether this bot runs as an AI agent: mentions and DMs start an agent session. Defaults to false. */has_agent?: CreateBotRequestHasAgent;/** Display name. */name: string;diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/createBotRequestHasAgent.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/createBotRequestHasAgent.tsindex f6eecdf88f..6381ef1bcf 100644--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/createBotRequestHasAgent.ts+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/createBotRequestHasAgent.ts@@ -6,6 +6,6 @@*//**- * Whether mentioning this bot opens a sandboxed coding-agent session. Defaults to false.+ * Whether this bot runs as an AI agent: mentions and DMs start an agent session. Defaults to false.*/export type CreateBotRequestHasAgent = boolean | null;diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/createChannelScopedBotRequest.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/createChannelScopedBotRequest.tsindex 11cc38841f..045a1ce88a 100644--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/createChannelScopedBotRequest.ts+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/createChannelScopedBotRequest.ts@@ -21,7 +21,7 @@ export interface CreateChannelScopedBotRequest {description?: CreateChannelScopedBotRequestDescription;/** Stable handle. */handle: string;- /** Whether mentioning this bot opens a sandboxed coding-agent session. Defaults to false. */+ /** Whether this bot runs as an AI agent: mentions and DMs start an agent session. Defaults to false. */has_agent?: CreateChannelScopedBotRequestHasAgent;/** Display name. */name: string;diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/createChannelScopedBotRequestHasAgent.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/createChannelScopedBotRequestHasAgent.tsindex fa8e1f8c93..f04d567477 100644--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/createChannelScopedBotRequestHasAgent.ts+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/createChannelScopedBotRequestHasAgent.ts@@ -6,6 +6,6 @@*//**- * Whether mentioning this bot opens a sandboxed coding-agent session. Defaults to false.+ * Whether this bot runs as an AI agent: mentions and DMs start an agent session. Defaults to false.*/export type CreateChannelScopedBotRequestHasAgent = boolean | null;diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/patchBotRequest.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/patchBotRequest.tsindex 3689147a4d..245fee97d3 100644--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/patchBotRequest.ts+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/patchBotRequest.ts@@ -20,7 +20,7 @@ export interface PatchBotRequest {description?: PatchBotRequestDescription;/** Stable handle. */handle?: PatchBotRequestHandle;- /** Whether mentioning this bot opens a sandboxed coding-agent session. Omit to leave unchanged. */+ /** Whether this bot runs as an AI agent: mentions and DMs start an agent session. Omit to leave unchanged. */has_agent?: PatchBotRequestHasAgent;/** Display name. */name?: PatchBotRequestName;diff --git a/apps/web/src/lib/service-clients/service-storage/generated/schemas/patchBotRequestHasAgent.ts b/apps/web/src/lib/service-clients/service-storage/generated/schemas/patchBotRequestHasAgent.tsindex d477d004fd..7fc2647e57 100644--- a/apps/web/src/lib/service-clients/service-storage/generated/schemas/patchBotRequestHasAgent.ts+++ b/apps/web/src/lib/service-clients/service-storage/generated/schemas/patchBotRequestHasAgent.ts@@ -6,6 +6,6 @@*//**- * Whether mentioning this bot opens a sandboxed coding-agent session. Omit to leave unchanged.+ * Whether this bot runs as an AI agent: mentions and DMs start an agent session. Omit to leave unchanged.*/export type PatchBotRequestHasAgent = boolean | null;diff --git a/apps/web/src/lib/service-clients/service-storage/generated/zod.ts b/apps/web/src/lib/service-clients/service-storage/generated/zod.tsindex cd976083e9..d539232436 100644--- a/apps/web/src/lib/service-clients/service-storage/generated/zod.ts+++ b/apps/web/src/lib/service-clients/service-storage/generated/zod.ts@@ -34,7 +34,7 @@ export const listAgentsResponseItem = zodhas_agent: zod.boolean().describe(- 'Whether mentioning this bot opens a sandboxed coding-agent session.'+ 'Whether this bot runs as an AI agent: mentions and DMs start an agent session.'),id: zod.string(),kind: zod.enum(['owned', 'system']).describe('Bot kind.'),@@ -335,7 +335,7 @@ export const updateAgentResponse = zodhas_agent: zod.boolean().describe(- 'Whether mentioning this bot opens a sandboxed coding-agent session.'+ 'Whether this bot runs as an AI agent: mentions and DMs start an agent session.'),id: zod.string(),kind: zod.enum(['owned', 'system']).describe('Bot kind.'),@@ -772,7 +772,7 @@ export const getSelfBotResponse = zodhas_agent: zod.boolean().describe(- 'Whether mentioning this bot opens a sandboxed coding-agent session.'+ 'Whether this bot runs as an AI agent: mentions and DMs start an agent session.'),id: zod.string(),kind: zod.enum(['owned', 'system']).describe('Bot kind.'),@@ -4117,7 +4117,7 @@ export const createChannelScopedBotBody = zod.boolean().nullish().describe(- 'Whether mentioning this bot opens a sandboxed coding-agent session. Defaults to false.'+ 'Whether this bot runs as an AI agent: mentions and DMs start an agent session. Defaults to false.'),name: zod.string().describe('Display name.'),team_id: zoddiff --git a/apps/web/src/lib/service-clients/service-storage/openapi.json b/apps/web/src/lib/service-clients/service-storage/openapi.jsonindex 001340baf0..9c65aeb5f2 100644--- a/apps/web/src/lib/service-clients/service-storage/openapi.json+++ b/apps/web/src/lib/service-clients/service-storage/openapi.json@@ -22932,7 +22932,7 @@},"has_agent": {"type": "boolean",- "description": "Whether mentioning this bot opens a sandboxed coding-agent session."+ "description": "Whether this bot runs as an AI agent: mentions and DMs start an agent session."},"id": {"$ref": "#/components/schemas/BotId",@@ -26847,7 +26847,7 @@},"has_agent": {"type": ["boolean", "null"],- "description": "Whether mentioning this bot opens a sandboxed coding-agent session. Defaults to false."+ "description": "Whether this bot runs as an AI agent: mentions and DMs start an agent session. Defaults to false."},"name": {"type": "string",@@ -27037,7 +27037,7 @@},"has_agent": {"type": ["boolean", "null"],- "description": "Whether mentioning this bot opens a sandboxed coding-agent session. Defaults to false."+ "description": "Whether this bot runs as an AI agent: mentions and DMs start an agent session. Defaults to false."},"name": {"type": "string",@@ -38398,7 +38398,7 @@},"has_agent": {"type": ["boolean", "null"],- "description": "Whether mentioning this bot opens a sandboxed coding-agent session. Omit to leave unchanged."+ "description": "Whether this bot runs as an AI agent: mentions and DMs start an agent session. Omit to leave unchanged."},"name": {"type": ["string", "null"],diff --git a/crates/agent_trigger/src/domain/service/test.rs b/crates/agent_trigger/src/domain/service/test.rsindex c7ded85ae6..8edd9afaf3 100644--- a/crates/agent_trigger/src/domain/service/test.rs+++ b/crates/agent_trigger/src/domain/service/test.rs@@ -3,6 +3,7 @@ use super::*;#[cfg(feature = "admission")]mod admission;mod call;+mod configured_agent;mod task_assignment;use agent_session::domain::error::AgentSessionError;diff --git a/crates/agent_trigger/src/domain/service/test/configured_agent.rs b/crates/agent_trigger/src/domain/service/test/configured_agent.rsnew file mode 100644index 0000000000..bebb4a4eac--- /dev/null+++ b/crates/agent_trigger/src/domain/service/test/configured_agent.rs@@ -0,0 +1,19 @@+use super::*;++#[tokio::test]+async fn non_coding_agent_mentions_dispatch_when_the_agent_flag_is_enabled() {+ for enabled in [false, true] {+ let posted = message(vec![mention_of(BotId::TEST_A)]);+ let mut bots = MockAgentBotLookup::new();+ bots.expect_get_agent().once().return_once(move |bot_id| {+ Box::pin(async move {+ let mut agent = private_agent(bot_id);+ agent.bot.has_agent = enabled;+ agent.is_coding = false;+ Ok(Some(agent))+ })+ });++ assert_eq!(mention_yields_event(&posted, bots).await, enabled);+ }+}diff --git a/crates/bots/AGENTS.md b/crates/bots/AGENTS.mdindex 139b878ecb..d7d2307321 100644--- a/crates/bots/AGENTS.md+++ b/crates/bots/AGENTS.md@@ -42,6 +42,8 @@ for bot mutations that channel bots, agent triggers, and memory build on.## Gotchas+- Agent create/update/patch must persist `has_agent = true` atomically with+ configuration writes; mention dispatch gates on this flag for every harness.- Kafka events key on the bot's bare UUID (no `bot|` prefix); `bot.updated`metadata describes the requested PATCH, not a full snapshot — an omittedfield serializes as `null` (see `README.md`).diff --git a/crates/bots/src/domain/models.rs b/crates/bots/src/domain/models.rsindex 70d32f33ec..43dac27377 100644--- a/crates/bots/src/domain/models.rs+++ b/crates/bots/src/domain/models.rs@@ -148,7 +148,7 @@ pub struct Bot {pub updated_at: DateTime<Utc>,/// Soft-delete timestamp.pub deleted_at: Option<DateTime<Utc>>,- /// Whether mentioning this bot opens a sandboxed coding-agent session.+ /// Whether this bot runs as an AI agent: mentions and DMs start an agent session.pub has_agent: bool,}@@ -615,7 +615,7 @@ pub struct CreateBotRequest {pub description: Option<String>,/// Optional avatar URL.pub avatar_url: Option<String>,- /// Whether mentioning this bot opens a sandboxed coding-agent session. Defaults to false.+ /// Whether this bot runs as an AI agent: mentions and DMs start an agent session. Defaults to false.pub has_agent: Option<bool>,}@@ -631,7 +631,7 @@ pub struct PatchBotRequest {pub description: Option<String>,/// Optional avatar URL.pub avatar_url: Option<String>,- /// Whether mentioning this bot opens a sandboxed coding-agent session. Omit to leave unchanged.+ /// Whether this bot runs as an AI agent: mentions and DMs start an agent session. Omit to leave unchanged.pub has_agent: Option<bool>,}@@ -671,7 +671,7 @@ pub struct CreateChannelScopedBotRequest {pub token_label: Option<String>,/// Optional token expiration timestamp.pub token_expires_at: Option<DateTime<Utc>>,- /// Whether mentioning this bot opens a sandboxed coding-agent session. Defaults to false.+ /// Whether this bot runs as an AI agent: mentions and DMs start an agent session. Defaults to false.pub has_agent: Option<bool>,}diff --git a/crates/bots/src/domain/ports.rs b/crates/bots/src/domain/ports.rsindex bd50f27f7e..c696ed26eb 100644--- a/crates/bots/src/domain/ports.rs+++ b/crates/bots/src/domain/ports.rs@@ -20,7 +20,8 @@ pub trait BotRepo: Send + Sync + 'static {/// Repository error.type Err: Into<anyhow::Error> + Send;- /// Create an owned agent and its selected channel memberships atomically.+ /// Create an owned agent and its selected channel memberships atomically,+ /// with `has_agent` enabled.fn create_agent(&self,owner: BotOwner,@@ -28,7 +29,8 @@ pub trait BotRepo: Send + Sync + 'static {req: CreateAgentRequest,) -> impl Future<Output = Result<Agent, Self::Err>> + Send;- /// Replace an owned agent and its selected channel memberships atomically.+ /// Replace an owned agent and its selected channel memberships atomically,+ /// enabling `has_agent` even if it was previously disabled./// The direct agent conversations it takes part in are not among them and/// are left as they are.fn update_agent(diff --git a/crates/bots/src/inbound/toolset/configure_bot.rs b/crates/bots/src/inbound/toolset/configure_bot.rsindex 8ae530a03d..b449ef15fb 100644--- a/crates/bots/src/inbound/toolset/configure_bot.rs+++ b/crates/bots/src/inbound/toolset/configure_bot.rs@@ -57,9 +57,9 @@ pub struct ConfigureBot {)]#[serde(default)]pub avatar_url: Option<String>,- /// Optional coding-agent session flag.+ /// Optional AI-agent session flag.#[schemars(- description = "Set true if mentioning this bot should open a sandboxed coding-agent session. Omit to leave unchanged."+ description = "Set true to make this bot an AI agent: mentions and DMs start an agent session. Omit to leave unchanged.")]#[serde(default)]pub has_agent: Option<bool>,diff --git a/crates/bots/src/inbound/toolset/create_bot.rs b/crates/bots/src/inbound/toolset/create_bot.rsindex 55a5c790ae..9ba248e2b8 100644--- a/crates/bots/src/inbound/toolset/create_bot.rs+++ b/crates/bots/src/inbound/toolset/create_bot.rs@@ -78,9 +78,9 @@ pub struct CreateBot {)]#[serde(default)]pub credential_expires_at: Option<DateTime<Utc>>,- /// Optional coding-agent session flag.+ /// Optional AI-agent session flag.#[schemars(- description = "Set true if mentioning this bot should open a sandboxed coding-agent session. Defaults to false."+ description = "Set true to make this bot an AI agent: mentions and DMs start an agent session. Defaults to false.")]#[serde(default)]pub has_agent: Option<bool>,diff --git a/crates/bots/src/inbound/toolset/types.rs b/crates/bots/src/inbound/toolset/types.rsindex bc51435780..348056c409 100644--- a/crates/bots/src/inbound/toolset/types.rs+++ b/crates/bots/src/inbound/toolset/types.rs@@ -55,7 +55,7 @@ pub struct BotSummary {pub description: Option<String>,/// Optional profile-picture URL.pub avatar_url: Option<String>,- /// Whether mentioning this bot opens a sandboxed coding-agent session.+ /// Whether this bot runs as an AI agent: mentions and DMs start an agent session.pub has_agent: bool,}diff --git a/crates/bots/src/outbound/pg_bots_repo.rs b/crates/bots/src/outbound/pg_bots_repo.rsindex 857bcd672c..0f24db0ac8 100644--- a/crates/bots/src/outbound/pg_bots_repo.rs+++ b/crates/bots/src/outbound/pg_bots_repo.rs@@ -455,6 +455,7 @@ impl BotRepo for PgBotsRepo {handle = $5,description = $6,avatar_url = $7,+ has_agent = true,updated_at = now()WHERE id = $1AND deleted_at IS NULLdiff --git a/crates/bots/src/outbound/pg_bots_repo/tests.rs b/crates/bots/src/outbound/pg_bots_repo/tests.rsindex 8c82f3bf36..b0720fb19e 100644--- a/crates/bots/src/outbound/pg_bots_repo/tests.rs+++ b/crates/bots/src/outbound/pg_bots_repo/tests.rs@@ -19,6 +19,7 @@ use sqlx::PgPool;use std::sync::{Arc, Mutex};mod agent_dm;+mod agent_enabled;const USER_OWNER: &str = "macro|[email protected]";const USER_OTHER: &str = "macro|[email protected]";diff --git a/crates/bots/src/outbound/pg_bots_repo/tests/agent_enabled.rs b/crates/bots/src/outbound/pg_bots_repo/tests/agent_enabled.rsnew file mode 100644index 0000000000..f14379bfbb--- /dev/null+++ b/crates/bots/src/outbound/pg_bots_repo/tests/agent_enabled.rs@@ -0,0 +1,94 @@+use super::*;++#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn agent_update_and_patch_restore_mention_dispatch_flag(pool: PgPool) -> anyhow::Result<()> {+ let service = service(&pool);+ let mut request = create_agent_req("chat-agent", AgentChannelScope::All);+ request.harness = "in-memory".to_string();+ request.is_coding = false;+ let created = service.create_agent(user_id(USER_OWNER), request).await?;+ assert!(created.bot.has_agent);++ for (enabled, patch) in [(false, false), (true, false), (false, true), (true, true)] {+ sqlx::query!(+ "UPDATE bots SET has_agent = $2 WHERE id = $1",+ created.bot.id.as_uuid(),+ enabled,+ )+ .execute(&pool)+ .await?;++ let updated = if patch {+ service+ .patch_agent(+ user_id(USER_OWNER),+ created.bot.id,+ PatchAgentRequest {+ instructions: Some("Answer questions in chat.".to_string()),+ ..Default::default()+ },+ )+ .await?+ } else {+ service+ .update_agent(+ user_id(USER_OWNER),+ created.bot.id,+ update_agent_req("chat-agent", AgentChannelScope::All),+ )+ .await?+ };+ assert!(updated.bot.has_agent);+ assert!(!updated.is_coding);+ let fetched = service+ .manageable_agent(user_id(USER_OWNER), created.bot.id)+ .await?;+ assert!(fetched.bot.has_agent);+ }+ Ok(())+}++#[sqlx::test(migrator = "MACRO_DB_MIGRATIONS")]+async fn backfill_enables_configured_agents_and_preserves_plain_bots(+ pool: PgPool,+) -> anyhow::Result<()> {+ let service = service(&pool);+ let configured = service+ .create_agent(+ user_id(USER_OWNER),+ create_agent_req("configured-agent", AgentChannelScope::All),+ )+ .await?;+ let plain = service+ .create_bot(user_id(USER_OWNER), create_req("plain-bot"))+ .await?;+ sqlx::query!(+ "UPDATE bots SET has_agent = false WHERE id = $1",+ configured.bot.id.as_uuid(),+ )+ .execute(&pool)+ .await?;++ for _ in 0..2 {+ sqlx::raw_sql(include_str!(+ "../../../../../macro_db_client/migrations/20261105072859_enable_configured_bot_agents.sql"+ ))+ .execute(&pool)+ .await?;+ }+ assert!(+ service+ .manageable_agent(user_id(USER_OWNER), configured.bot.id)+ .await?+ .bot+ .has_agent+ );+ assert!(+ !PgBotsRepo::new(pool)+ .get_bot(plain.id)+ .await?+ .expect("plain bot")+ .has_agent+ );+ Ok(())+}diff --git a/crates/macro_db_client/migrations/20261105072859_enable_configured_bot_agents.sql b/crates/macro_db_client/migrations/20261105072859_enable_configured_bot_agents.sqlnew file mode 100644index 0000000000..f3062aaeff--- /dev/null+++ b/crates/macro_db_client/migrations/20261105072859_enable_configured_bot_agents.sql@@ -0,0 +1,7 @@+-- Configured agents must be eligible for mention dispatch, regardless of harness.+SET LOCAL lock_timeout = '5s';++UPDATE bots+SET has_agent = true+WHERE NOT has_agent+ AND EXISTS (SELECT 1 FROM agent_configs WHERE bot_id = bots.id);diff --git a/docs/agent-guide/settings.md b/docs/agent-guide/settings.mdindex c8a20246fd..b460fea99a 100644--- a/docs/agent-guide/settings.md+++ b/docs/agent-guide/settings.md@@ -788,8 +788,9 @@ how to add the bot to channels and use its token with the Macro SDK. **Createbot** keeps Profile and Channels visible. **Advanced** starts collapsed on bothdesktop and mobile and contains:-- **Agent → Show in model selector**: makes the bot available when starting an- AI chat; connect an agent such as Codex or Hermes to handle requests. This+- **Agent → Enable AI agent**: makes the bot available in the model selector+ and lets it respond to mentions, using a chat agent or a connected external+ runtime. Saving an agent configuration enables it regardless of harness. Thissection remains gated by the agents rollout.- **Ownership → Mentionable**: lets teammates find and @mention the bot andcreates it under team ownership. With the switch off, the creator owns it.diff --git a/packages/sdk/generated/storage/types.gen.ts b/packages/sdk/generated/storage/types.gen.tsindex 1f5d68f03a..5c635ce766 100644--- a/packages/sdk/generated/storage/types.gen.ts+++ b/packages/sdk/generated/storage/types.gen.ts@@ -1409,7 +1409,7 @@ export type Bot = {*/handle: string;/**- * Whether mentioning this bot opens a sandboxed coding-agent session.+ * Whether this bot runs as an AI agent: mentions and DMs start an agent session.*/has_agent: boolean;/**@@ -4025,7 +4025,7 @@ export type CreateBotRequest = {*/handle: string;/**- * Whether mentioning this bot opens a sandboxed coding-agent session. Defaults to false.+ * Whether this bot runs as an AI agent: mentions and DMs start an agent session. Defaults to false.*/has_agent?: boolean | null;/**@@ -4158,7 +4158,7 @@ export type CreateChannelScopedBotRequest = {*/handle: string;/**- * Whether mentioning this bot opens a sandboxed coding-agent session. Defaults to false.+ * Whether this bot runs as an AI agent: mentions and DMs start an agent session. Defaults to false.*/has_agent?: boolean | null;/**@@ -11445,7 +11445,7 @@ export type PatchBotRequest = {*/handle?: string | null;/**- * Whether mentioning this bot opens a sandboxed coding-agent session. Omit to leave unchanged.+ * Whether this bot runs as an AI agent: mentions and DMs start an agent session. Omit to leave unchanged.*/has_agent?: boolean | null;/**diff --git a/packages/sdk/specs/storage.json b/packages/sdk/specs/storage.jsonindex 001340baf0..9c65aeb5f2 100644--- a/packages/sdk/specs/storage.json+++ b/packages/sdk/specs/storage.json@@ -22932,7 +22932,7 @@},"has_agent": {"type": "boolean",- "description": "Whether mentioning this bot opens a sandboxed coding-agent session."+ "description": "Whether this bot runs as an AI agent: mentions and DMs start an agent session."},"id": {"$ref": "#/components/schemas/BotId",@@ -26847,7 +26847,7 @@},"has_agent": {"type": ["boolean", "null"],- "description": "Whether mentioning this bot opens a sandboxed coding-agent session. Defaults to false."+ "description": "Whether this bot runs as an AI agent: mentions and DMs start an agent session. Defaults to false."},"name": {"type": "string",@@ -27037,7 +27037,7 @@},"has_agent": {"type": ["boolean", "null"],- "description": "Whether mentioning this bot opens a sandboxed coding-agent session. Defaults to false."+ "description": "Whether this bot runs as an AI agent: mentions and DMs start an agent session. Defaults to false."},"name": {"type": "string",@@ -38398,7 +38398,7 @@},"has_agent": {"type": ["boolean", "null"],- "description": "Whether mentioning this bot opens a sandboxed coding-agent session. Omit to leave unchanged."+ "description": "Whether this bot runs as an AI agent: mentions and DMs start an agent session. Omit to leave unchanged."},"name": {"type": ["string", "null"],