fix(coding-agent): refresh session state before next turn

This commit is contained in:
Mat
2026-06-30 13:56:04 +02:00
committed by GitHub
parent 9be55bc773
commit e547bb9f41
3 changed files with 94 additions and 1 deletions
@@ -352,6 +352,7 @@ export class AgentSession {
// (session persistence, extensions, auto-compaction, retry logic)
this._unsubscribeAgent = this.agent.subscribe(this._handleAgentEvent);
this._installAgentToolHooks();
this._installAgentNextTurnRefresh();
this._buildRuntime({
activeToolNames: this._initialActiveToolNames,
@@ -462,6 +463,25 @@ export class AgentSession {
};
}
private _installAgentNextTurnRefresh(): void {
const previousPrepareNextTurn = this.agent.prepareNextTurn;
this.agent.prepareNextTurn = async (turn, signal) => {
const previousSnapshot = await previousPrepareNextTurn?.(turn, signal);
const previousContext = previousSnapshot?.context ?? turn.context;
return {
...previousSnapshot,
context: {
...previousContext,
systemPrompt: this.agent.state.systemPrompt,
tools: this.agent.state.tools.slice(),
},
model: this.agent.state.model,
thinkingLevel: this.agent.state.thinkingLevel,
};
};
}
// =========================================================================
// Event Subscription
// =========================================================================