diff --git a/pkg/tests/runner2_test.go b/pkg/tests/runner2_test.go index 12ac4fa0..27d4c226 100644 --- a/pkg/tests/runner2_test.go +++ b/pkg/tests/runner2_test.go @@ -32,3 +32,26 @@ echo This is the input: ${GPTSCRIPT_INPUT} resp, err = r.Chat(context.Background(), resp.State, prg, nil, "input 2") r.AssertStep(t, resp, err) } + +func TestContextShareBug(t *testing.T) { + r := tester.NewRunner(t) + prg, err := loader.ProgramFromSource(context.Background(), ` +chat: true +tools: sharecontext + +Say hi + +--- +name: sharecontext +share context: realcontext +--- +name: realcontext + +#!sys.echo + +Yo dawg`, "") + require.NoError(t, err) + + resp, err := r.Chat(context.Background(), nil, prg, nil, "input 1") + r.AssertStep(t, resp, err) +} diff --git a/pkg/tests/testdata/TestContextShareBug/call1-resp.golden b/pkg/tests/testdata/TestContextShareBug/call1-resp.golden new file mode 100644 index 00000000..2861a036 --- /dev/null +++ b/pkg/tests/testdata/TestContextShareBug/call1-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 1" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestContextShareBug/call1.golden b/pkg/tests/testdata/TestContextShareBug/call1.golden new file mode 100644 index 00000000..0a46f0ca --- /dev/null +++ b/pkg/tests/testdata/TestContextShareBug/call1.golden @@ -0,0 +1,25 @@ +`{ + "model": "gpt-4o", + "internalSystemPrompt": false, + "messages": [ + { + "role": "system", + "content": [ + { + "text": "\nYo dawg\nSay hi" + } + ], + "usage": {} + }, + { + "role": "user", + "content": [ + { + "text": "input 1" + } + ], + "usage": {} + } + ], + "chat": true +}` diff --git a/pkg/tests/testdata/TestContextShareBug/step1.golden b/pkg/tests/testdata/TestContextShareBug/step1.golden new file mode 100644 index 00000000..cb17be6d --- /dev/null +++ b/pkg/tests/testdata/TestContextShareBug/step1.golden @@ -0,0 +1,48 @@ +`{ + "done": false, + "content": "TEST RESULT CALL: 1", + "toolID": "inline:", + "state": { + "continuation": { + "state": { + "input": "input 1", + "completion": { + "model": "gpt-4o", + "internalSystemPrompt": false, + "messages": [ + { + "role": "system", + "content": [ + { + "text": "\nYo dawg\nSay hi" + } + ], + "usage": {} + }, + { + "role": "user", + "content": [ + { + "text": "input 1" + } + ], + "usage": {} + }, + { + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 1" + } + ], + "usage": {} + } + ], + "chat": true + } + }, + "result": "TEST RESULT CALL: 1" + }, + "continuationToolID": "inline:" + } +}` diff --git a/pkg/types/tool.go b/pkg/types/tool.go index 57ce3fbf..0d2a5cc0 100644 --- a/pkg/types/tool.go +++ b/pkg/types/tool.go @@ -557,6 +557,15 @@ func (t Tool) GetContextTools(prg Program) ([]ToolReference, error) { result.Add(contextRef) } + exportOnlyTools, err := t.getCompletionToolRefs(prg, nil, ToolTypeDefault, ToolTypeContext) + if err != nil { + return nil, err + } + + for _, contextRef := range exportOnlyTools { + result.AddAll(prg.ToolSet[contextRef.ToolID].getExportedContext(prg)) + } + return result.List() }