@@ -91,21 +91,20 @@ func (s *session) FromUser(ctx context.Context, prompt string, opts ...llm.Opt)
9191}
9292
9393// Generate a response from a tool calling result
94- func (s * session ) FromTool (ctx context.Context , call string , result any , opts ... llm.Opt ) error {
95- // Append the tool result
96- if message , err := toolResult (call , result ); err != nil {
97- return err
98- } else {
99- s .seq [len (s .seq )- 1 ] = message
94+ func (s * session ) FromTool (ctx context.Context , results ... llm.ToolResult ) error {
95+ if len (results ) == 0 {
96+ return llm .ErrConflict .Withf ("No tool results" )
10097 }
10198
102- // The options come from the session options and the user options
103- chatopts := make ([]llm.Opt , 0 , len (s .opts )+ len (opts ))
104- chatopts = append (chatopts , s .opts ... )
105- chatopts = append (chatopts , opts ... )
99+ // Append the tool results
100+ for _ , result := range results {
101+ if message , err := toolResult (result ); err != nil {
102+ s .seq = append (s .seq , message )
103+ }
104+ }
106105
107106 // Call the 'chat' method
108- r , err := s .model .client .Chat (ctx , s , chatopts ... )
107+ r , err := s .model .client .Chat (ctx , s , s . opts ... )
109108 if err != nil {
110109 return err
111110 } else {
@@ -177,17 +176,17 @@ func userPrompt(prompt string, opts ...llm.Opt) (*MessageMeta, error) {
177176 return & meta , nil
178177}
179178
180- func toolResult (name string , result any ) (* MessageMeta , error ) {
179+ func toolResult (result llm. ToolResult ) (* MessageMeta , error ) {
181180 // Turn result into JSON
182- data , err := json .Marshal (result )
181+ data , err := json .Marshal (result . Value () )
183182 if err != nil {
184183 return nil , err
185184 }
186185
187186 // Create a new message
188187 var meta MessageMeta
189188 meta .Role = "tool"
190- meta .FunctionName = name
189+ meta .FunctionName = result . Call (). Name ()
191190 meta .Content = string (data )
192191
193192 // Return success
0 commit comments