Skip to content

Commit 489b4c4

Browse files
Consolidate conversion layer types and functions (#82)
- Move ProviderData, ToolCall, ToolResult types to backend/tool/types - Remove duplicate ConvertMemoryMessageToProto from backend/agent - Replace simplified api/conv/message.go with comprehensive implementation - Simplify shared/conv to only utility functions (Ptr, FromPtr, ErrorToString) This consolidation establishes clear ownership: - backend/tool/types: persistence types for tool calls/results - backend/api/conv: Memory↔Proto conversions (API layer) - backend/agent: Memory↔Model conversions (LLM provider layer) Co-authored-by: construct-agent <noreply@construct.sh>
1 parent 86ea11d commit 489b4c4

8 files changed

Lines changed: 604 additions & 1635 deletions

File tree

backend/agent/conv.go

Lines changed: 11 additions & 531 deletions
Large diffs are not rendered by default.

backend/agent/task_reconciler.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -717,20 +717,20 @@ func (r *TaskReconciler) reconcileExecuteTools(ctx context.Context, taskID uuid.
717717
return Result{Retry: true}, nil
718718
}
719719

720-
func (r *TaskReconciler) callTools(ctx context.Context, task *memory.Task, message *memory.Message) ([]*ToolResult, map[string]int64, error) {
720+
func (r *TaskReconciler) callTools(ctx context.Context, task *memory.Task, message *memory.Message) ([]*tooltypes.ToolResult, map[string]int64, error) {
721721
logger := r.logger.With(
722722
KeyTaskID, task.ID,
723723
KeyMessageID, message.ID,
724724
)
725725
LogOperationStart(logger, "call tools")
726726

727-
var toolResults []*ToolResult
727+
var toolResults []*tooltypes.ToolResult
728728
toolStats := make(map[string]int64)
729729

730730
for _, block := range message.Content.Blocks {
731731
switch block.Kind {
732732
case types.MessageBlockKindToolCall:
733-
var toolCall ToolCall
733+
var toolCall tooltypes.ToolCall
734734
err := json.Unmarshal([]byte(block.Payload), &toolCall)
735735
if err != nil {
736736
logger.ErrorContext(ctx, "failed to unmarshal tool call", "error", err)
@@ -764,7 +764,7 @@ func (r *TaskReconciler) callTools(ctx context.Context, task *memory.Task, messa
764764
}
765765

766766
// Create unified ToolResult directly
767-
toolResult := &ToolResult{
767+
toolResult := &tooltypes.ToolResult{
768768
Tool: toolCall.Tool,
769769
Output: &tooltypes.ToolOutput{
770770
Interpreter: &tooltypes.InterpreterOutput{
@@ -774,7 +774,7 @@ func (r *TaskReconciler) callTools(ctx context.Context, task *memory.Task, messa
774774
},
775775
},
776776
Succeeded: err == nil,
777-
Provider: &ProviderData{
777+
Provider: &tooltypes.ProviderData{
778778
Kind: toolCall.Provider.Kind,
779779
ID: toolCall.Provider.ID,
780780
},
@@ -801,7 +801,7 @@ func (r *TaskReconciler) callTools(ctx context.Context, task *memory.Task, messa
801801
return toolResults, toolStats, nil
802802
}
803803

804-
func (r *TaskReconciler) persistToolResults(ctx context.Context, taskID uuid.UUID, toolResults []*ToolResult, tx *memory.Client) (*memory.Message, error) {
804+
func (r *TaskReconciler) persistToolResults(ctx context.Context, taskID uuid.UUID, toolResults []*tooltypes.ToolResult, tx *memory.Client) (*memory.Message, error) {
805805
toolBlocks := make([]types.MessageBlock, 0, len(toolResults))
806806
for _, toolResult := range toolResults {
807807
jsonResult, err := json.Marshal(toolResult)
@@ -842,7 +842,7 @@ func logInterpreterArgs(ctx context.Context, taskID uuid.UUID, toolID string, ar
842842
logInterpreter(ctx, taskID, toolID, a.Script, "args_interpreter")
843843
}
844844

845-
func logInterpreterResult(ctx context.Context, taskID uuid.UUID, toolID string, result *ToolResult) {
845+
func logInterpreterResult(ctx context.Context, taskID uuid.UUID, toolID string, result *tooltypes.ToolResult) {
846846
jsonResult, err := json.MarshalIndent(result, "", " ")
847847
if err != nil {
848848
slog.ErrorContext(ctx, "failed to marshal interpreter result", "error", err)

backend/agent/types.go

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)