@@ -258,6 +258,29 @@ func (c *Context) WrappedContext(e *Engine) context.Context {
258
258
return context .WithValue (c .Ctx , engineContext {}, & cp )
259
259
}
260
260
261
+ func populateMessageParams (ctx Context , completion * types.CompletionRequest , tool types.Tool ) error {
262
+ completion .Model = tool .Parameters .ModelName
263
+ completion .MaxTokens = tool .Parameters .MaxTokens
264
+ completion .JSONResponse = tool .Parameters .JSONResponse
265
+ completion .Cache = tool .Parameters .Cache
266
+ completion .Chat = tool .Parameters .Chat
267
+ completion .Temperature = tool .Parameters .Temperature
268
+ completion .InternalSystemPrompt = tool .Parameters .InternalPrompt
269
+
270
+ if tool .Chat && completion .InternalSystemPrompt == nil {
271
+ completion .InternalSystemPrompt = new (bool )
272
+ }
273
+
274
+ var err error
275
+ completion .Tools , err = tool .GetCompletionTools (* ctx .Program , ctx .AgentGroup ... )
276
+ if err != nil {
277
+ return err
278
+ }
279
+
280
+ completion .Messages = addUpdateSystem (ctx , tool , completion .Messages )
281
+ return nil
282
+ }
283
+
261
284
func (e * Engine ) Start (ctx Context , input string ) (ret * Return , _ error ) {
262
285
tool := ctx .Tool
263
286
@@ -290,28 +313,11 @@ func (e *Engine) Start(ctx Context, input string) (ret *Return, _ error) {
290
313
return nil , fmt .Errorf ("credential tools cannot make calls to the LLM" )
291
314
}
292
315
293
- completion := types.CompletionRequest {
294
- Model : tool .Parameters .ModelName ,
295
- MaxTokens : tool .Parameters .MaxTokens ,
296
- JSONResponse : tool .Parameters .JSONResponse ,
297
- Cache : tool .Parameters .Cache ,
298
- Chat : tool .Parameters .Chat ,
299
- Temperature : tool .Parameters .Temperature ,
300
- InternalSystemPrompt : tool .Parameters .InternalPrompt ,
301
- }
302
-
303
- if tool .Chat && completion .InternalSystemPrompt == nil {
304
- completion .InternalSystemPrompt = new (bool )
305
- }
306
-
307
- var err error
308
- completion .Tools , err = tool .GetCompletionTools (* ctx .Program , ctx .AgentGroup ... )
309
- if err != nil {
316
+ var completion types.CompletionRequest
317
+ if err := populateMessageParams (ctx , & completion , tool ); err != nil {
310
318
return nil , err
311
319
}
312
320
313
- completion .Messages = addUpdateSystem (ctx , tool , completion .Messages )
314
-
315
321
if tool .Chat && input == "{}" {
316
322
input = ""
317
323
}
@@ -497,6 +503,9 @@ func (e *Engine) Continue(ctx Context, state *State, results ...CallResult) (*Re
497
503
return nil , fmt .Errorf ("invalid continue call, no completion needed" )
498
504
}
499
505
500
- state .Completion .Messages = addUpdateSystem (ctx , ctx .Tool , state .Completion .Messages )
506
+ if err := populateMessageParams (ctx , & state .Completion , ctx .Tool ); err != nil {
507
+ return nil , err
508
+ }
509
+
501
510
return e .complete (ctx .Ctx , state )
502
511
}
0 commit comments