Skip to content

Commit 1c75954

Browse files
chore: drop input continuations feature
1 parent 04dd074 commit 1c75954

22 files changed

+20
-1088
lines changed

pkg/runner/runner.go

Lines changed: 18 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,7 @@ func (r *Runner) Chat(ctx context.Context, prevState ChatState, prg types.Progra
172172
return resp, err
173173
}
174174

175-
if state == nil || state.StartContinuation {
176-
if state != nil {
177-
state = state.WithResumeInput(&input)
178-
input = state.InputContextContinuationInput
179-
}
175+
if state == nil {
180176
state, err = r.start(callCtx, state, monitor, env, input)
181177
if err != nil {
182178
return resp, err
@@ -186,11 +182,9 @@ func (r *Runner) Chat(ctx context.Context, prevState ChatState, prg types.Progra
186182
state.ResumeInput = &input
187183
}
188184

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
194188
}
195189

196190
if state.Result != nil {
@@ -335,24 +329,10 @@ func getToolRefInput(prg *types.Program, ref types.ToolReference, input string)
335329
return string(output), err
336330
}
337331

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) {
339333
toolRefs, err := callCtx.Tool.GetContextTools(*callCtx.Program)
340334
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
356336
}
357337

358338
for i, toolRef := range toolRefs {
@@ -363,47 +343,31 @@ func (r *Runner) getContext(callCtx engine.Context, state *State, monitor Monito
363343

364344
contextInput, err := getToolRefInput(callCtx.Program, toolRef, input)
365345
if err != nil {
366-
return nil, nil, err
346+
return nil, err
367347
}
368348

369349
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)
375351
if err != nil {
376-
return nil, nil, err
352+
return nil, err
377353
}
378354
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)
389356
}
390357
result = append(result, engine.InputContext{
391358
ToolID: toolRef.ToolID,
392359
Content: *content.Result,
393360
})
394361
}
395362

396-
return result, newState, nil
363+
return result, nil
397364
}
398365

399366
func (r *Runner) call(callCtx engine.Context, monitor Monitor, env []string, input string) (*State, error) {
400367
result, err := r.start(callCtx, nil, monitor, env, input)
401368
if err != nil {
402369
return nil, err
403370
}
404-
if result.StartContinuation {
405-
return result, nil
406-
}
407371
return r.resume(callCtx, monitor, env, result)
408372
}
409373

@@ -435,15 +399,10 @@ func (r *Runner) start(callCtx engine.Context, state *State, monitor Monitor, en
435399
}
436400
}
437401

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)
440403
if err != nil {
441404
return nil, err
442405
}
443-
if newState != nil && newState.InputContextContinuation != nil {
444-
newState.StartContinuation = true
445-
return newState, nil
446-
}
447406

448407
e := engine.Engine{
449408
Model: r.c,
@@ -493,11 +452,7 @@ type State struct {
493452
SubCalls []SubCallResult `json:"subCalls,omitempty"`
494453
SubCallID string `json:"subCallID,omitempty"`
495454

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"`
501456
}
502457

503458
func (s State) WithResumeInput(input *string) *State {
@@ -510,10 +465,6 @@ func (s State) ContinuationContentToolID() (string, error) {
510465
return s.ContinuationToolID, nil
511466
}
512467

513-
if s.InputContextContinuation != nil {
514-
return s.InputContextContinuation.ContinuationContentToolID()
515-
}
516-
517468
for _, subCall := range s.SubCalls {
518469
if s.SubCallID == subCall.CallID {
519470
return subCall.State.ContinuationContentToolID()
@@ -527,10 +478,6 @@ func (s State) ContinuationContent() (string, error) {
527478
return *s.Continuation.Result, nil
528479
}
529480

530-
if s.InputContextContinuation != nil {
531-
return s.InputContextContinuation.ContinuationContent()
532-
}
533-
534481
for _, subCall := range s.SubCalls {
535482
if s.SubCallID == subCall.CallID {
536483
return subCall.State.ContinuationContent()
@@ -549,10 +496,6 @@ func (r *Runner) resume(callCtx engine.Context, monitor Monitor, env []string, s
549496
retState, retErr = r.handleOutput(callCtx, monitor, env, retState, retErr)
550497
}()
551498

552-
if state.StartContinuation {
553-
return nil, fmt.Errorf("invalid state, resume should not have StartContinuation set to true")
554-
}
555-
556499
if state.Continuation == nil {
557500
return nil, errors.New("invalid state, resume should have Continuation data")
558501
}
@@ -651,18 +594,18 @@ func (r *Runner) resume(callCtx engine.Context, monitor Monitor, env []string, s
651594
Env: env,
652595
}
653596

654-
var contextInput string
597+
var contentInput string
655598

656599
if state.Continuation != nil && state.Continuation.State != nil {
657-
contextInput = state.Continuation.State.Input
600+
contentInput = state.Continuation.State.Input
658601
}
659602

660603
if state.ResumeInput != nil {
661-
contextInput = *state.ResumeInput
604+
contentInput = *state.ResumeInput
662605
}
663606

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 {
666609
return state, err
667610
}
668611

@@ -772,10 +715,6 @@ func (r *Runner) subCalls(callCtx engine.Context, monitor Monitor, env []string,
772715
callCtx.LastReturn = state.Continuation
773716
}
774717

775-
if state.InputContextContinuation != nil {
776-
return state, nil, nil
777-
}
778-
779718
if state.SubCallID != "" {
780719
if state.ResumeInput == nil {
781720
return nil, nil, fmt.Errorf("invalid state, input must be set for sub call continuation on callID [%s]", state.SubCallID)

pkg/tests/runner_test.go

Lines changed: 2 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -212,82 +212,8 @@ func TestContextSubChat(t *testing.T) {
212212
prg, err := r.Load("")
213213
require.NoError(t, err)
214214

215-
resp, err := r.Chat(context.Background(), nil, prg, os.Environ(), "User 1")
216-
require.NoError(t, err)
217-
r.AssertResponded(t)
218-
assert.False(t, resp.Done)
219-
autogold.Expect("Assistant Response 1 - from chatbot1").Equal(t, resp.Content)
220-
autogold.ExpectFile(t, toJSONString(t, resp), autogold.Name(t.Name()+"/step1"))
221-
222-
r.RespondWith(tester.Result{
223-
Content: []types.ContentPart{
224-
{
225-
ToolCall: &types.CompletionToolCall{
226-
ID: "call_2",
227-
Function: types.CompletionFunctionCall{
228-
Name: types.ToolNormalizer("sys.chat.finish"),
229-
Arguments: "Response from context chatbot",
230-
},
231-
},
232-
},
233-
},
234-
}, tester.Result{
235-
Text: "Assistant Response 2 - from context tool",
236-
}, tester.Result{
237-
Text: "Assistant Response 3 - from main chat tool",
238-
})
239-
resp, err = r.Chat(context.Background(), resp.State, prg, os.Environ(), "User 2")
240-
require.NoError(t, err)
241-
r.AssertResponded(t)
242-
assert.False(t, resp.Done)
243-
autogold.Expect("Assistant Response 3 - from main chat tool").Equal(t, resp.Content)
244-
autogold.ExpectFile(t, toJSONString(t, resp), autogold.Name(t.Name()+"/step2"))
245-
246-
r.RespondWith(tester.Result{
247-
Content: []types.ContentPart{
248-
{
249-
ToolCall: &types.CompletionToolCall{
250-
ID: "call_3",
251-
Function: types.CompletionFunctionCall{
252-
Name: "chatbot",
253-
Arguments: "Input to chatbot1 on resume",
254-
},
255-
},
256-
},
257-
},
258-
}, tester.Result{
259-
Text: "Assistant Response 4 - from chatbot1",
260-
})
261-
resp, err = r.Chat(context.Background(), resp.State, prg, os.Environ(), "User 3")
262-
require.NoError(t, err)
263-
r.AssertResponded(t)
264-
assert.False(t, resp.Done)
265-
autogold.Expect("Assistant Response 3 - from main chat tool").Equal(t, resp.Content)
266-
autogold.ExpectFile(t, toJSONString(t, resp), autogold.Name(t.Name()+"/step3"))
267-
268-
r.RespondWith(tester.Result{
269-
Content: []types.ContentPart{
270-
{
271-
ToolCall: &types.CompletionToolCall{
272-
ID: "call_4",
273-
Function: types.CompletionFunctionCall{
274-
Name: types.ToolNormalizer("sys.chat.finish"),
275-
Arguments: "Response from context chatbot after resume",
276-
},
277-
},
278-
},
279-
},
280-
}, tester.Result{
281-
Text: "Assistant Response 5 - from context tool resume",
282-
}, tester.Result{
283-
Text: "Assistant Response 6 - from main chat tool resume",
284-
})
285-
resp, err = r.Chat(context.Background(), resp.State, prg, os.Environ(), "User 4")
286-
require.NoError(t, err)
287-
r.AssertResponded(t)
288-
assert.False(t, resp.Done)
289-
autogold.Expect("Assistant Response 6 - from main chat tool resume").Equal(t, resp.Content)
290-
autogold.ExpectFile(t, toJSONString(t, resp), autogold.Name(t.Name()+"/step4"))
215+
_, err = r.Chat(context.Background(), nil, prg, os.Environ(), "User 1")
216+
autogold.Expect("invalid state: context tool [testdata/TestContextSubChat/test.gpt:subtool] can not result in a continuation").Equal(t, err.Error())
291217
}
292218

293219
func TestSubChat(t *testing.T) {

pkg/tests/testdata/TestContextSubChat/call10-resp.golden

Lines changed: 0 additions & 9 deletions
This file was deleted.

pkg/tests/testdata/TestContextSubChat/call10.golden

Lines changed: 0 additions & 43 deletions
This file was deleted.

pkg/tests/testdata/TestContextSubChat/call3-resp.golden

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)