@@ -172,11 +172,7 @@ func (r *Runner) Chat(ctx context.Context, prevState ChatState, prg types.Progra
172
172
return resp , err
173
173
}
174
174
175
- if state == nil || state .StartContinuation {
176
- if state != nil {
177
- state = state .WithResumeInput (& input )
178
- input = state .InputContextContinuationInput
179
- }
175
+ if state == nil {
180
176
state , err = r .start (callCtx , state , monitor , env , input )
181
177
if err != nil {
182
178
return resp , err
@@ -186,11 +182,9 @@ func (r *Runner) Chat(ctx context.Context, prevState ChatState, prg types.Progra
186
182
state .ResumeInput = & input
187
183
}
188
184
189
- if ! state .StartContinuation {
190
- state , err = r .resume (callCtx , monitor , env , state )
191
- if err != nil {
192
- return resp , err
193
- }
185
+ state , err = r .resume (callCtx , monitor , env , state )
186
+ if err != nil {
187
+ return resp , err
194
188
}
195
189
196
190
if state .Result != nil {
@@ -335,24 +329,10 @@ func getToolRefInput(prg *types.Program, ref types.ToolReference, input string)
335
329
return string (output ), err
336
330
}
337
331
338
- func (r * Runner ) getContext (callCtx engine.Context , state * State , monitor Monitor , env []string , input string ) (result []engine.InputContext , _ * State , _ error ) {
332
+ func (r * Runner ) getContext (callCtx engine.Context , state * State , monitor Monitor , env []string , input string ) (result []engine.InputContext , _ error ) {
339
333
toolRefs , err := callCtx .Tool .GetContextTools (* callCtx .Program )
340
334
if err != nil {
341
- return nil , nil , err
342
- }
343
-
344
- var newState * State
345
- if state != nil {
346
- cp := * state
347
- newState = & cp
348
- if newState .InputContextContinuation != nil {
349
- newState .InputContexts = nil
350
- newState .InputContextContinuation = nil
351
- newState .InputContextContinuationInput = ""
352
- newState .ResumeInput = state .InputContextContinuationResumeInput
353
-
354
- input = state .InputContextContinuationInput
355
- }
335
+ return nil , err
356
336
}
357
337
358
338
for i , toolRef := range toolRefs {
@@ -363,47 +343,31 @@ func (r *Runner) getContext(callCtx engine.Context, state *State, monitor Monito
363
343
364
344
contextInput , err := getToolRefInput (callCtx .Program , toolRef , input )
365
345
if err != nil {
366
- return nil , nil , err
346
+ return nil , err
367
347
}
368
348
369
349
var content * State
370
- if state != nil && state .InputContextContinuation != nil {
371
- content , err = r .subCallResume (callCtx .Ctx , callCtx , monitor , env , toolRef .ToolID , "" , state .InputContextContinuation .WithResumeInput (state .ResumeInput ), engine .ContextToolCategory )
372
- } else {
373
- content , err = r .subCall (callCtx .Ctx , callCtx , monitor , env , toolRef .ToolID , contextInput , "" , engine .ContextToolCategory )
374
- }
350
+ content , err = r .subCall (callCtx .Ctx , callCtx , monitor , env , toolRef .ToolID , contextInput , "" , engine .ContextToolCategory )
375
351
if err != nil {
376
- return nil , nil , err
352
+ return nil , err
377
353
}
378
354
if content .Continuation != nil {
379
- if newState == nil {
380
- newState = & State {}
381
- }
382
- newState .InputContexts = result
383
- newState .InputContextContinuation = content
384
- newState .InputContextContinuationInput = input
385
- if state != nil {
386
- newState .InputContextContinuationResumeInput = state .ResumeInput
387
- }
388
- return nil , newState , nil
355
+ return nil , fmt .Errorf ("invalid state: context tool [%s] can not result in a continuation" , toolRef .ToolID )
389
356
}
390
357
result = append (result , engine.InputContext {
391
358
ToolID : toolRef .ToolID ,
392
359
Content : * content .Result ,
393
360
})
394
361
}
395
362
396
- return result , newState , nil
363
+ return result , nil
397
364
}
398
365
399
366
func (r * Runner ) call (callCtx engine.Context , monitor Monitor , env []string , input string ) (* State , error ) {
400
367
result , err := r .start (callCtx , nil , monitor , env , input )
401
368
if err != nil {
402
369
return nil , err
403
370
}
404
- if result .StartContinuation {
405
- return result , nil
406
- }
407
371
return r .resume (callCtx , monitor , env , result )
408
372
}
409
373
@@ -435,15 +399,10 @@ func (r *Runner) start(callCtx engine.Context, state *State, monitor Monitor, en
435
399
}
436
400
}
437
401
438
- var newState * State
439
- callCtx .InputContext , newState , err = r .getContext (callCtx , state , monitor , env , input )
402
+ callCtx .InputContext , err = r .getContext (callCtx , state , monitor , env , input )
440
403
if err != nil {
441
404
return nil , err
442
405
}
443
- if newState != nil && newState .InputContextContinuation != nil {
444
- newState .StartContinuation = true
445
- return newState , nil
446
- }
447
406
448
407
e := engine.Engine {
449
408
Model : r .c ,
@@ -493,11 +452,7 @@ type State struct {
493
452
SubCalls []SubCallResult `json:"subCalls,omitempty"`
494
453
SubCallID string `json:"subCallID,omitempty"`
495
454
496
- InputContexts []engine.InputContext `json:"inputContexts,omitempty"`
497
- InputContextContinuation * State `json:"inputContextContinuation,omitempty"`
498
- InputContextContinuationInput string `json:"inputContextContinuationInput,omitempty"`
499
- InputContextContinuationResumeInput * string `json:"inputContextContinuationResumeInput,omitempty"`
500
- StartContinuation bool `json:"startContinuation,omitempty"`
455
+ InputContexts []engine.InputContext `json:"inputContexts,omitempty"`
501
456
}
502
457
503
458
func (s State ) WithResumeInput (input * string ) * State {
@@ -510,10 +465,6 @@ func (s State) ContinuationContentToolID() (string, error) {
510
465
return s .ContinuationToolID , nil
511
466
}
512
467
513
- if s .InputContextContinuation != nil {
514
- return s .InputContextContinuation .ContinuationContentToolID ()
515
- }
516
-
517
468
for _ , subCall := range s .SubCalls {
518
469
if s .SubCallID == subCall .CallID {
519
470
return subCall .State .ContinuationContentToolID ()
@@ -527,10 +478,6 @@ func (s State) ContinuationContent() (string, error) {
527
478
return * s .Continuation .Result , nil
528
479
}
529
480
530
- if s .InputContextContinuation != nil {
531
- return s .InputContextContinuation .ContinuationContent ()
532
- }
533
-
534
481
for _ , subCall := range s .SubCalls {
535
482
if s .SubCallID == subCall .CallID {
536
483
return subCall .State .ContinuationContent ()
@@ -549,10 +496,6 @@ func (r *Runner) resume(callCtx engine.Context, monitor Monitor, env []string, s
549
496
retState , retErr = r .handleOutput (callCtx , monitor , env , retState , retErr )
550
497
}()
551
498
552
- if state .StartContinuation {
553
- return nil , fmt .Errorf ("invalid state, resume should not have StartContinuation set to true" )
554
- }
555
-
556
499
if state .Continuation == nil {
557
500
return nil , errors .New ("invalid state, resume should have Continuation data" )
558
501
}
@@ -651,18 +594,18 @@ func (r *Runner) resume(callCtx engine.Context, monitor Monitor, env []string, s
651
594
Env : env ,
652
595
}
653
596
654
- var contextInput string
597
+ var contentInput string
655
598
656
599
if state .Continuation != nil && state .Continuation .State != nil {
657
- contextInput = state .Continuation .State .Input
600
+ contentInput = state .Continuation .State .Input
658
601
}
659
602
660
603
if state .ResumeInput != nil {
661
- contextInput = * state .ResumeInput
604
+ contentInput = * state .ResumeInput
662
605
}
663
606
664
- callCtx .InputContext , state , err = r .getContext (callCtx , state , monitor , env , contextInput )
665
- if err != nil || state . InputContextContinuation != nil {
607
+ callCtx .InputContext , err = r .getContext (callCtx , state , monitor , env , contentInput )
608
+ if err != nil {
666
609
return state , err
667
610
}
668
611
@@ -772,10 +715,6 @@ func (r *Runner) subCalls(callCtx engine.Context, monitor Monitor, env []string,
772
715
callCtx .LastReturn = state .Continuation
773
716
}
774
717
775
- if state .InputContextContinuation != nil {
776
- return state , nil , nil
777
- }
778
-
779
718
if state .SubCallID != "" {
780
719
if state .ResumeInput == nil {
781
720
return nil , nil , fmt .Errorf ("invalid state, input must be set for sub call continuation on callID [%s]" , state .SubCallID )
0 commit comments