Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(agents): open mentioned agents with their configured instructions (#6998)

Eric Hayesf0f80152b9fa
diff --git a/crates/agent_harness/src/domain/model.rs b/crates/agent_harness/src/domain/model.rs
index 2006d4feac..8c996cfe87 100644
--- a/crates/agent_harness/src/domain/model.rs
+++ b/crates/agent_harness/src/domain/model.rs
@@ -116,8 +116,9 @@ pub struct OpenSession {
/// session so resume and teardown keep routing correctly after a restart.
///
/// A session's instructions are stored on its row whichever kind serves it,
-/// but only [`Self::InMemory`] reads them today - it builds its system prompt
-/// in this process, so there is nothing to transport. The rest need one, and
+/// but only [`Self::InMemory`] and [`Self::ClaudeCloud`] read them today -
+/// the first builds its system prompt in this process, the second passes
+/// them to Claude at create. The rest need a transport, and
/// ACP supplies none: `session/new` carries a working directory, MCP servers
/// and `_meta`, and nothing else. [`Self::SandboxedCoder`] will get a
/// per-session file listed alongside `SYSTEM.md` in `container/opencode.json`,
@@ -329,7 +330,8 @@ pub struct AgentRuntimeConfig {
pub model: String,
/// Harness slug stamped onto the new session.
pub harness: String,
- /// Configured agent instructions, reserved for a dedicated runtime transport.
+ /// Configured agent instructions, snapshotted onto each new session's row
+ /// so a mention opens with the same system prompt the create menu does.
pub instructions: String,
/// Which Pipedream MCP servers the agent's sessions are handed.
pub mcp_servers: AgentMcpServers,
diff --git a/crates/agent_harness/src/domain/service/open.rs b/crates/agent_harness/src/domain/service/open.rs
index 09f1e69a72..858c009240 100644
--- a/crates/agent_harness/src/domain/service/open.rs
+++ b/crates/agent_harness/src/domain/service/open.rs
@@ -486,6 +486,12 @@ where
let defaults = self.defaults.for_bot(bot_id);
let sandbox_size = self.sessions.user_sandbox_size(&origin.sender).await?;
+ // The same profile the create menu snapshots: a mention states nothing
+ // about how the runtime should work, so the bot's configured
+ // instructions are what it opens with, exactly as a dedicated session
+ // would. Blank instructions are "none" stated clumsily.
+ let instructions =
+ Some(runtime.instructions.clone()).filter(|text| !text.trim().is_empty());
// Provisioned before the session exists, because the row is what makes
// the token mean anything: it carries the hash the proxy recognises.
@@ -519,10 +525,7 @@ where
// Managed sandboxes run in the path baked into their image.
workspace: agent_session::MANAGED_CONTAINER_WORKSPACE.to_owned(),
sandbox_size,
- // A mention carries no instructions: the prompt is whatever
- // was said in the channel, and nothing there states how the
- // runtime should work.
- instructions: None,
+ instructions,
// Snapshotted so the proxy enforces exactly what this attach
// advertised, for as long as the session lives.
mcp_servers: runtime.mcp_servers.clone(),
diff --git a/crates/agent_harness/src/domain/service/test.rs b/crates/agent_harness/src/domain/service/test.rs
index ac28424752..12b0f458fc 100644
--- a/crates/agent_harness/src/domain/service/test.rs
+++ b/crates/agent_harness/src/domain/service/test.rs
@@ -933,6 +933,9 @@ async fn composer_failure_stops_open_delivery_and_keeps_the_prompt_queued() {
));
}
+/// The agent's instructions are its system prompt, and the runtime reads
+/// them off the session row - so a mention snapshots them there, the same as
+/// the create menu does, and never folds them into the prompt body.
#[tokio::test]
async fn open_sends_context_but_not_agent_instructions_to_the_agent_prompt() {
let context = ConversationContext {
@@ -950,7 +953,7 @@ async fn open_sends_context_but_not_agent_instructions_to_the_agent_prompt() {
..ConversationContext::default()
};
let composer = PromptComposerMock::default();
- let (service, _repo, containers, announcer, _runtimes) = harness_with_edges(
+ let (service, repo, containers, announcer, _runtimes) = harness_with_edges(
PromptContextMock::with_context(context.clone()),
composer.clone(),
);
@@ -980,6 +983,35 @@ async fn open_sends_context_but_not_agent_instructions_to_the_agent_prompt() {
prompts(&container.agent()),
[vec![ContentBlock::from(context_prompt(&raw))]]
);
+ let session = repo.get(id).await.expect("the session row exists");
+ assert_eq!(session.instructions.as_deref(), Some("Diagnose first."));
+}
+
+/// A bot configured with no instructions opens with none: whitespace is not
+/// a system prompt, and the row says so the same way the create menu's does.
+#[tokio::test]
+async fn open_stores_no_instructions_when_the_agent_has_only_blank_ones() {
+ let (service, repo, containers, _announcer, _runtimes) = harness();
+ let mut command = open_command();
+ command.runtime.instructions = " \n".to_owned();
+ let id = AgentSessionId::new();
+
+ let open = service.execute(id, HarnessCommand::Open(command));
+ let drive = async {
+ loop {
+ if containers.spawned() == 1 {
+ break;
+ }
+ tokio::task::yield_now().await;
+ }
+ let container = containers.container(id).unwrap();
+ complete_handshake(&container).await;
+ };
+ let (result, ()) = tokio::join!(open, drive);
+ result.unwrap();
+
+ let session = repo.get(id).await.expect("the session row exists");
+ assert_eq!(session.instructions, None);
}
/// A mention in a document comment: the agent is told which mark the comment