Skip to content

Commit f2bfa9f

Browse files
Merge pull request #827 from ibuildthecloud/share-context-bug
bug: respect "share context" from referenced tools
2 parents 5d2505a + 7d469ce commit f2bfa9f

File tree

5 files changed

+114
-0
lines changed

5 files changed

+114
-0
lines changed

pkg/tests/runner2_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,26 @@ echo This is the input: ${GPTSCRIPT_INPUT}
3232
resp, err = r.Chat(context.Background(), resp.State, prg, nil, "input 2")
3333
r.AssertStep(t, resp, err)
3434
}
35+
36+
func TestContextShareBug(t *testing.T) {
37+
r := tester.NewRunner(t)
38+
prg, err := loader.ProgramFromSource(context.Background(), `
39+
chat: true
40+
tools: sharecontext
41+
42+
Say hi
43+
44+
---
45+
name: sharecontext
46+
share context: realcontext
47+
---
48+
name: realcontext
49+
50+
#!sys.echo
51+
52+
Yo dawg`, "")
53+
require.NoError(t, err)
54+
55+
resp, err := r.Chat(context.Background(), nil, prg, nil, "input 1")
56+
r.AssertStep(t, resp, err)
57+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
`{
2+
"role": "assistant",
3+
"content": [
4+
{
5+
"text": "TEST RESULT CALL: 1"
6+
}
7+
],
8+
"usage": {}
9+
}`
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
`{
2+
"model": "gpt-4o",
3+
"internalSystemPrompt": false,
4+
"messages": [
5+
{
6+
"role": "system",
7+
"content": [
8+
{
9+
"text": "\nYo dawg\nSay hi"
10+
}
11+
],
12+
"usage": {}
13+
},
14+
{
15+
"role": "user",
16+
"content": [
17+
{
18+
"text": "input 1"
19+
}
20+
],
21+
"usage": {}
22+
}
23+
],
24+
"chat": true
25+
}`
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
`{
2+
"done": false,
3+
"content": "TEST RESULT CALL: 1",
4+
"toolID": "inline:",
5+
"state": {
6+
"continuation": {
7+
"state": {
8+
"input": "input 1",
9+
"completion": {
10+
"model": "gpt-4o",
11+
"internalSystemPrompt": false,
12+
"messages": [
13+
{
14+
"role": "system",
15+
"content": [
16+
{
17+
"text": "\nYo dawg\nSay hi"
18+
}
19+
],
20+
"usage": {}
21+
},
22+
{
23+
"role": "user",
24+
"content": [
25+
{
26+
"text": "input 1"
27+
}
28+
],
29+
"usage": {}
30+
},
31+
{
32+
"role": "assistant",
33+
"content": [
34+
{
35+
"text": "TEST RESULT CALL: 1"
36+
}
37+
],
38+
"usage": {}
39+
}
40+
],
41+
"chat": true
42+
}
43+
},
44+
"result": "TEST RESULT CALL: 1"
45+
},
46+
"continuationToolID": "inline:"
47+
}
48+
}`

pkg/types/tool.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,15 @@ func (t Tool) GetContextTools(prg Program) ([]ToolReference, error) {
557557
result.Add(contextRef)
558558
}
559559

560+
exportOnlyTools, err := t.getCompletionToolRefs(prg, nil, ToolTypeDefault, ToolTypeContext)
561+
if err != nil {
562+
return nil, err
563+
}
564+
565+
for _, contextRef := range exportOnlyTools {
566+
result.AddAll(prg.ToolSet[contextRef.ToolID].getExportedContext(prg))
567+
}
568+
560569
return result.List()
561570
}
562571

0 commit comments

Comments
 (0)