@@ -3,6 +3,7 @@ package screentracker
33import (
44 "context"
55 "fmt"
6+ "log/slog"
67 "strings"
78 "sync"
89 "time"
@@ -43,6 +44,9 @@ type ConversationConfig struct {
4344 SkipSendMessageStatusCheck bool
4445 // ReadyForInitialPrompt detects whether the agent has initialized and is ready to accept the initial prompt
4546 ReadyForInitialPrompt func (message string ) bool
47+ FormatToolCall func (message string ) (string , []string )
48+ // Logger for logging tool calls and other events
49+ Logger * slog.Logger
4650}
4751
4852type ConversationRole string
@@ -82,6 +86,8 @@ type Conversation struct {
8286 InitialPromptSent bool
8387 // ReadyForInitialPrompt keeps track if the agent is ready to accept the initial prompt
8488 ReadyForInitialPrompt bool
89+ //
90+ toolCallMessageSet map [string ]bool
8591}
8692
8793type ConversationStatus string
@@ -205,9 +211,18 @@ func (c *Conversation) lastMessage(role ConversationRole) ConversationMessage {
205211func (c * Conversation ) updateLastAgentMessage (screen string , timestamp time.Time ) {
206212 agentMessage := FindNewMessage (c .screenBeforeLastUserMessage , screen , c .cfg .AgentType )
207213 lastUserMessage := c .lastMessage (ConversationRoleUser )
214+ var toolCalls []string
208215 if c .cfg .FormatMessage != nil {
209216 agentMessage = c .cfg .FormatMessage (agentMessage , lastUserMessage .Message )
210217 }
218+ if c .cfg .FormatToolCall != nil {
219+ agentMessage , toolCalls = c .cfg .FormatToolCall (agentMessage )
220+ }
221+ for _ , toolCall := range toolCalls {
222+ if c .toolCallMessageSet [toolCall ] == false {
223+ c .toolCallMessageSet [toolCall ] = true
224+ }
225+ }
211226 shouldCreateNewMessage := len (c .messages ) == 0 || c .messages [len (c .messages )- 1 ].Role == ConversationRoleUser
212227 lastAgentMessage := c .lastMessage (ConversationRoleAgent )
213228 if lastAgentMessage .Message == agentMessage {
@@ -220,6 +235,13 @@ func (c *Conversation) updateLastAgentMessage(screen string, timestamp time.Time
220235 }
221236 if shouldCreateNewMessage {
222237 c .messages = append (c .messages , conversationMessage )
238+ // Logging all the tool calls till now
239+ for toolCall := range c .toolCallMessageSet {
240+ c .cfg .Logger .Info ("Tool call detected" , "toolCall" , toolCall )
241+ }
242+ // Cleanup
243+ c .toolCallMessageSet = make (map [string ]bool )
244+
223245 } else {
224246 c .messages [len (c .messages )- 1 ] = conversationMessage
225247 }
0 commit comments