Refactor buildStandardResponse to Handle NextResponse More Safely

- Updated the buildStandardResponse method to assign the NextResponse to a variable only if it is not nil, improving code clarity and preventing potential nil pointer dereferences.
- This change enhances the robustness of the response building process in the Assistant's delegation handling.
This commit is contained in:
Max 2025-12-28 10:49:38 +08:00
parent 88aca7cef0
commit b61f0130e6

View file

@ -65,6 +65,12 @@ func (ast *Assistant) handleDelegation(
// buildStandardResponse builds the standard agent response when no custom Next hook processing is needed
func (ast *Assistant) buildStandardResponse(npc *NextProcessContext) *agentContext.Response {
var next interface{} = nil;
if npc.NextResponse != nil {
next = npc.NextResponse
}
return &agentContext.Response{
ContextID: npc.Context.ID,
RequestID: npc.Context.RequestID(),
@ -72,7 +78,7 @@ func (ast *Assistant) buildStandardResponse(npc *NextProcessContext) *agentConte
ChatID: npc.Context.ChatID,
AssistantID: ast.ID,
Create: npc.CreateResponse,
Next: npc.NextResponse,
Next: next,
Completion: npc.CompletionResponse,
Tools: npc.ToolCallResponses,
}