@@ -828,49 +828,49 @@ func formatMessagesForLog(messages []providers.Message) string {
828828 return "[]"
829829 }
830830
831- var result string
832- result += "[\n "
831+ var sb strings. Builder
832+ sb . WriteString ( "[\n " )
833833 for i , msg := range messages {
834- result += fmt .Sprintf ( " [%d] Role: %s\n " , i , msg .Role )
834+ fmt .Fprintf ( & sb , " [%d] Role: %s\n " , i , msg .Role )
835835 if len (msg .ToolCalls ) > 0 {
836- result += " ToolCalls:\n "
836+ sb . WriteString ( " ToolCalls:\n " )
837837 for _ , tc := range msg .ToolCalls {
838- result += fmt .Sprintf ( " - ID: %s, Type: %s, Name: %s\n " , tc .ID , tc .Type , tc .Name )
838+ fmt .Fprintf ( & sb , " - ID: %s, Type: %s, Name: %s\n " , tc .ID , tc .Type , tc .Name )
839839 if tc .Function != nil {
840- result += fmt .Sprintf ( " Arguments: %s\n " , utils .Truncate (tc .Function .Arguments , 200 ))
840+ fmt .Fprintf ( & sb , " Arguments: %s\n " , utils .Truncate (tc .Function .Arguments , 200 ))
841841 }
842842 }
843843 }
844844 if msg .Content != "" {
845845 content := utils .Truncate (msg .Content , 200 )
846- result += fmt .Sprintf ( " Content: %s\n " , content )
846+ fmt .Fprintf ( & sb , " Content: %s\n " , content )
847847 }
848848 if msg .ToolCallID != "" {
849- result += fmt .Sprintf ( " ToolCallID: %s\n " , msg .ToolCallID )
849+ fmt .Fprintf ( & sb , " ToolCallID: %s\n " , msg .ToolCallID )
850850 }
851- result += "\n "
851+ sb . WriteString ( "\n " )
852852 }
853- result += "]"
854- return result
853+ sb . WriteString ( "]" )
854+ return sb . String ()
855855}
856856
857857// formatToolsForLog formats tool definitions for logging
858- func formatToolsForLog (tools []providers.ToolDefinition ) string {
859- if len (tools ) == 0 {
858+ func formatToolsForLog (toolDefs []providers.ToolDefinition ) string {
859+ if len (toolDefs ) == 0 {
860860 return "[]"
861861 }
862862
863- var result string
864- result += "[\n "
865- for i , tool := range tools {
866- result += fmt .Sprintf ( " [%d] Type: %s, Name: %s\n " , i , tool .Type , tool .Function .Name )
867- result += fmt .Sprintf ( " Description: %s\n " , tool .Function .Description )
863+ var sb strings. Builder
864+ sb . WriteString ( "[\n " )
865+ for i , tool := range toolDefs {
866+ fmt .Fprintf ( & sb , " [%d] Type: %s, Name: %s\n " , i , tool .Type , tool .Function .Name )
867+ fmt .Fprintf ( & sb , " Description: %s\n " , tool .Function .Description )
868868 if len (tool .Function .Parameters ) > 0 {
869- result += fmt .Sprintf ( " Parameters: %s\n " , utils .Truncate (fmt .Sprintf ("%v" , tool .Function .Parameters ), 200 ))
869+ fmt .Fprintf ( & sb , " Parameters: %s\n " , utils .Truncate (fmt .Sprintf ("%v" , tool .Function .Parameters ), 200 ))
870870 }
871871 }
872- result += "]"
873- return result
872+ sb . WriteString ( "]" )
873+ return sb . String ()
874874}
875875
876876// summarizeSession summarizes the conversation history for a session.
@@ -946,14 +946,18 @@ func (al *AgentLoop) summarizeSession(agent *AgentInstance, sessionKey string) {
946946
947947// summarizeBatch summarizes a batch of messages.
948948func (al * AgentLoop ) summarizeBatch (ctx context.Context , agent * AgentInstance , batch []providers.Message , existingSummary string ) (string , error ) {
949- prompt := "Provide a concise summary of this conversation segment, preserving core context and key points.\n "
949+ var sb strings.Builder
950+ sb .WriteString ("Provide a concise summary of this conversation segment, preserving core context and key points.\n " )
950951 if existingSummary != "" {
951- prompt += "Existing context: " + existingSummary + "\n "
952+ sb .WriteString ("Existing context: " )
953+ sb .WriteString (existingSummary )
954+ sb .WriteString ("\n " )
952955 }
953- prompt += "\n CONVERSATION:\n "
956+ sb . WriteString ( "\n CONVERSATION:\n " )
954957 for _ , m := range batch {
955- prompt += fmt .Sprintf ( "%s: %s\n " , m .Role , m .Content )
958+ fmt .Fprintf ( & sb , "%s: %s\n " , m .Role , m .Content )
956959 }
960+ prompt := sb .String ()
957961
958962 response , err := agent .Provider .Chat (ctx , []providers.Message {{Role : "user" , Content : prompt }}, nil , agent .Model , map [string ]interface {}{
959963 "max_tokens" : 1024 ,
0 commit comments