fix: save placeholder message when task is cancelled
When user cancels a task with /stop, the user message was saved but the assistant response was not, causing orphaned user messages in session history. Now saves '[Task cancelled by user]' placeholder to keep conversation history complete.
This commit is contained in:
parent
af2862b561
commit
270814c3c9
1 changed files with 6 additions and 0 deletions
|
|
@ -846,6 +846,12 @@ func (al *AgentLoop) runAgentLoop(
|
|||
// 3. Run LLM iteration loop
|
||||
finalContent, iteration, err := al.runLLMIteration(ctx, agent, messages, opts)
|
||||
if err != nil {
|
||||
// If task was cancelled, save a placeholder message to session
|
||||
// This prevents the user message from being orphaned without a response
|
||||
if errors.Is(err, context.Canceled) {
|
||||
agent.Sessions.AddMessage(opts.SessionKey, "assistant", "[Task cancelled by user]")
|
||||
agent.Sessions.Save(opts.SessionKey)
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue