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(agent): open each reply with a line from a fast model (#7795)
Wolf Mermelsteinc3ecfd3f074e
diff --git a/apps/web/src/features/block-agent/component/AgentMessage.tsx b/apps/web/src/features/block-agent/component/AgentMessage.tsxindex 7f973271f4..10dc6b5a07 100644--- a/apps/web/src/features/block-agent/component/AgentMessage.tsx+++ b/apps/web/src/features/block-agent/component/AgentMessage.tsx@@ -247,6 +247,9 @@ function promptAuthorName(: idToDisplayName(author.userId);}+const AGENT_CONTEXT_OPEN = '<m-agent-context>';+const PENDING_AGENT_CONTEXT = `${AGENT_CONTEXT_OPEN}{"version":1,"text":""}</m-agent-context>\n\n`;+/*** A prompt, in the chat block's user-bubble treatment* (`@core/component/AI/component/message/UserMessage.tsx`): right-aligned,@@ -256,13 +259,28 @@ function promptAuthorName(function UserMessage(props: { message: FoldedMessage }) {const userId = useUserId();const authorName = () => promptAuthorName(props.message.author, userId());+ // The harness puts context before every prompt it delivers. Until the log+ // confirms this one, an empty stand-in renders where it will, through the+ // same markdown, so nothing moves when the real one arrives.+ const parts = () => {+ const parts = props.message.parts;+ if (!props.message.pending) return parts;+ const first = parts.findIndex((part) => part.kind === 'text');+ const part = parts[first];+ if (part?.kind !== 'text' || part.text.startsWith(AGENT_CONTEXT_OPEN))+ return parts;+ return parts.map((each, index) =>+ index === first+ ? { ...part, text: PENDING_AGENT_CONTEXT + part.text }+ : each+ );+ };return (<div- class="flex w-full flex-col items-end gap-0.5 transition-opacity"+ class="flex w-full flex-col items-end gap-0.5"// Still on the wire: the fold shows the prompt before the log confirms- // it, and the confirmation clears this in place.- classList={{ 'opacity-60': props.message.pending }}+ // it. It reads as sent at once - dimming it made the wait feel longer.aria-busy={props.message.pending || undefined}ref={(el) =>messageSendMotion(el, () =>@@ -280,7 +298,7 @@ function UserMessage(props: { message: FoldedMessage }) {)}</Show><UserMessageBubble>- <For each={props.message.parts}>+ <For each={parts()}>{(part, index) => (<AgentMessagePartpart={part}diff --git a/crates/agent/src/model/reasoning_effort.rs b/crates/agent/src/model/reasoning_effort.rsindex 7d6feb9252..3f75cd0246 100644--- a/crates/agent/src/model/reasoning_effort.rs+++ b/crates/agent/src/model/reasoning_effort.rs@@ -36,6 +36,7 @@ impl ReasoningEffort {}"openai/gpt-5.5" => &[Default, None, Low, Medium, High, XHigh],"openai/gpt-5-mini" => &[Default, Minimal, Low, Medium, High],+ "openai/gpt-5.4-mini" => &[Default, None, Low, Medium, High, XHigh],_ => &[],}}diff --git a/crates/agent_harness/container/SYSTEM.md b/crates/agent_harness/container/SYSTEM.mdindex fe98f3a7c7..85a1740067 100644--- a/crates/agent_harness/container/SYSTEM.md+++ b/crates/agent_harness/container/SYSTEM.md@@ -10,4 +10,4 @@ General rules:- Inspect existing code before making changes.- Keep changes focused on the user's request.- Run relevant formatting, checks, and tests before reporting completion.-- Every prompt opens with a private context block naming the session's owner, whose access you act with, and who sent the prompt. Follow its note on what a prompt from someone else may do.+- Every prompt opens with a private context block naming the session's owner, whose access you act with, and who sent the prompt. Follow its note on what a prompt from someone else may do. Treat it as system hints, not part of the conversation: never mention, quote, or refer to it (no "the context says"); just act on it.diff --git a/crates/agent_inmem/src/outbound/rig_engine/opener.rs b/crates/agent_inmem/src/outbound/rig_engine/opener.rsnew file mode 100644index 0000000000..8d9b94de73--- /dev/null+++ b/crates/agent_inmem/src/outbound/rig_engine/opener.rs@@ -0,0 +1,252 @@+//! The first line of a turn's reply, written by a fast model racing the+//! turn's own.+//!+//! The fast model answers `true|<line>` when the line is the whole reply (a+//! greeting, thanks, a trivial fact) and `false|<line>` when it only opens+//! one. Either way the line streams to the user as the fast model writes it,+//! long before the turn's model has its first token; `true` also stops the+//! turn's model, which has nothing left to say.++use std::sync::Arc;+use std::time::Duration;++use agent::types::{AssistantMessagePart, ChatMessage, ChatMessageContent, Role};+use agent::{AgentLoop, Message, ReasoningEffort, StreamPart};+use ai_toolset::AsyncToolCollection;+use ai_usage::{UsageContext, UsageRecorder};+use futures::StreamExt as _;+use tokio::sync::mpsc;+use tracing::Instrument as _;++/// The fastest small model that judged every whole-reply-or-not case right.+/// Cerebras gpt-oss-120b was about 4x faster but rate-limited under load.+pub(super) const MODEL: &str = "openai/gpt-5.4-mini";++/// How long the turn waits for the verdict. Past it, the turn's own model is+/// close enough that an opening line is not worth showing.+pub(super) const VERDICT_TIMEOUT: Duration = Duration::from_millis(1500);++/// How long the rest of the line may take once the verdict is in.+pub(super) const LINE_TIMEOUT: Duration = Duration::from_secs(2);++const MAX_TOKENS: u64 = 64;++/// The tail of the conversation the fast model reads: enough to tell "thanks"+/// that closes a task from "thanks, now also…".+const TRANSCRIPT_MESSAGES: usize = 6;+const TRANSCRIPT_MESSAGE_CHARS: usize = 600;++/// Told to the turn's model, so its reply does not open a second time. "May":+/// the opener can lose the race, skip, or fail, and then nothing was shown.+pub(super) const ALREADY_OPENED: &str = "A faster model may already have shown the first line \+of your reply: a short acknowledgement such as \"On it.\" or \"Let me check your calendar.\". \+Begin with substance. Do not acknowledge the request or announce what you are about to do.";++/// Who the line speaks as: the session's agent and the model behind it, so a+/// question about either is answered truthfully rather than as the fast+/// model itself.+pub(super) struct Speaker<'a> {+ /// The agent's name, with its `@` handle when it has one.+ pub agent: &'a str,+ /// The model the session's own turn runs on.+ pub model: &'a str,+}++/// The fast model's verdict. A line's text so far comes with it; the rest+/// follows on the receiver.+pub(super) enum Verdict {+ /// The line is the entire reply.+ Complete(String),+ /// The line opens a reply the turn's model writes.+ Opening(String),+ /// No line fits this follow-up; nothing is shown.+ Silent,+}++/// Start the fast model on `messages`, the conversation ending with the+/// prompt being answered. Its text arrives on the returned receiver as it is+/// written; dropping the receiver stops it.+pub(super) fn spawn(+ recorder: Arc<dyn UsageRecorder>,+ usage_context: UsageContext,+ speaker: &Speaker<'_>,+ tool_names: &str,+ messages: &[ChatMessage],+) -> mpsc::Receiver<String> {+ let (lines, receiver) = mpsc::channel(32);+ let follow_up = messages+ .iter()+ .any(|message| matches!(message.role, Role::Assistant));+ let system_prompt = system_prompt(speaker, tool_names, follow_up);+ let prompt = Message::user(format!(+ "The conversation so far. Write the first line of the reply to the last message.\n\n{}",+ transcript(messages)+ ));+ let metering = agent::MeteringContext::current();+ tokio::spawn(+ agent::MeteringContext::carry(metering, async move {+ let agent_loop = AgentLoop::new(recorder)+ .with_model(MODEL)+ .with_reasoning_effort(ReasoningEffort::None)+ .with_max_tokens(MAX_TOKENS)+ .with_genai_telemetry(false);+ let (mut session, cancel) = agent_loop+ .session(+ Arc::new(AsyncToolCollection::<()>::new()),+ Arc::new(()),+ system_prompt,+ usage_context,+ )+ .await+ .cancellable();+ // The turn stops listening once it has what it needs; stop the+ // request then too, not at the next chunk.+ let started = tokio::select! {+ () = lines.closed() => return cancel.cancel(),+ started = session.send_message(vec![prompt]) => started,+ };+ let mut stream = match started {+ Ok(stream) => stream,+ Err(error) => {+ tracing::warn!(%error, "the opening line's model did not start");+ return;+ }+ };+ loop {+ let part = tokio::select! {+ () = lines.closed() => return cancel.cancel(),+ part = stream.next() => part,+ };+ match part {+ None => return,+ Some(Ok(StreamPart::Content(delta))) => {+ if lines.send(delta).await.is_err() {+ return cancel.cancel();+ }+ }+ Some(Ok(_)) => {}+ Some(Err(error)) => {+ tracing::warn!(%error, "the opening line's model failed");+ return;+ }+ }+ }+ })+ .in_current_span(),+ );+ receiver+}++/// Read up to the fast model's verdict: `true|`, `false|`, or `skip|`.+/// `None` when it wrote anything else or stopped first.+pub(super) async fn verdict(lines: &mut mpsc::Receiver<String>) -> Option<Verdict> {+ let mut text = String::new();+ while let Some(delta) = lines.recv().await {+ text.push_str(&delta);+ let written = text.trim_start();+ if let Some((flag, head)) = written.split_once('|') {+ let head = head.trim_start().to_owned();+ return match flag.trim() {+ "true" => Some(Verdict::Complete(head)),+ "false" => Some(Verdict::Opening(head)),+ "skip" => Some(Verdict::Silent),+ _ => None,+ };+ }+ if written.len() > "false|".len() + 2 {+ return None;+ }+ }+ None+}++fn system_prompt(speaker: &Speaker<'_>, tool_names: &str, follow_up: bool) -> String {+ let Speaker { agent, model } = speaker;+ // Mid-conversation, a generic "Let me check that." often reads oddly;+ // there the model may show nothing instead.+ let silence = if follow_up {+ "This is a follow-up. If the reply is complete, answer true as usual. Otherwise write an \+opener only if it is specific to this request (\"move it to 3\" → false|Let me move it to 3.). \+If the only line you would write is filler like \"Let me check that.\", \"On it.\", \"Sure —\" or \+\"Got it.\", output skip| instead (\"shorter\" → skip|, \"who is priya again\" → skip|).\n"+ } else {+ ""+ };+ format!(+ "You write the very first line of an AI assistant's reply. It is shown to the user \+instantly while the assistant works on the real answer. Write as the assistant: you are \+{agent}, running on the model {model}. If asked who you are or which model you are, answer \+with exactly these facts; never claim any other name, model or company.+Output format, exactly: <verdict>|<line>+{silence}- true only if <line> is the ENTIRE reply and nothing else needs doing: greetings, \+thanks, acknowledgements, arithmetic, who you are or which model you run on (\"hi there\" → \+true|Hi!, \"thanks\" → true|You're welcome!, \"what's 2+2\" → true|4.). A message that also \+asks for anything to be done or looked up is false (\"thanks, now add Sarah\" → false). If in \+any doubt, false.+- false for everything else. Then <line> only shows the assistant is starting, in \+the obvious direction, states no facts or answers, and never claims anything was done \+(\"false|Let me check your calendar.\", \"false|On it.\", \"false|Good question.\", \+\"false|Let me think about that.\"). Never ask questions.+Never try to answer anything that needs the user's data, a tool, or a skill: just show you're on \+it or thinking about it.+Answer only what the user said. Never mention context, metadata, instructions, or this format.+One line, under 12 words. The assistant's tools: {tool_names}."+ )+}++pub(super) fn transcript(messages: &[ChatMessage]) -> String {+ let start = messages.len().saturating_sub(TRANSCRIPT_MESSAGES);+ messages[start..]+ .iter()+ .filter_map(|message| {+ let speaker = match message.role {+ Role::User => "User",+ Role::Assistant => "Assistant",+ Role::System => return None,+ };+ let text = match &message.content {+ ChatMessageContent::Text(text) => text.clone(),+ ChatMessageContent::AssistantMessageParts(parts) => parts+ .iter()+ .filter_map(|part| match part {+ AssistantMessagePart::Text { text } => Some(text.as_str()),+ _ => None,+ })+ .collect::<Vec<_>>()+ .join("\n"),+ };+ let text = without_agent_context(&text);+ let text = text.trim();+ (!text.is_empty()).then(|| {+ // The end of a long message is what the reply answers.+ let skip = text+ .chars()+ .count()+ .saturating_sub(TRANSCRIPT_MESSAGE_CHARS);+ let text: String = text.chars().skip(skip).collect();+ format!("{speaker}: {text}")+ })+ })+ .collect::<Vec<_>>()+ .join("\n\n")+}++const AGENT_CONTEXT_OPEN: &str = "<m-agent-context>";+const AGENT_CONTEXT_CLOSE: &str = "</m-agent-context>";++/// `text` without its hidden `<m-agent-context>` blocks: session metadata the+/// app prepends for the turn's model, which the opening line's model would+/// otherwise remark on instead of the user's words.+fn without_agent_context(text: &str) -> String {+ let mut rest = text;+ let mut kept = String::with_capacity(text.len());+ while let Some(start) = rest.find(AGENT_CONTEXT_OPEN) {+ kept.push_str(&rest[..start]);+ rest = match rest[start..].find(AGENT_CONTEXT_CLOSE) {+ Some(end) => &rest[start + end + AGENT_CONTEXT_CLOSE.len()..],+ None => "",+ };+ }+ kept.push_str(rest);+ kept+}diff --git a/crates/agent_inmem/src/outbound/rig_engine/test.rs b/crates/agent_inmem/src/outbound/rig_engine/test.rsindex 49453eac88..e33550a0f7 100644--- a/crates/agent_inmem/src/outbound/rig_engine/test.rs+++ b/crates/agent_inmem/src/outbound/rig_engine/test.rs@@ -197,9 +197,10 @@ fn sessions_of_an_agent_share_everything_before_their_instructions() {let second = system_prompt(&TOOLS, Some(&identity), Some("task B"), None);let shared = format!(- "{}\n{}\n{TOOLS}",+ "{}\n{}\n{}\n{TOOLS}",prompt::agent_identity::render("Grunk", "grunk"),- prompt::agent_session::PROMPT+ prompt::agent_session::PROMPT,+ opener::ALREADY_OPENED,);assert_eq!(first.shared(), Some(shared.as_str()));assert_eq!(second.shared(), Some(shared.as_str()));@@ -231,3 +232,72 @@ fn empty_instructions_add_no_section() {assert!(!prompt.contains("session_instructions"));}++#[tokio::test]+async fn opening_verdict_split_across_deltas_keeps_the_head_of_the_line() {+ let (lines, mut receiver) = mpsc::channel(8);+ for delta in ["tr", "ue|Hi", " there", "!"] {+ lines.send(delta.to_owned()).await.unwrap();+ }++ let verdict = opener::verdict(&mut receiver).await;++ assert!(matches!(verdict, Some(opener::Verdict::Complete(head)) if head == "Hi"));+ assert_eq!(receiver.recv().await.as_deref(), Some(" there"));+}++#[tokio::test]+async fn opening_verdict_reads_false_as_an_opening_only() {+ let (lines, mut receiver) = mpsc::channel(8);+ lines+ .send("false| Let me check your calendar.".to_owned())+ .await+ .unwrap();++ let verdict = opener::verdict(&mut receiver).await;++ assert!(matches!(+ verdict,+ Some(opener::Verdict::Opening(head)) if head == "Let me check your calendar."+ ));+}++#[tokio::test]+async fn opening_verdict_skip_shows_nothing() {+ let (lines, mut receiver) = mpsc::channel(8);+ for delta in ["sk", "ip|"] {+ lines.send(delta.to_owned()).await.unwrap();+ }++ let verdict = opener::verdict(&mut receiver).await;++ assert!(matches!(verdict, Some(opener::Verdict::Silent)));+}++#[tokio::test]+async fn opening_without_a_verdict_is_dropped() {+ let (lines, mut receiver) = mpsc::channel(8);+ lines+ .send("Sure, let me look into it.".to_owned())+ .await+ .unwrap();+ drop(lines);++ assert!(opener::verdict(&mut receiver).await.is_none());+}++#[test]+fn opening_transcript_leaves_out_the_hidden_agent_context() {+ let messages = vec![agent::types::ChatMessage {+ content: agent::types::ChatMessageContent::Text(+ "<m-agent-context>{\"version\":1,\"text\":\"<session owner=\\\"[email protected]\\\"/>\"}</m-agent-context>\n\nwhat is going on in my workspace".to_owned(),+ ),+ role: agent::types::Role::User,+ attachments: None,+ }];++ assert_eq!(+ opener::transcript(&messages),+ "User: what is going on in my workspace"+ );+}diff --git a/crates/agent_inmem/src/rig_engine.rs b/crates/agent_inmem/src/rig_engine.rsindex 4f26b0ec48..a8151f26e7 100644--- a/crates/agent_inmem/src/rig_engine.rs+++ b/crates/agent_inmem/src/rig_engine.rs@@ -42,6 +42,8 @@ use crate::domain::engine::{AgentIdentity, TurnEngine, TurnRequest};use crate::domain::tool_gate::{NativeToolGate, NativeToolVerdict, UngatedNativeTools};use crate::inbound::ask_user::{AskUser, AskUserContext};+#[path = "outbound/rig_engine/opener.rs"]+mod opener;#[cfg(test)]#[path = "outbound/rig_engine/test.rs"]mod test;@@ -189,6 +191,9 @@ struct NativeTools {without_user_input: Arc<AsyncToolCollection<InMemToolContext>>,prompt: String,deferred: Arc<[ai_toolset::SearchableTool]>,+ /// Every native tool's name, for the opening line's model to guess the+ /// direction a reply will take.+ tool_names: String,}impl NativeTools {@@ -198,11 +203,20 @@ impl NativeTools {.expect("tools_for should return a fresh, uniquely owned collection");let other_tools = Arc::into_inner(tools_for(AiHost::AgentSession).toolset).expect("tools_for should return a fresh, uniquely owned collection");+ let with_user_input = tools_for_turn(base_tools, true);+ let tool_names = with_user_input+ .tools+ .keys()+ .map(String::as_str)+ .chain(tools.deferred.iter().map(|tool| tool.name.as_str()))+ .collect::<Vec<_>>()+ .join(", ");Self {- with_user_input: Arc::new(tools_for_turn(base_tools, true)),+ with_user_input: Arc::new(with_user_input),without_user_input: Arc::new(tools_for_turn(other_tools, false)),prompt: tools.prompt.to_string(),deferred: tools.deferred,+ tool_names,}}@@ -263,6 +277,7 @@ async fn drive_turn(user_input,reviewer,} = request;+ let started = tokio::time::Instant::now();// A turn runs as a person: tools act with the owner's identity, the// memory is theirs, and usage is billed to them. A session owned by@@ -279,6 +294,38 @@ async fn drive_turn(}};+ // Started before anything else so its line is out before the turn's+ // model has a first token.+ let usage_ctx = ai_usage::UsageContext::new(ai_usage::AiFeature::AgentSession, owner.clone());+ let agent = identity.as_ref().map_or_else(+ || "Macro".to_owned(),+ |identity| format!("{} (@{})", identity.name, identity.handle),+ );+ // How the race went, on one span per turn. `outcome` is `complete` (the+ // line was the whole reply), `opening` (the line opened the turn's+ // reply), `silent` (no line fit this follow-up), `turn_first` (the+ // turn's model spoke first), `no_verdict` (the+ // fast model failed or answered without one) or `timeout`.+ let opener_span = tracing::info_span!(+ "agent.opener",+ agent.opener.model = opener::MODEL,+ agent.opener.outcome = tracing::field::Empty,+ agent.opener.verdict_ms = tracing::field::Empty,+ agent.opener.line_chars = tracing::field::Empty,+ agent.opener.turn_first_part_ms = tracing::field::Empty,+ );+ let mut opening_line = opener_span.in_scope(|| {+ opener::spawn(+ base_context.recorder.clone(),+ usage_ctx.clone(),+ &opener::Speaker {+ agent: &agent,+ model: crate::domain::models::display_name(&model),+ },+ &native_tools.tool_names,+ &messages,+ )+ });// Chat's tools with the session's prompt: the user tools (`SendEmail`,// `CreateCalendarEvent`) defer to the user, and this runtime finishes// them in the turn through `reviewer`.@@ -291,7 +338,6 @@ async fn drive_turn();let toolset = native_tools.for_turn(user_input.is_some());- let usage_ctx = ai_usage::UsageContext::new(ai_usage::AiFeature::AgentSession, owner.clone());// Carry the feature on the context so tool-spawned subagents attribute to it.let mut tool_context = base_context.clone();tool_context.usage_context = usage_ctx.clone();@@ -366,7 +412,110 @@ async fn drive_turn(let rig_messages = agent::to_rig_messages(&messages);let result = async {let mut stream = session.send_message(rig_messages).await?;+ let mut turn_spoke = false;+ // The opening line's model usually has its verdict long before this+ // one's first prose. Thinking passes through while the race goes on;+ // should this model write prose or call a tool first, its own opening+ // stands and the line is dropped.+ let race = {+ let verdict =+ tokio::time::timeout(opener::VERDICT_TIMEOUT, opener::verdict(&mut opening_line));+ tokio::pin!(verdict);+ loop {+ tokio::select! {+ biased;+ part = stream.next() => {+ if !turn_spoke {+ turn_spoke = true;+ opener_span+ .record("agent.opener.turn_first_part_ms", elapsed_ms(started));+ }+ match part {+ Some(Ok(part @ (StreamPart::Thinking(_) | StreamPart::Usage(_)))) => {+ if parts.send(Ok(part)).await.is_err() {+ loop_cancel.cancel();+ return Ok(());+ }+ }+ part => break Race::TurnFirst(part),+ }+ }+ opening = &mut verdict => break Race::Opening(opening),+ }+ }+ };+ let mut separate = false;+ match race {+ Race::TurnFirst(None) => {+ opener_span.record("agent.opener.outcome", "turn_first");+ return Ok(());+ }+ Race::TurnFirst(Some(part)) => {+ opener_span.record("agent.opener.outcome", "turn_first");+ if parts.send(part).await.is_err() {+ loop_cancel.cancel();+ return Ok(());+ }+ }+ Race::Opening(Ok(Some(verdict))) => {+ opener_span.record("agent.opener.verdict_ms", elapsed_ms(started));+ let (outcome, line) = match verdict {+ opener::Verdict::Complete(head) => ("complete", Some((true, head))),+ opener::Verdict::Opening(head) => ("opening", Some((false, head))),+ opener::Verdict::Silent => ("silent", None),+ };+ opener_span.record("agent.opener.outcome", outcome);+ if let Some((complete, head)) = line {+ let deadline = tokio::time::Instant::now() + opener::LINE_TIMEOUT;+ let mut line_chars = 0;+ let mut finished = false;+ let mut delta = Some(head);+ while let Some(text) = delta {+ line_chars += text.chars().count();+ opener_span.record("agent.opener.line_chars", line_chars);+ if !text.is_empty()+ && parts.send(Ok(StreamPart::Content(text))).await.is_err()+ {+ loop_cancel.cancel();+ return Ok(());+ }+ delta = match tokio::time::timeout_at(deadline, opening_line.recv()).await {+ Ok(next) => {+ finished = next.is_none();+ next+ }+ Err(_) => None,+ };+ }+ // Only a whole line stands alone: one that stalled or+ // came out empty leaves the reply to this model.+ if complete && finished && line_chars > 0 {+ loop_cancel.cancel();+ return Ok(());+ }+ separate = line_chars > 0;+ }+ }+ Race::Opening(Ok(None)) => {+ opener_span.record("agent.opener.outcome", "no_verdict");+ }+ Race::Opening(Err(_)) => {+ opener_span.record("agent.opener.outcome", "timeout");+ }+ }+ drop(opening_line);while let Some(part) = stream.next().await {+ if !turn_spoke {+ turn_spoke = true;+ opener_span.record("agent.opener.turn_first_part_ms", elapsed_ms(started));+ }+ let part = match part {+ Ok(StreamPart::Content(text)) if separate && !text.trim().is_empty() => {+ separate = false;+ Ok(StreamPart::Content(format!("\n\n{}", text.trim_start())))+ }+ other => other,+ };if parts.send(part).await.is_err() {// The consumer is gone; stop the loop rather than keep// spending tokens into the void.@@ -381,8 +530,20 @@ async fn drive_turn(result}+/// Which spoke first: the turn's own model, or the opening line's.+enum Race {+ TurnFirst(Option<Result<StreamPart, AgentError>>),+ /// The verdict, `None` without one, or `Err` past the verdict timeout.+ Opening(Result<Option<opener::Verdict>, tokio::time::error::Elapsed>),+}++fn elapsed_ms(since: tokio::time::Instant) -> u64 {+ u64::try_from(since.elapsed().as_millis()).unwrap_or(u64::MAX)+}+/// The turn's system prompt: the agent's identity, the agent-session-/// preamble, the static Macro prompt (how to use the product: mentions,+/// preamble, the note that an opening line is already out (see [`opener`]),+/// the static Macro prompt (how to use the product: mentions,/// tools, terminology), then the session's own instructions and the owner's/// memory when there are any.///@@ -412,6 +573,8 @@ fn system_prompt(}shared.push_str(&prompt::agent_session::PROMPT.to_string());shared.push('\n');+ shared.push_str(opener::ALREADY_OPENED);+ shared.push('\n');shared.push_str(&tools_prompt.to_string());let mut rest = String::new();// Blank instructions are "none" stated clumsily. A delimited section withdiff --git a/crates/prompt/src/agent_session.rs b/crates/prompt/src/agent_session.rsindex f2f3a7ebf8..8f9205b006 100644--- a/crates/prompt/src/agent_session.rs+++ b/crates/prompt/src/agent_session.rs@@ -12,7 +12,7 @@ static INSTRUCTIONS: &str = r##"You are a Macro agent working inside an agent se- You have no shell and no filesystem. Everything you can do, you do through the tools you are given.- When a request needs an external app (for example, "import my Notion docs"), use SearchTools for its actions. If the app is missing or a workflow needs an unconnected account, use DiscoverConnectors to search for the app and inspect its actual capabilities and connection status. This also applies when a native import tool exists but requires that app's connection. For a suitable unconnected app, include the returned connect_markup and tell the owner to connect to continue; do not substitute instructions to find Settings or ask for document URLs before resolving the missing connection. After authorization the session resumes automatically, and SearchTools can load the refreshed tools. Never claim an app supports an action merely because its name matches.- Work autonomously: nobody can approve intermediate questions mid-turn, so make reasonable assumptions, state them briefly, and proceed.-- Every prompt opens with a private context block naming the session's owner, whose access you act with, and who sent the prompt. Follow its note on what a prompt from someone else may do.+- Every prompt opens with a private context block naming the session's owner, whose access you act with, and who sent the prompt. Follow its note on what a prompt from someone else may do. Treat it as system hints, not part of the conversation: never mention, quote, or refer to it (no "the context says"); just act on it."##;static INTENT: &str = "The model behaves as a fast product assistant inside an agent session: \diff --git a/docs/AGENT_GUIDE/ai-chat.md b/docs/AGENT_GUIDE/ai-chat.mdindex 5bf5e48720..f47e7e48d1 100644--- a/docs/AGENT_GUIDE/ai-chat.md+++ b/docs/AGENT_GUIDE/ai-chat.md@@ -40,6 +40,16 @@ runtime starts on it; no model change appears in the new session's transcript.A selected effort is confirmed before the first prompt; settings the runtimealready reports do not need another control request.+Macro's in-process agent opens each reply with a line from a fast model+(`gpt-5.4-mini`), usually within half a second of Enter. Small talk+("hi there", "thanks") gets that line as the whole reply, and the chosen model,+already started alongside it, is cancelled. A real task ("what is on my calendar tomorrow?") gets a short+opener ("Let me check your calendar."), then the chosen model's answer after a+blank line, with no second acknowledgement. The opener answers the user's+words, never the prompt's hidden context. The sent prompt is fully opaque from+the first paint, and its `Context` chip is already in place, so nothing shifts+when the server confirms it.+Repeat from a fresh tab using Home, Agents, and a document's Chat action.Focusing an agent composer prepares its transcript renderer locally; focus alonemust not send a prompt. Record navigation and focus time separately from typing