diff --git a/loop/loop.go b/loop/loop.go index e115287a2b97683e179ceb6791a4303d1714228c..6d46338d55de9c0540d209370895f3eb985de418 100644 --- a/loop/loop.go +++ b/loop/loop.go @@ -245,6 +245,7 @@ func (l *Loop) processLLMRequest(ctx context.Context) error { resp, err := llmService.Do(llmCtx, req) if err != nil { // Record the error as a message so it can be displayed in the UI + // EndOfTurn must be true so the agent working state is properly updated errorMessage := llm.Message{ Role: llm.MessageRoleAssistant, Content: []llm.Content{ @@ -253,6 +254,7 @@ func (l *Loop) processLLMRequest(ctx context.Context) error { Text: fmt.Sprintf("LLM request failed: %v", err), }, }, + EndOfTurn: true, } if recordErr := l.recordMessage(ctx, errorMessage, llm.Usage{}); recordErr != nil { l.logger.Error("failed to record error message", "error", recordErr) diff --git a/loop/loop_test.go b/loop/loop_test.go index c59f96f32160b451215b840ab5e20f3f6a2aec96..88d015447d6ac5c14fed23cc05efec4a9430c597 100644 --- a/loop/loop_test.go +++ b/loop/loop_test.go @@ -1548,6 +1548,11 @@ func TestProcessLLMRequestError(t *testing.T) { if !strings.Contains(recordedMessages[0].Content[0].Text, "LLM request failed") { t.Errorf("expected error message to contain 'LLM request failed', got: %s", recordedMessages[0].Content[0].Text) } + + // Verify EndOfTurn is set so the agent working state is properly updated + if !recordedMessages[0].EndOfTurn { + t.Error("expected error message to have EndOfTurn=true so agent working state is updated") + } } // errorLLMService is a test LLM service that always returns an error