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
feat(agents): start coding agents through code mode; hide the dispatch tools there (#9338)
Wolf Mermelsteine08f2513796f
diff --git a/crates/agent_code_mode/SKILL.md b/crates/agent_code_mode/SKILL.mdindex 5f9b3c2f3e..61c3b0b433 100644--- a/crates/agent_code_mode/SKILL.md+++ b/crates/agent_code_mode/SKILL.md@@ -48,6 +48,7 @@ When it returns duplicates, tell the user it created nothing and ask whether to- Search several precise phrases concurrently, read relevant documents, then calculate an aggregate in one execution. Preserve query attribution, source IDs and sampling limits.- Collect a bounded recent-email batch, fetch relevant content, then map macro.ai.decide over it with bounded parallelism. Retain every error and distinguish probability estimates from facts. The ai guide has a complete example.- Generate structured extraction with macro.ai.structuredCompletion and toolset:{type:'none'}, using source text already fetched; check the returned outcome rather than assuming success.+- Start another agent's session only when the user asks for one: choose one of the user's own agents from macro.agents.list() by name and pass it as agent to macro.agentSessions.createManaged({agent, prompt, repoUrl}), or omit agent for the default persona. Write a self-contained prompt, return session.id, and check back later with a routine rather than waiting in the execution.- Use Handlebars to personalize many drafts, persist a single email review stack, and return its reference. The templates guide shows the full module. Chat continues while the user edits and sends later.- Present what the program made, changed or found with `await execution.views.present(view)`, in the format of the PresentView schema in ExecuteCode's description. A view is a review with nothing saved: it is checked and drawn at once while main continues, and it never comes back as an event. A view that does not match throws with what to fix.- Persist calendar drafts with the same review entity, and let the user finish in the reused component. Reviews survive the Deno process and page reload. Creating one immediately presents a completed PresentReview tool call in the shared session stream; it does not wait for approval. The card can appear while main is still running. "Presented to the user" never means sent or approved. Submissions queue a separate outcome into the original session. The direct PresentReview tool offers the same UI outside code mode. After presenting, end by asking "Should I kick it off?"; when the person whose account the review uses says yes, submit it with the direct DecideReview tool, which approves it as the card would. It refuses in a turn someone else prompted or a system event started, and while the review is not ready. An approved import reports its end later as a review.settled system event with the final report.diff --git a/crates/agent_code_mode/src/domain/service.rs b/crates/agent_code_mode/src/domain/service.rsindex 2dfdacd883..1ca5478195 100644--- a/crates/agent_code_mode/src/domain/service.rs+++ b/crates/agent_code_mode/src/domain/service.rs@@ -253,6 +253,9 @@ pub fn covered_by_code_sdk(name: &str, user_tool: bool) -> bool {| "CreateSkill"| "Decide"| "GenerateObject"+ // macro.agents.list() and macro.agentSessions.createManaged.+ | "ListCodingAgents"+ | "DispatchCodingAgent")}diff --git a/crates/ai_tools/src/lib.rs b/crates/ai_tools/src/lib.rsindex 1ec67a3cf7..86e43f99e8 100644--- a/crates/ai_tools/src/lib.rs+++ b/crates/ai_tools/src/lib.rs@@ -370,8 +370,10 @@ fn tools_for_inner(host: AiHost, code_mode_direct: bool) -> ToolSetWithPrompt {};let prompt: Box<dyn std::fmt::Display + Send + Sync> = match host {AiHost::Chat => Box::new(prompt::TOOL_USE_PROMPT.compose(&prompt::coding_agents::PROMPT)),+ // Code mode hides the dispatch tools; agents start sessions through the SDK.AiHost::AgentSession if code_mode_direct => Box::new(- prompt::CODE_MODE_SESSION_TOOL_USE_PROMPT.compose(&prompt::coding_agents::PROMPT),+ prompt::CODE_MODE_SESSION_TOOL_USE_PROMPT+ .compose(&prompt::coding_agents::CODE_MODE_PROMPT),),AiHost::AgentSession => {Box::new(prompt::SESSION_TOOL_USE_PROMPT.compose(&prompt::coding_agents::PROMPT))diff --git a/crates/ai_tools/src/test.rs b/crates/ai_tools/src/test.rsindex 23518bc9ca..77abc961af 100644--- a/crates/ai_tools/src/test.rs+++ b/crates/ai_tools/src/test.rs@@ -121,6 +121,29 @@ fn coding_dispatch_is_available_to_every_host_but_not_internal_subagents() {}}+#[test]+fn code_mode_starts_agents_through_the_sdk_instead_of_dispatch_tools() {+ let tools = tools_for_agent_code_mode();+ let prompt = tools.prompt.to_string();+ for name in ["ListCodingAgents", "DispatchCodingAgent"] {+ assert!(!tools.toolset.tools.contains_key(name), "{name}");+ assert!(+ !tools.deferred.iter().any(|tool| tool.name == name),+ "{name}"+ );+ assert!(!prompt.contains(name), "{name}");+ }+ assert!(tools.toolset.tools.contains_key("ListAgentUpdates"));+ assert!(prompt.contains("macro.agents.list()"));+ assert!(prompt.contains("macro.agentSessions.createManaged"));+ assert!(+ !tools_for(AiHost::AgentSession)+ .prompt+ .to_string()+ .contains("createManaged")+ );+}+#[test]fn project_workflows_are_available_in_every_host_alongside_folder_and_property_tools() {let names = [@@ -650,7 +673,6 @@ fn code_mode_retains_direct_lifecycles_and_hides_sdk_methods_from_lazy_discovery"EditPresentation","EditDocument","Subagent",- "DispatchCodingAgent","SearchTools","LoadTools","DiscoverConnectors",diff --git a/crates/prompt/src/code_mode_agents.txt b/crates/prompt/src/code_mode_agents.txtnew file mode 100644index 0000000000..cbe27dbffd--- /dev/null+++ b/crates/prompt/src/code_mode_agents.txt@@ -0,0 +1,20 @@+Do repository and coding work yourself when you can. Start another agent session only when the user asks for one, or the work needs a repository runtime you do not have.++Start sessions from ExecuteCode. macro.agents.list() returns the user's own configurable agents; choose by name and instructions, preferring an agent the user named, and pass it as `agent` to macro.agentSessions.createManaged. Never invent an agent or construct one by id. To use the default persona instead, omit `agent`. Read AgentSessionNamespace.createManaged with ReadCodeDocs before the first call.++```javascript+export async function main({macro}) {+ const agents = await macro.agents.list();+ const names = await Promise.all(agents.map((agent) => agent.name()));+ const agent = agents[names.indexOf('Web maintainer')];+ if (!agent) return {data: {error: 'No agent named Web maintainer', available: names}};+ const session = await macro.agentSessions.createManaged({+ agent,+ repoUrl: 'https://github.com/acme/web',+ prompt: 'Fix the login redirect loop in acme/web. ...',+ });+ return {data: {sessionId: session.id}};+}+```++The prompt must be self-contained: the task, repository, relevant findings and links, constraints, and expected outcome. The new session does not receive this conversation. When the outcome is a pull request, require it to be ready for review, not a draft, with CI passing before the agent finishes. Create once per task and do not retry automatically after an uncertain failure. Link the session in your reply with its id. To check on it later, create a routine; never wait or poll inside an execution.diff --git a/crates/prompt/src/coding_agents.rs b/crates/prompt/src/coding_agents.rsindex 75d5bfab56..723af533bc 100644--- a/crates/prompt/src/coding_agents.rs+++ b/crates/prompt/src/coding_agents.rs@@ -8,3 +8,11 @@ pub static PROMPT: StaticPrompt<'static> = StaticPrompt::borrowed(include_str!("coding_agents.txt"),"Select an available coding persona and start a session for repository work. Pull-request tasks require a ready, CI-passing pull request rather than a draft.",);++/// Code-mode replacement for [`PROMPT`]: these sessions start agents through+/// the SDK, and the dispatch tools are hidden there.+pub static CODE_MODE_PROMPT: StaticPrompt<'static> = StaticPrompt::borrowed(+ "Starting agent sessions",+ include_str!("code_mode_agents.txt"),+ "Work natively first; start another agent's session from ExecuteCode with macro.agents.list and macro.agentSessions.createManaged. Pull-request tasks require a ready, CI-passing pull request rather than a draft.",+);diff --git a/crates/prompt/src/lib.rs b/crates/prompt/src/lib.rsindex 395beee582..6778f6095d 100644--- a/crates/prompt/src/lib.rs+++ b/crates/prompt/src/lib.rs@@ -420,6 +420,11 @@ mod tests {let coding = coding_agents::PROMPT.to_string();assert!(coding.contains("ready for review, not a draft"));assert!(coding.contains("CI passing"));++ let code_mode = coding_agents::CODE_MODE_PROMPT.to_string();+ assert!(code_mode.contains("macro.agentSessions.createManaged"));+ assert!(code_mode.contains("ready for review, not a draft"));+ assert!(!code_mode.contains("DispatchCodingAgent"));}#[test]diff --git a/docs/agent-guide/ai-chat.md b/docs/agent-guide/ai-chat.mdindex 5a5ae6e632..99857c2d9e 100644--- a/docs/agent-guide/ai-chat.md+++ b/docs/agent-guide/ai-chat.md@@ -351,6 +351,12 @@ you can follow up there. Reloading the chat restores the same session card.Failed dispatches do not show a successful session card. If no coding agents areavailable, configure one in Agents before retrying.+Code-mode sessions do not get these two tools. They do the coding work themselves+first and, when asked to hand a task off, run `ExecuteCode`: pick one of your own+agents from `macro.agents.list()` and start it with+`macro.agentSessions.createManaged({ agent, prompt, repoUrl })`, omitting `agent`+for the default persona. Built-in personas cannot be chosen by id there yet.+Ask a chat agent what your coding agents need from you and it calls`ListAgentUpdates`: your non-archived coding sessions waiting on a permission,question, or tool approval, plus sessions running with no activity for 20