@@ -131,7 +131,7 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
131131 }
132132
133133 if len(a.tools) > 0 {
134− // add anthropic caching to the last tool
134+ // Add anthropic caching to the last tool.
135135 a.tools[len(a.tools)-1].SetProviderOptions(a.getCacheControlOptions())
136136 }
137137
@@ -153,7 +153,7 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
153153 }
154154
155155 var wg sync.WaitGroup
156− // Generate title if first message
156+ // Generate title if first message.
157157 if len(msgs) == 0 {
158158 wg.Go(func() {
159159 sessionLock.Lock()
@@ -162,13 +162,13 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
162162 })
163163 }
164164
165− // Add the user message to the session
165+ // Add the user message to the session.
166166 _, err = a.createUserMessage(ctx, call)
167167 if err != nil {
168168 return nil, err
169169 }
170170
171− // add the session to the context
171+ // Add the session to the context.
172172 ctx = context.WithValue(ctx, tools.SessionIDContextKey, call.SessionID)
173173
174174 genCtx, cancel := context.WithCancel(ctx)
@@ -195,10 +195,10 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
195195 PresencePenalty: call.PresencePenalty,
196196 TopK: call.TopK,
197197 FrequencyPenalty: call.FrequencyPenalty,
198− // Before each step create the new assistant message
198+ // Before each step create a new assistant message.
199199 PrepareStep: func(callContext context.Context, options fantasy.PrepareStepFunctionOptions) (_ context.Context, prepared fantasy.PrepareStepResult, err error) {
200200 prepared.Messages = options.Messages
201− // reset all cached items
201+ // Reset all cached items.
202202 for i := range prepared.Messages {
203203 prepared.Messages[i].ProviderOptions = nil
204204 }
@@ -216,14 +216,14 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
216216 lastSystemRoleInx := 0
217217 systemMessageUpdated := false
218218 for i, msg := range prepared.Messages {
219− // only add cache control to the last message
219+ // Only add cache control to the last message.
220220 if msg.Role == fantasy.MessageRoleSystem {
221221 lastSystemRoleInx = i
222222 } else if !systemMessageUpdated {
223223 prepared.Messages[lastSystemRoleInx].ProviderOptions = a.getCacheControlOptions()
224224 systemMessageUpdated = true
225225 }
226− // than add cache control to the last 2 messages
226+ // Than add cache control to the last 2 messages.
227227 if i > len(prepared.Messages)-3 {
228228 prepared.Messages[i].ProviderOptions = a.getCacheControlOptions()
229229 }
@@ -394,10 +394,10 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
394394 if currentAssistant == nil {
395395 return result, err
396396 }
397− // Ensure we finish thinking on error to close the reasoning state
397+ // Ensure we finish thinking on error to close the reasoning state.
398398 currentAssistant.FinishThinking()
399399 toolCalls := currentAssistant.ToolCalls()
400− // INFO: we use the parent context here because the genCtx has been cancelled
400+ // INFO: we use the parent context here because the genCtx has been cancelled.
401401 msgs, createErr := a.messages.List(ctx, currentAssistant.SessionID)
402402 if createErr != nil {
403403 return nil, createErr
@@ -459,7 +459,8 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
459459 } else {
460460 currentAssistant.AddFinish(message.FinishReasonError, "API Error", err.Error())
461461 }
462− // INFO: we use the parent context here because the genCtx has been cancelled
462+ // Note: we use the parent context here because the genCtx has been
463+ // cancelled.
463464 updateErr := a.messages.Update(ctx, *currentAssistant)
464465 if updateErr != nil {
465466 return nil, updateErr
@@ -473,7 +474,7 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
473474 if summarizeErr := a.Summarize(genCtx, call.SessionID, call.ProviderOptions); summarizeErr != nil {
474475 return nil, summarizeErr
475476 }
476− // if the agent was not done...
477+ // If the agent wasn't done...
477478 if len(currentAssistant.ToolCalls()) > 0 {
478479 existing, ok := a.messageQueue.Get(call.SessionID)
479480 if !ok {
@@ -485,7 +486,7 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
485486 }
486487 }
487488
488− // release active request before processing queued messages
489+ // Release active request before processing queued messages.
489490 a.activeRequests.Del(call.SessionID)
490491 cancel()
491492
@@ -493,7 +494,7 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
493494 if !ok || len(queuedMessages) == 0 {
494495 return result, err
495496 }
496− // there are queued messages restart the loop
497+ // There are queued messages restart the loop.
497498 firstQueuedMessage := queuedMessages[0]
498499 a.messageQueue.Set(call.SessionID, queuedMessages[1:])
499500 return a.Run(ctx, firstQueuedMessage)
@@ -513,7 +514,7 @@ func (a *sessionAgent) Summarize(ctx context.Context, sessionID string, opts fan
513514 return err
514515 }
515516 if len(msgs) == 0 {
516− // nothing to summarize
517+ // Nothing to summarize.
517518 return nil
518519 }
519520
@@ -553,7 +554,7 @@ func (a *sessionAgent) Summarize(ctx context.Context, sessionID string, opts fan
553554 return a.messages.Update(genCtx, summaryMessage)
554555 },
555556 OnReasoningEnd: func(id string, reasoning fantasy.ReasoningContent) error {
556− // handle anthropic signature
557+ // Handle anthropic signature.
557558 if anthropicData, ok := reasoning.ProviderMetadata["anthropic"]; ok {
558559 if signature, ok := anthropicData.(*anthropic.ReasoningOptionMetadata); ok && signature.Signature != "" {
559560 summaryMessage.AppendReasoningSignature(signature.Signature)
@@ -570,7 +571,7 @@ func (a *sessionAgent) Summarize(ctx context.Context, sessionID string, opts fan
570571 if err != nil {
571572 isCancelErr := errors.Is(err, context.Canceled)
572573 if isCancelErr {
573− // User cancelled summarize we need to remove the summary message
574+ // User cancelled summarize we need to remove the summary message.
574575 deleteErr := a.messages.Delete(ctx, summaryMessage.ID)
575576 return deleteErr
576577 }
@@ -597,7 +598,7 @@ func (a *sessionAgent) Summarize(ctx context.Context, sessionID string, opts fan
597598
598599 a.updateSessionUsage(a.largeModel, ¤tSession, resp.TotalUsage, openrouterCost)
599600
600− // just in case get just the last usage
601+ // Just in case, get just the last usage info.
601602 usage := resp.Response.Usage
602603 currentSession.SummaryMessageID = summaryMessage.ID
603604 currentSession.CompletionTokens = usage.OutputTokens
@@ -643,7 +644,8 @@ func (a *sessionAgent) preparePrompt(msgs []message.Message, attachments ...mess
643644 if len(m.Parts) == 0 {
644645 continue
645646 }
646− // Assistant message without content or tool calls (cancelled before it returned anything)
647+ // Assistant message without content or tool calls (cancelled before it
648+ // returned anything).
647649 if m.Role == message.Assistant && len(m.ToolCalls()) == 0 && m.Content().Text == "" && m.ReasoningContent().String() == "" {
648650 continue
649651 }
@@ -718,7 +720,7 @@ func (a *sessionAgent) generateTitle(ctx context.Context, session *session.Sessi
718720
719721 title = strings.ReplaceAll(title, "\n", " ")
720722
721− // remove thinking tags if present
723+ // Remove thinking tags if present.
722724 if idx := strings.Index(title, "</think>"); idx > 0 {
723725 title = title[idx+len("</think>"):]
724726 }
@@ -784,13 +786,13 @@ func (a *sessionAgent) updateSessionUsage(model Model, session *session.Session,
784786}
785787
786788func (a *sessionAgent) Cancel(sessionID string) {
787− // Cancel regular requests
789+ // Cancel regular requests.
788790 if cancel, ok := a.activeRequests.Take(sessionID); ok && cancel != nil {
789791 slog.Info("Request cancellation initiated", "session_id", sessionID)
790792 cancel()
791793 }
792794
793− // Also check for summarize requests
795+ // Also check for summarize requests.
794796 if cancel, ok := a.activeRequests.Take(sessionID + "-summarize"); ok && cancel != nil {
795797 slog.Info("Summarize cancellation initiated", "session_id", sessionID)
796798 cancel()