fix(agent): prevent empty response when no Knowledge Base is configured
- guard against empty content completion in analyzeResponse/executeLoop with retry (max 2), nudge message, and fallback response - propagate actual finish_reason through streaming pipeline instead of hardcoding "stop" in streamThinkingToEventBus - add FinishReason field to StreamResponse and streamLLMResult - add finish marker chunk in processStreamDelta for empty content scenarios - propagate lastFinishReason through EOF handler in processStream - strengthen PureAgent system prompt with MCP tool guidelines and graceful fallback instructions for unanswerable questions - add unit tests for empty response bug and finish_reason propagation
This commit is contained in:
@@ -51,9 +51,10 @@ func (e *AgentEngine) manageContextWindow(ctx context.Context, messages []chat.M
|
||||
// responseVerdict captures the result of analyzing an LLM response to determine
|
||||
// whether the agent loop should stop and what the final answer is (if any).
|
||||
type responseVerdict struct {
|
||||
isDone bool
|
||||
finalAnswer string
|
||||
step types.AgentStep
|
||||
isDone bool
|
||||
finalAnswer string
|
||||
emptyContent bool // LLM returned stop with no tool calls and empty content
|
||||
step types.AgentStep
|
||||
}
|
||||
|
||||
// analyzeResponse inspects the LLM response for stop conditions:
|
||||
@@ -102,9 +103,10 @@ func (e *AgentEngine) analyzeResponse(
|
||||
})
|
||||
|
||||
return responseVerdict{
|
||||
isDone: true,
|
||||
finalAnswer: response.Content,
|
||||
step: step,
|
||||
isDone: true,
|
||||
finalAnswer: response.Content,
|
||||
emptyContent: response.Content == "",
|
||||
step: step,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user