Two interaction patterns let users send messages while the agent is already working: steering redirects the agent mid-turn, and queueing buffers messages for sequential processing after the current turn completes.
When a session is actively processing a turn, incoming messages can be delivered in one of two modes via the mode field on MessageOptions:
| Mode | Behavior | Use case |
|---|---|---|
"immediate" (steering) | Injected into the current LLM turn | "Actually, don't create that file—use a different approach" |
"enqueue" (queueing) | Queued and processed after the current turn finishes | "After this, also fix the tests" |
sequenceDiagram
participant U as User
participant S as Session
participant LLM as Agent
U->>S: send({ prompt: "Refactor auth" })
S->>LLM: Turn starts
Note over U,LLM: Agent is busy...
U->>S: send({ prompt: "Use JWT instead", mode: "immediate" })
S-->>LLM: Injected into current turn (steering)
U->>S: send({ prompt: "Then update the docs", mode: "enqueue" })
S-->>S: Queued for next turn
LLM->>S: Turn completes (incorporates steering)
S->>LLM: Processes queued message
LLM->>S: Turn completes
Set the optional source when forwarding a message from another agent. An identified agent source serializes as agent-<id>. Leave source unset for ordinary human sends to preserve runtime defaults. Both send and send-and-wait APIs support source with "enqueue" and "immediate" delivery.
| SDK | Identified agent source |
|---|---|
| Node.js / TypeScript | source: "agent-sender-id" |
| Python | source=AgentMessageSource("sender-id") |
| Go | Source: copilot.MessageSourceAgent("sender-id") |
| .NET | Source = MessageSource.Agent("sender-id") |
| Java | .setSource(MessageSource.agent("sender-id")) |
| Rust | .with_source(MessageSource::Agent("sender-id".into())) |
The typed APIs also support user and system. Use system for internal application context, not as a substitute for an identified agent. Agent provenance lets the runtime distinguish agent input from human authorization while retaining its agent-message steering behavior. Derive the sender ID from trusted application metadata, never from message text.
Use an automation source for a turn your application sends on behalf of an automation the user configured, such as a recurring check-in. It serializes as automation-<id>. An automation turn defines the session's task like a user message but carries no human authority. With Assisted Permissions in Autopilot, it starts a new permission-recovery epoch for automatic denials and gives the completion reviewer its task. The auto-approval judge never treats it as a person's instruction. Use a stable, non-empty automation name as the ID, because the runtime records the source as provenance and does not treat automation- alone as an automation turn.
| SDK | Automation source |
|---|---|
| Node.js / TypeScript | source: "automation-merge-check" |
| Python | source=AutomationMessageSource("merge-check") |
| Go | Source: copilot.MessageSourceAutomation("merge-check") |
| .NET | Source = MessageSource.Automation("merge-check") |
| Java | .setSource(MessageSource.automation("merge-check")) |
| Rust | .with_source(MessageSource::Automation("merge-check".into())) |
Source identifies origin. Delivery mode requests urgency. Neither requires the recipient to produce a visible reply, and source does not set billing flags. The runtime applies its existing scheduling rules. Rust callers using the typed RPC API can also pass MessageSource to rpc::SendRequest::with_source(...).
A successful high-level send acknowledgement returns a message ID and confirms acceptance, not that the recipient has consumed the message. Do not automatically resend an accepted message merely because no reply appears. Send-and-wait can complete on an idle event without an assistant message.
warning
Remote backends do not necessarily preserve source end to end. Mission Control can include source in its local echo without carrying it in the remote HTTP request. A local source event does not prove that the remote worker received the same provenance.
Steering sends a message that is injected directly into the agent's current turn. The agent sees the message in real time and adjusts its response accordingly—useful for course-correcting without aborting the turn.
import { CopilotClient } from "copilot-sdk-supercharged";
const client = new CopilotClient({ mode: "coding-agent" });
await client.start();
const session = await client.createSession({
model: "auto",
permissions: {
onRequest: async () => ({ kind: "approve-once" }),
},
});
// Start a long-running task
const msgId = await session.send({
prompt: "Refactor the authentication module to use sessions",
});
// While the agent is working, steer it
await session.send({
prompt: "Actually, use JWT tokens instead of sessions",
mode: "immediate",
});
from copilot import CopilotClient
from copilot.session import PermissionDecisionApproveOnce
async def main():
client = CopilotClient(mode="coding-agent")
await client.start()
session = await client.create_session(
model="auto",
permissions={"on_request": lambda req, inv: PermissionDecisionApproveOnce()},
)
# Start a long-running task
msg_id = await session.send(
"Refactor the authentication module to use sessions",
)
# While the agent is working, steer it
await session.send(
"Actually, use JWT tokens instead of sessions",
mode="immediate",
)
await client.stop()
package main
import (
"context"
copilot "github.com/microsoft/copilot-sdk/go/v2"
"github.com/microsoft/copilot-sdk/go/v2/rpc"
"log"
)
func main() {
ctx := context.Background()
client := copilot.NewClient(&copilot.ClientOptions{Mode: copilot.ModeCodingAgent})
if err := client.Start(ctx); err != nil {
log.Fatal(err)
}
defer client.Stop()
session, err := client.CreateSession(ctx, &copilot.CreateSessionOptions{
Model: "auto",
Permissions: copilot.SessionPermissionOptions{
OnRequest: func(req copilot.PermissionRequest, inv copilot.PermissionInvocation) (rpc.PermissionDecision, error) {
return &rpc.PermissionDecisionApproveOnce{}, nil
},
},
})
if err != nil {
log.Fatal(err)
}
// Start a long-running task
_, err = session.Send(ctx, copilot.MessageOptions{
Prompt: "Refactor the authentication module to use sessions",
})
if err != nil {
log.Fatal(err)
}
// While the agent is working, steer it
_, err = session.Send(ctx, copilot.MessageOptions{
Prompt: "Actually, use JWT tokens instead of sessions",
Mode: "immediate",
})
if err != nil {
log.Fatal(err)
}
}
#pragma warning disable MCPSDK001 // PermissionDecision is experimental.
using Microsoft.Copilot;
using Microsoft.Copilot.Rpc;
await using var client = new CopilotClient(new CopilotClientOptions { Mode = CopilotClientMode.CodingAgent });
await using var session = await client.CreateSessionAsync(new CreateSessionOptions
{
Model = "auto",
Permissions = new SessionPermissionOptions
{
OnRequest = (req, inv) => Task.FromResult(PermissionDecision.ApproveOnce())
}
});
// Start a long-running task
var msgId = await session.SendAsync(new MessageOptions
{
Prompt = "Refactor the authentication module to use sessions"
});
// While the agent is working, steer it
await session.SendAsync(new MessageOptions
{
Prompt = "Actually, use JWT tokens instead of sessions",
Mode = "immediate"
});
import com.microsoft.copilot.CopilotClient;
import com.microsoft.copilot.rpc.*;
try (var client = new CopilotClient(new CopilotClientOptions().setMode(CopilotClientMode.CODING_AGENT))) {
client
.start()
.get();
var session = client
.createSession(new CreateSessionOptions()
.setModel("auto")
.setPermissions(new SessionPermissionOptions()
.setOnRequest(PermissionHandler.APPROVE_ALL)))
.get();
// Start a long-running task
session
.send(new MessageOptions()
.setPrompt("Refactor the authentication module to use sessions"))
.get();
// While the agent is working, steer it
session
.send(new MessageOptions()
.setPrompt("Actually, use JWT tokens instead of sessions")
.setMode("immediate"))
.get();
}
note
Steering messages are best-effort within the current turn. If the agent has already committed to a tool call, the steering takes effect after that call completes but still within the same turn.
Queueing buffers messages to be processed sequentially after the current turn finishes. Each queued message starts its own full turn. This is the default mode: a message sent without mode is queued the same way while a turn is running. The two differ after a turn ends while a background agent is still running: a single message sent without mode starts a new turn right away, but a message sent with mode: "enqueue" waits until the background agents finish.
import { CopilotClient } from "copilot-sdk-supercharged";
const client = new CopilotClient({ mode: "coding-agent" });
await client.start();
const session = await client.createSession({
model: "auto",
permissions: {
onRequest: async () => ({ kind: "approve-once" }),
},
});
// Send an initial task
await session.send({ prompt: "Set up the project structure" });
// Queue follow-up tasks while the agent is busy
await session.send({
prompt: "Add unit tests for the auth module",
mode: "enqueue",
});
await session.send({
prompt: "Update the README with setup instructions",
mode: "enqueue",
});
// Messages are processed in FIFO order after each turn completes
from copilot import CopilotClient
from copilot.session import PermissionDecisionApproveOnce
async def main():
client = CopilotClient(mode="coding-agent")
await client.start()
session = await client.create_session(
model="auto",
permissions={"on_request": lambda req, inv: PermissionDecisionApproveOnce()},
)
# Send an initial task
await session.send("Set up the project structure")
# Queue follow-up tasks while the agent is busy
await session.send(
"Add unit tests for the auth module",
mode="enqueue",
)
await session.send(
"Update the README with setup instructions",
mode="enqueue",
)
# Messages are processed in FIFO order after each turn completes
await client.stop()
package main
import (
"context"
copilot "github.com/microsoft/copilot-sdk/go/v2"
"github.com/microsoft/copilot-sdk/go/v2/rpc"
)
func main() {
ctx := context.Background()
client := copilot.NewClient(&copilot.ClientOptions{Mode: copilot.ModeCodingAgent})
client.Start(ctx)
session, _ := client.CreateSession(ctx, &copilot.CreateSessionOptions{
Model: "auto",
Permissions: copilot.SessionPermissionOptions{
OnRequest: func(req copilot.PermissionRequest, inv copilot.PermissionInvocation) (rpc.PermissionDecision, error) {
return &rpc.PermissionDecisionApproveOnce{}, nil
},
},
})
session.Send(ctx, copilot.MessageOptions{
Prompt: "Set up the project structure",
})
session.Send(ctx, copilot.MessageOptions{
Prompt: "Add unit tests for the auth module",
Mode: "enqueue",
})
session.Send(ctx, copilot.MessageOptions{
Prompt: "Update the README with setup instructions",
Mode: "enqueue",
})
}
// Send an initial task
session.Send(ctx, copilot.MessageOptions{
Prompt: "Set up the project structure",
})
// Queue follow-up tasks while the agent is busy
session.Send(ctx, copilot.MessageOptions{
Prompt: "Add unit tests for the auth module",
Mode: "enqueue",
})
session.Send(ctx, copilot.MessageOptions{
Prompt: "Update the README with setup instructions",
Mode: "enqueue",
})
// Messages are processed in FIFO order after each turn completes
// Send an initial task
await session.SendAsync(new MessageOptions
{
Prompt = "Set up the project structure"
});
// Queue follow-up tasks while the agent is busy
await session.SendAsync(new MessageOptions
{
Prompt = "Add unit tests for the auth module",
Mode = "enqueue"
});
await session.SendAsync(new MessageOptions
{
Prompt = "Update the README with setup instructions",
Mode = "enqueue"
});
// Messages are processed in FIFO order after each turn completes
import com.microsoft.copilot.CopilotClient;
import com.microsoft.copilot.rpc.*;
try (var client = new CopilotClient(new CopilotClientOptions().setMode(CopilotClientMode.CODING_AGENT))) {
client
.start()
.get();
var session = client
.createSession(new CreateSessionOptions()
.setModel("auto")
.setPermissions(new SessionPermissionOptions()
.setOnRequest(PermissionHandler.APPROVE_ALL)))
.get();
// Send an initial task
session
.send(new MessageOptions()
.setPrompt("Set up the project structure"))
.get();
// Queue follow-up tasks while the agent is busy
session
.send(new MessageOptions()
.setPrompt("Add unit tests for the auth module")
.setMode("enqueue"))
.get();
session
.send(new MessageOptions()
.setPrompt("Update the README with setup instructions")
.setMode("enqueue"))
.get();
// Messages are processed in FIFO order after each turn completes
}
You can use both patterns together in a single session. Steering affects the current turn while queued messages wait for their own turns:
const session = await client.createSession({
model: "auto",
permissions: {
onRequest: async () => ({ kind: "approve-once" }),
},
});
// Start a task
await session.send({ prompt: "Refactor the database layer" });
// Steer the current work
await session.send({
prompt: "Make sure to keep backwards compatibility with the v1 API",
mode: "immediate",
});
// Queue a follow-up for after this turn
await session.send({
prompt: "Now add migration scripts for the schema changes",
mode: "enqueue",
});
from copilot import CopilotClient
from copilot.session import PermissionDecisionApproveOnce
client = CopilotClient(mode="coding-agent")
session = await client.create_session(
model="auto",
permissions={"on_request": lambda req, inv: PermissionDecisionApproveOnce()},
)
# Start a task
await session.send("Refactor the database layer")
# Steer the current work
await session.send(
"Make sure to keep backwards compatibility with the v1 API",
mode="immediate",
)
# Queue a follow-up for after this turn
await session.send(
"Now add migration scripts for the schema changes",
mode="enqueue",
)
| Scenario | Pattern | Why |
|---|---|---|
| Agent is going down the wrong path | Steering | Redirects the current turn without losing progress |
| You thought of something the agent should also do | Queueing | Doesn't disrupt current work; runs next |
| Agent is about to make a mistake | Steering | Intervenes before the mistake is committed |
| You want to chain multiple tasks | Queueing | FIFO ordering ensures predictable execution |
| You want to add context to the current task | Steering | Agent incorporates it into its current reasoning |
| You want to batch unrelated requests | Queueing | Each gets its own full turn with clean context |
Here's a pattern for building an interactive UI that supports both modes:
import { CopilotClient, CopilotSession } from "copilot-sdk-supercharged";
interface PendingMessage {
prompt: string;
mode: "immediate" | "enqueue";
sentAt: Date;
}
class InteractiveChat {
private session: CopilotSession;
private isProcessing = false;
private pendingMessages: PendingMessage[] = [];
constructor(session: CopilotSession) {
this.session = session;
session.on((event) => {
if (event.type === "session.idle") {
this.isProcessing = false;
this.onIdle();
}
if (event.type === "assistant.message") {
this.renderMessage(event);
}
});
}
async sendMessage(prompt: string): Promise<void> {
if (!this.isProcessing) {
this.isProcessing = true;
await this.session.send({ prompt });
return;
}
// Session is busy — let the user choose how to deliver
// Your UI would present this choice (e.g., buttons, keyboard shortcuts)
}
async steer(prompt: string): Promise<void> {
this.pendingMessages.push({
prompt,
mode: "immediate",
sentAt: new Date(),
});
await this.session.send({ prompt, mode: "immediate" });
}
async enqueue(prompt: string): Promise<void> {
this.pendingMessages.push({
prompt,
mode: "enqueue",
sentAt: new Date(),
});
await this.session.send({ prompt, mode: "enqueue" });
}
private onIdle(): void {
this.pendingMessages = [];
// Update UI to show session is ready for new input
}
private renderMessage(event: unknown): void {
// Render assistant message in your UI
}
}
| Language | Field | Type | Default | Description |
|---|---|---|---|---|
| Node.js | mode | "enqueue" \| "immediate" | "enqueue" | Message delivery mode |
| Python | mode | Literal["enqueue", "immediate"] | "enqueue" | Message delivery mode |
| Go | Mode | string | "enqueue" | Message delivery mode |
| .NET | Mode | string? | "enqueue" | Message delivery mode |
| Mode | Effect | During active turn | During idle |
|---|---|---|---|
"enqueue" | Queue for next turn | Waits in FIFO queue | Starts a new turn immediately |
"immediate" | Inject into current turn | Injected before next LLM call | Starts a new turn immediately |
note
When the session is idle (not processing), both modes behave identically—the message starts a new turn immediately. If a turn has ended but a background agent is still running, "immediate" (and a single message sent without mode) starts a new turn immediately, while "enqueue" waits until the background agents finish.
Default to queueing—Use "enqueue" (or omit mode) for most messages. It's predictable and doesn't risk disrupting in-progress work.
Reserve steering for corrections—Use "immediate" when the agent is actively doing the wrong thing and you need to redirect it before it goes further.
Keep steering messages concise—The agent needs to quickly understand the course correction. Long, complex steering messages may confuse the current context.
Don't over-steer—Multiple rapid steering messages can degrade turn quality. If you need to change direction significantly, consider aborting the turn and starting fresh.
Show queue state in your UI—Display the number of queued messages so users know what's pending. Listen for idle events to clear the display.
Handle the steering-to-queue fallback—If a steering message arrives after the turn completes, it's automatically moved to the queue. Design your UI to reflect this transition.
Can you improve this documentation? These fine people already did:
copilot-cli-release-app[bot], Steve Sanderson, Stephen Toub, Brett Cannon, copilot-sdk-mirror-writer[bot], Antonio Goncalves, Jeremiah Isaacson, Sunbrye Ly, Patrick Nikoletich, Ed Burns, Bruno Borges & AuroEdit on GitHub
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |