Remove emitLastMessage from continue(), use prompt(AppMessage) instead

Cleans up the temporary emitLastMessage plumbing since we now use
Agent.prompt(AppMessage) for hook messages instead of appendMessage+continue.

- Remove emitLastMessage parameter from Agent.continue()
- Remove from transport interface and implementations
- Remove from agentLoopContinue()
This commit is contained in:
Mario Zechner 2025-12-27 01:58:58 +01:00
parent a6322fda59
commit c1b4d043a8
5 changed files with 10 additions and 27 deletions

View file

@ -216,12 +216,7 @@ export class Agent {
* Continue from the current context without adding a new user message.
* Used for retry after overflow recovery when context already has user message or tool results.
*/
/**
* Continue from the current context without adding a new user message.
* Used for retry after overflow recovery when context already has user message or tool results.
* @param emitLastMessage If true, emit message_start/message_end for the last message
*/
async continue(emitLastMessage?: boolean) {
async continue() {
const messages = this._state.messages;
if (messages.length === 0) {
throw new Error("No messages to continue from");
@ -232,7 +227,7 @@ export class Agent {
throw new Error(`Cannot continue from message role: ${lastMessage.role}`);
}
await this._runAgentLoopContinue(emitLastMessage);
await this._runAgentLoopContinue();
}
/**
@ -249,10 +244,10 @@ export class Agent {
/**
* Internal: Continue the agent loop from current context.
*/
private async _runAgentLoopContinue(emitLastMessage?: boolean) {
private async _runAgentLoopContinue() {
const { llmMessages, cfg } = await this._prepareRun();
const events = this.transport.continue(llmMessages, cfg, this.abortController!.signal, emitLastMessage);
const events = this.transport.continue(llmMessages, cfg, this.abortController!.signal);
await this._processEvents(events);
}

View file

@ -380,7 +380,7 @@ export class AppTransport implements AgentTransport {
}
}
async *continue(messages: Message[], cfg: AgentRunConfig, signal?: AbortSignal, emitLastMessage?: boolean) {
async *continue(messages: Message[], cfg: AgentRunConfig, signal?: AbortSignal) {
const authToken = await this.options.getAuthToken();
if (!authToken) {
throw new Error("Auth token is required for AppTransport");
@ -390,7 +390,7 @@ export class AppTransport implements AgentTransport {
const context = this.buildContext(messages, cfg);
const pc = this.buildLoopConfig(cfg);
for await (const ev of agentLoopContinue(context, pc, signal, streamFn as any, emitLastMessage)) {
for await (const ev of agentLoopContinue(context, pc, signal, streamFn as any)) {
yield ev;
}
}

View file

@ -73,12 +73,12 @@ export class ProviderTransport implements AgentTransport {
}
}
async *continue(messages: Message[], cfg: AgentRunConfig, signal?: AbortSignal, emitLastMessage?: boolean) {
async *continue(messages: Message[], cfg: AgentRunConfig, signal?: AbortSignal) {
const model = this.getModel(cfg);
const context = this.buildContext(messages, cfg);
const pc = this.buildLoopConfig(model, cfg);
for await (const ev of agentLoopContinue(context, pc, signal, undefined, emitLastMessage)) {
for await (const ev of agentLoopContinue(context, pc, signal)) {
yield ev;
}
}

View file

@ -28,10 +28,5 @@ export interface AgentTransport {
): AsyncIterable<AgentEvent>;
/** Continue from current context (no new user message) */
continue(
messages: Message[],
config: AgentRunConfig,
signal?: AbortSignal,
emitLastMessage?: boolean,
): AsyncIterable<AgentEvent>;
continue(messages: Message[], config: AgentRunConfig, signal?: AbortSignal): AsyncIterable<AgentEvent>;
}

View file

@ -44,14 +44,12 @@ export function agentLoop(
* Continue an agent loop from the current context without adding a new message.
* Used for retry after overflow - context already has user message or tool results.
* Throws if the last message is not a user message or tool result.
* @param emitLastMessage If true, emit message_start/message_end for the last message in context
*/
export function agentLoopContinue(
context: AgentContext,
config: AgentLoopConfig,
signal?: AbortSignal,
streamFn?: typeof streamSimple,
emitLastMessage?: boolean,
): EventStream<AgentEvent, AgentContext["messages"]> {
// Validate that we can continue from this context
const lastMessage = context.messages[context.messages.length - 1];
@ -70,12 +68,7 @@ export function agentLoopContinue(
stream.push({ type: "agent_start" });
stream.push({ type: "turn_start" });
// Optionally emit events for the last message (used when message was added outside the loop)
if (emitLastMessage) {
stream.push({ type: "message_start", message: lastMessage });
stream.push({ type: "message_end", message: lastMessage });
}
// No user message events - we're continuing from existing context
await runLoop(currentContext, newMessages, config, signal, stream, streamFn);
})();