refactor(runtime): remove nil checks for receiver in RuntimeTraceCollector methods

refactor(factory): enforce skill middleware requirement in NewAgentHandlerService
refactor(reply_interrupt): improve error handling for pending interrupts
This commit is contained in:
mlogclub
2026-04-19 11:40:17 +08:00
parent 3e98e9379c
commit 700ec2a38b
6 changed files with 23 additions and 57 deletions
@@ -55,7 +55,7 @@ func NewAgentFactory() *AgentFactory {
chatModelFactory: NewChatModelFactory(),
toolFactory: NewToolFactory(),
instructionService: instruction.NewService(nil, nil, nil),
handlerService: NewAgentHandlerService(nil),
handlerService: NewAgentHandlerService(NewSkillMiddlewareService()),
}
}
@@ -73,21 +73,19 @@ func (f *AgentFactory) BuildCustomerServiceAgent(ctx context.Context, input Buil
allTools = append(allTools, input.StaticTools...)
instructionResult := f.instructionService.Build(input.AIAgent, nil, input.InstructionToolDefinitions, input.StaticToolCodes)
handlers := make([]adk.ChatModelAgentMiddleware, 0, 3)
if f.handlerService != nil {
builtHandlers, err := f.handlerService.Build(ctx, BuildAgentHandlersInput{
AIAgent: input.AIAgent,
InstructionToolDefinitions: input.InstructionToolDefinitions,
DynamicToolDefinitions: input.DynamicMCPToolDefinitions,
DynamicTools: dynamicTools,
StaticToolMetadata: input.StaticToolMetadata,
Collector: input.Collector,
InstructionSummary: buildInstructionTraceSummary(instructionResult.Summary),
})
if err != nil {
return nil, err
}
handlers = append(handlers, builtHandlers...)
builtHandlers, err := f.handlerService.Build(ctx, BuildAgentHandlersInput{
AIAgent: input.AIAgent,
InstructionToolDefinitions: input.InstructionToolDefinitions,
DynamicToolDefinitions: input.DynamicMCPToolDefinitions,
DynamicTools: dynamicTools,
StaticToolMetadata: input.StaticToolMetadata,
Collector: input.Collector,
InstructionSummary: buildInstructionTraceSummary(instructionResult.Summary),
})
if err != nil {
return nil, err
}
handlers = append(handlers, builtHandlers...)
inner, err := adk.NewChatModelAgent(ctx, &adk.ChatModelAgentConfig{
Name: strings.TrimSpace(input.AIAgent.Name),
Description: strings.TrimSpace(input.AIAgent.Description),
@@ -31,7 +31,7 @@ type BuildAgentHandlersInput struct {
func NewAgentHandlerService(skillMiddleware *SkillMiddlewareService) *AgentHandlerService {
if skillMiddleware == nil {
skillMiddleware = NewSkillMiddlewareService()
panic("skill middleware is required")
}
return &AgentHandlerService{skillMiddleware: skillMiddleware}
}
@@ -9,7 +9,7 @@ import (
func TestAgentHandlerServiceBuildWithCollectorOnly(t *testing.T) {
collector := einocallbacks.NewRuntimeTraceCollector()
service := NewAgentHandlerService(nil)
service := NewAgentHandlerService(NewSkillMiddlewareService())
handlers, err := service.Build(context.Background(), BuildAgentHandlersInput{
Collector: collector,
@@ -33,7 +33,7 @@ func TestAgentHandlerServiceBuildWithCollectorOnly(t *testing.T) {
}
func TestAgentHandlerServiceBuildWithEmptyInput(t *testing.T) {
service := NewAgentHandlerService(nil)
service := NewAgentHandlerService(NewSkillMiddlewareService())
handlers, err := service.Build(context.Background(), BuildAgentHandlersInput{})
if err != nil {