package llm // Input is the interface for conversation inputs. // Types that implement this interface can be part of a conversation: // Message, ToolCall, ToolCallResponse, and ResponseChoice. type Input interface { // isInput is a marker method to ensure only valid types implement this interface. isInput() } // Implement Input interface for all valid input types. func (Message) isInput() {} func (ToolCall) isInput() {} func (ToolCallResponse) isInput() {} func (ResponseChoice) isInput() {} // Request represents a request to a language model. type Request struct { Conversation []Input Messages []Message Toolbox ToolBox Temperature *float64 } // NextRequest will take the current request's conversation, messages, the response, and any tool results, and // return a new request with the conversation updated to include the response and tool results. func (req Request) NextRequest(resp ResponseChoice, toolResults []ToolCallResponse) Request { var res Request res.Toolbox = req.Toolbox res.Temperature = req.Temperature res.Conversation = make([]Input, len(req.Conversation)) copy(res.Conversation, req.Conversation) // now for every input message, convert those to an Input to add to the conversation for _, msg := range req.Messages { res.Conversation = append(res.Conversation, msg) } if resp.Content != "" || resp.Refusal != "" || len(resp.Calls) > 0 { res.Conversation = append(res.Conversation, resp) } // if there are tool results, then we need to add those to the conversation for _, result := range toolResults { res.Conversation = append(res.Conversation, result) } return res }