refactor: remove trace data from reply context and related services
This commit is contained in:
@@ -2,10 +2,8 @@ package runtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
applicationruntime "agent-desk/internal/ai/application/runtime"
|
||||
"agent-desk/internal/ai/runtime/graphs"
|
||||
@@ -19,7 +17,6 @@ type runtimeReplyRunInput struct {
|
||||
Conversation models.Conversation
|
||||
Message models.Message
|
||||
AIAgent models.AIAgent
|
||||
Trace *aiReplyTraceData
|
||||
}
|
||||
|
||||
type runtimeReplyResumeInput struct {
|
||||
@@ -27,7 +24,6 @@ type runtimeReplyResumeInput struct {
|
||||
Message models.Message
|
||||
AIAgent models.AIAgent
|
||||
PendingInterrupt *models.ConversationInterrupt
|
||||
Trace *aiReplyTraceData
|
||||
}
|
||||
|
||||
func newRuntimeReplyExecutor() *runtimeReplyExecutor {
|
||||
@@ -39,17 +35,12 @@ func (e *runtimeReplyExecutor) Run(ctx context.Context, input runtimeReplyRunInp
|
||||
if aiConfig == nil {
|
||||
return nil, fmt.Errorf("ai config is nil")
|
||||
}
|
||||
runtimeStartedAt := time.Now()
|
||||
summary, err := Service.Run(ctx, applicationruntime.Request{
|
||||
Conversation: input.Conversation,
|
||||
UserMessage: input.Message,
|
||||
AIAgent: input.AIAgent,
|
||||
AIConfig: *aiConfig,
|
||||
})
|
||||
if input.Trace != nil {
|
||||
input.Trace.RuntimeLatencyMs = time.Since(runtimeStartedAt).Milliseconds()
|
||||
e.fillTraceFromSummary(input.Trace, summary, err)
|
||||
}
|
||||
return summary, err
|
||||
}
|
||||
|
||||
@@ -61,10 +52,6 @@ func (e *runtimeReplyExecutor) ResumePendingInterrupt(ctx context.Context, input
|
||||
if aiConfig == nil {
|
||||
return nil, fmt.Errorf("ai config is nil")
|
||||
}
|
||||
runtimeStartedAt := time.Now()
|
||||
if input.Trace != nil {
|
||||
input.Trace.ResumeSource = "pending_interrupt"
|
||||
}
|
||||
summary, err := Service.Resume(ctx, applicationruntime.ResumeRequest{
|
||||
Conversation: input.Conversation,
|
||||
UserMessage: input.Message,
|
||||
@@ -75,32 +62,9 @@ func (e *runtimeReplyExecutor) ResumePendingInterrupt(ctx context.Context, input
|
||||
strings.TrimSpace(input.PendingInterrupt.InterruptID): strings.TrimSpace(input.Message.Content),
|
||||
},
|
||||
})
|
||||
if input.Trace != nil {
|
||||
input.Trace.RuntimeLatencyMs = time.Since(runtimeStartedAt).Milliseconds()
|
||||
e.fillTraceFromSummary(input.Trace, summary, err)
|
||||
}
|
||||
return summary, err
|
||||
}
|
||||
|
||||
func (e *runtimeReplyExecutor) fillTraceFromSummary(trace *aiReplyTraceData, summary *applicationruntime.Summary, runErr error) {
|
||||
if trace == nil {
|
||||
return
|
||||
}
|
||||
if runErr != nil {
|
||||
trace.Status = "runtime_error"
|
||||
trace.FinalAction = "error"
|
||||
if summary != nil {
|
||||
trace.Runtime = json.RawMessage(summary.TraceData)
|
||||
}
|
||||
return
|
||||
}
|
||||
trace.Status = "runtime_prepared"
|
||||
trace.FinalAction = runtimeTraceFinalAction(summary)
|
||||
if summary != nil && strings.TrimSpace(summary.TraceData) != "" {
|
||||
trace.Runtime = json.RawMessage(summary.TraceData)
|
||||
}
|
||||
}
|
||||
|
||||
func expiredInterruptSummary() *applicationruntime.Summary {
|
||||
return &applicationruntime.Summary{
|
||||
Status: "expired",
|
||||
|
||||
Reference in New Issue
Block a user