Skip to content

Commit 1f9e86d

Browse files
Merge pull request #620 from ibuildthecloud/main
chore: add support for tools with only a single agent line and nothing else
2 parents 6cdd89d + 476f4ae commit 1f9e86d

File tree

11 files changed

+346
-2
lines changed

11 files changed

+346
-2
lines changed

pkg/engine/engine.go

+5
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ func NewContext(ctx context.Context, prg *types.Program, input string) (Context,
207207
}
208208

209209
callCtx.AgentGroup = agentGroup
210+
211+
if callCtx.Tool.IsAgentsOnly() && len(callCtx.AgentGroup) > 0 {
212+
callCtx.Tool = callCtx.Program.ToolSet[callCtx.AgentGroup[0].ToolID]
213+
}
214+
210215
return callCtx, nil
211216
}
212217

pkg/input/input.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package input
33
import (
44
"fmt"
55
"io"
6+
"io/fs"
67
"os"
78
"path/filepath"
89
"strings"
910

11+
"github.com/gptscript-ai/gptscript/internal"
1012
"github.com/gptscript-ai/gptscript/pkg/loader"
1113
"github.com/gptscript-ai/gptscript/pkg/types"
1214
)
@@ -33,7 +35,7 @@ func FromFile(file string) (string, error) {
3335
}
3436
return string(data), nil
3537
} else if file != "" {
36-
if s, err := os.Stat(file); err == nil && s.IsDir() {
38+
if s, err := fs.Stat(internal.FS, file); err == nil && s.IsDir() {
3739
for _, ext := range types.DefaultFiles {
3840
if _, err := os.Stat(filepath.Join(file, ext)); err == nil {
3941
file = filepath.Join(file, ext)
@@ -42,7 +44,7 @@ func FromFile(file string) (string, error) {
4244
}
4345
}
4446
log.Debugf("reading file %s", file)
45-
data, err := os.ReadFile(file)
47+
data, err := fs.ReadFile(internal.FS, file)
4648
if err != nil {
4749
return "", fmt.Errorf("reading %s: %w", file, err)
4850
}

pkg/parser/parser.go

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ func (c *context) finish(tools *[]Node) {
199199
len(c.tool.GlobalTools) > 0 ||
200200
len(c.tool.ExportInputFilters) > 0 ||
201201
len(c.tool.ExportOutputFilters) > 0 ||
202+
len(c.tool.Agents) > 0 ||
202203
c.tool.Chat {
203204
*tools = append(*tools, Node{
204205
ToolNode: &ToolNode{

pkg/tests/runner_test.go

+20
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,26 @@ func TestExport(t *testing.T) {
800800
assert.Equal(t, "TEST RESULT CALL: 3", x)
801801
}
802802

803+
func TestAgentOnly(t *testing.T) {
804+
r := tester.NewRunner(t)
805+
806+
prg, err := r.Load("")
807+
require.NoError(t, err)
808+
809+
r.RespondWith(tester.Result{
810+
Func: types.CompletionFunctionCall{
811+
Name: "agent2",
812+
Arguments: "Agent 2 input",
813+
},
814+
})
815+
816+
resp, err := r.Chat(context.Background(), nil, prg, nil, "Input 1")
817+
require.NoError(t, err)
818+
r.AssertResponded(t)
819+
assert.False(t, resp.Done)
820+
autogold.Expect("TEST RESULT CALL: 2").Equal(t, resp.Content)
821+
autogold.ExpectFile(t, toJSONString(t, resp), autogold.Name(t.Name()+"/step1"))
822+
}
803823
func TestAgents(t *testing.T) {
804824
r := tester.NewRunner(t)
805825

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
`{
2+
"role": "assistant",
3+
"content": [
4+
{
5+
"toolCall": {
6+
"index": 0,
7+
"id": "call_1",
8+
"function": {
9+
"name": "agent2",
10+
"arguments": "Agent 2 input"
11+
}
12+
}
13+
}
14+
],
15+
"usage": {}
16+
}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
`{
2+
"model": "gpt-4o",
3+
"internalSystemPrompt": false,
4+
"tools": [
5+
{
6+
"function": {
7+
"toolID": "testdata/TestAgentOnly/test.gpt:agent2",
8+
"name": "agent2",
9+
"parameters": {
10+
"properties": {
11+
"defaultPromptParameter": {
12+
"description": "Prompt to send to the assistant. This may be an instruction or question.",
13+
"type": "string"
14+
}
15+
},
16+
"type": "object"
17+
}
18+
}
19+
}
20+
],
21+
"messages": [
22+
{
23+
"role": "system",
24+
"content": [
25+
{
26+
"text": "I am agent1"
27+
}
28+
],
29+
"usage": {}
30+
},
31+
{
32+
"role": "user",
33+
"content": [
34+
{
35+
"text": "Input 1"
36+
}
37+
],
38+
"usage": {}
39+
}
40+
],
41+
"chat": true
42+
}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
`{
2+
"role": "assistant",
3+
"content": [
4+
{
5+
"text": "TEST RESULT CALL: 2"
6+
}
7+
],
8+
"usage": {}
9+
}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
`{
2+
"model": "gpt-4o",
3+
"internalSystemPrompt": false,
4+
"tools": [
5+
{
6+
"function": {
7+
"toolID": "testdata/TestAgentOnly/test.gpt:agent1",
8+
"name": "agent1",
9+
"parameters": {
10+
"properties": {
11+
"defaultPromptParameter": {
12+
"description": "Prompt to send to the assistant. This may be an instruction or question.",
13+
"type": "string"
14+
}
15+
},
16+
"type": "object"
17+
}
18+
}
19+
},
20+
{
21+
"function": {
22+
"toolID": "testdata/TestAgentOnly/test.gpt:agent3",
23+
"name": "agent3",
24+
"parameters": {
25+
"properties": {
26+
"defaultPromptParameter": {
27+
"description": "Prompt to send to the assistant. This may be an instruction or question.",
28+
"type": "string"
29+
}
30+
},
31+
"type": "object"
32+
}
33+
}
34+
}
35+
],
36+
"messages": [
37+
{
38+
"role": "system",
39+
"content": [
40+
{
41+
"text": "I am agent2"
42+
}
43+
],
44+
"usage": {}
45+
},
46+
{
47+
"role": "user",
48+
"content": [
49+
{
50+
"text": "Agent 2 input"
51+
}
52+
],
53+
"usage": {}
54+
}
55+
],
56+
"chat": true
57+
}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
`{
2+
"done": false,
3+
"content": "TEST RESULT CALL: 2",
4+
"toolID": "testdata/TestAgentOnly/test.gpt:agent2",
5+
"state": {
6+
"continuation": {
7+
"state": {
8+
"input": "Input 1",
9+
"completion": {
10+
"model": "gpt-4o",
11+
"internalSystemPrompt": false,
12+
"tools": [
13+
{
14+
"function": {
15+
"toolID": "testdata/TestAgentOnly/test.gpt:agent2",
16+
"name": "agent2",
17+
"parameters": {
18+
"properties": {
19+
"defaultPromptParameter": {
20+
"description": "Prompt to send to the assistant. This may be an instruction or question.",
21+
"type": "string"
22+
}
23+
},
24+
"type": "object"
25+
}
26+
}
27+
}
28+
],
29+
"messages": [
30+
{
31+
"role": "system",
32+
"content": [
33+
{
34+
"text": "I am agent1"
35+
}
36+
],
37+
"usage": {}
38+
},
39+
{
40+
"role": "user",
41+
"content": [
42+
{
43+
"text": "Input 1"
44+
}
45+
],
46+
"usage": {}
47+
},
48+
{
49+
"role": "assistant",
50+
"content": [
51+
{
52+
"toolCall": {
53+
"index": 0,
54+
"id": "call_1",
55+
"function": {
56+
"name": "agent2",
57+
"arguments": "Agent 2 input"
58+
}
59+
}
60+
}
61+
],
62+
"usage": {}
63+
}
64+
],
65+
"chat": true
66+
},
67+
"pending": {
68+
"call_1": {
69+
"index": 0,
70+
"id": "call_1",
71+
"function": {
72+
"name": "agent2",
73+
"arguments": "Agent 2 input"
74+
}
75+
}
76+
}
77+
},
78+
"calls": {
79+
"call_1": {
80+
"toolID": "testdata/TestAgentOnly/test.gpt:agent2",
81+
"input": "Agent 2 input"
82+
}
83+
}
84+
},
85+
"subCalls": [
86+
{
87+
"toolId": "testdata/TestAgentOnly/test.gpt:agent2",
88+
"callId": "call_1",
89+
"state": {
90+
"continuation": {
91+
"state": {
92+
"input": "Agent 2 input",
93+
"completion": {
94+
"model": "gpt-4o",
95+
"internalSystemPrompt": false,
96+
"tools": [
97+
{
98+
"function": {
99+
"toolID": "testdata/TestAgentOnly/test.gpt:agent1",
100+
"name": "agent1",
101+
"parameters": {
102+
"properties": {
103+
"defaultPromptParameter": {
104+
"description": "Prompt to send to the assistant. This may be an instruction or question.",
105+
"type": "string"
106+
}
107+
},
108+
"type": "object"
109+
}
110+
}
111+
},
112+
{
113+
"function": {
114+
"toolID": "testdata/TestAgentOnly/test.gpt:agent3",
115+
"name": "agent3",
116+
"parameters": {
117+
"properties": {
118+
"defaultPromptParameter": {
119+
"description": "Prompt to send to the assistant. This may be an instruction or question.",
120+
"type": "string"
121+
}
122+
},
123+
"type": "object"
124+
}
125+
}
126+
}
127+
],
128+
"messages": [
129+
{
130+
"role": "system",
131+
"content": [
132+
{
133+
"text": "I am agent2"
134+
}
135+
],
136+
"usage": {}
137+
},
138+
{
139+
"role": "user",
140+
"content": [
141+
{
142+
"text": "Agent 2 input"
143+
}
144+
],
145+
"usage": {}
146+
},
147+
{
148+
"role": "assistant",
149+
"content": [
150+
{
151+
"text": "TEST RESULT CALL: 2"
152+
}
153+
],
154+
"usage": {}
155+
}
156+
],
157+
"chat": true
158+
}
159+
},
160+
"result": "TEST RESULT CALL: 2"
161+
},
162+
"continuationToolID": "testdata/TestAgentOnly/test.gpt:agent2"
163+
}
164+
}
165+
],
166+
"subCallID": "call_1"
167+
}
168+
}`
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
agents: agent1, agent2
2+
3+
----
4+
name: agent1
5+
chat: true
6+
7+
I am agent1
8+
9+
----
10+
name: agent2
11+
chat: true
12+
agents: agent3
13+
14+
I am agent2
15+
16+
---
17+
name: agent3
18+
chat: true
19+
20+
I am agent3

0 commit comments

Comments
 (0)