Skip to content

Commit a80609f

Browse files
feat: add agents field
1 parent f7a38c3 commit a80609f

File tree

17 files changed

+573
-16
lines changed

17 files changed

+573
-16
lines changed

pkg/engine/engine.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,11 @@ type CallResult struct {
5454
}
5555

5656
type commonContext struct {
57-
ID string `json:"id"`
58-
Tool types.Tool `json:"tool"`
59-
InputContext []InputContext `json:"inputContext"`
60-
ToolCategory ToolCategory `json:"toolCategory,omitempty"`
57+
ID string `json:"id"`
58+
Tool types.Tool `json:"tool"`
59+
AgentGroup []types.ToolReference `json:"agentGroup,omitempty"`
60+
InputContext []InputContext `json:"inputContext"`
61+
ToolCategory ToolCategory `json:"toolCategory,omitempty"`
6162
}
6263

6364
type CallContext struct {
@@ -170,10 +171,16 @@ func (c *Context) SubCall(ctx context.Context, input, toolID, callID string, too
170171
callID = counter.Next()
171172
}
172173

174+
agentGroup, err := c.Tool.GetAgentGroup(c.AgentGroup, toolID)
175+
if err != nil {
176+
return Context{}, err
177+
}
178+
173179
return Context{
174180
commonContext: commonContext{
175181
ID: callID,
176182
Tool: tool,
183+
AgentGroup: agentGroup,
177184
ToolCategory: toolCategory,
178185
},
179186
Ctx: ctx,
@@ -240,7 +247,7 @@ func (e *Engine) Start(ctx Context, input string) (ret *Return, _ error) {
240247
}
241248

242249
var err error
243-
completion.Tools, err = tool.GetCompletionTools(*ctx.Program)
250+
completion.Tools, err = tool.GetCompletionTools(*ctx.Program, ctx.AgentGroup...)
244251
if err != nil {
245252
return nil, err
246253
}

pkg/loader/loader.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"os"
1212
"path"
1313
"path/filepath"
14-
"slices"
1514
"strconv"
1615
"strings"
1716
"time"
@@ -320,11 +319,7 @@ func link(ctx context.Context, cache *cache.Client, prg *types.Program, base *so
320319
// The below is done in two loops so that local names stay as the tool names
321320
// and don't get mangled by external references
322321

323-
for _, targetToolName := range slices.Concat(tool.Parameters.Tools,
324-
tool.Parameters.Export,
325-
tool.Parameters.ExportContext,
326-
tool.Parameters.Context,
327-
tool.Parameters.Credentials) {
322+
for _, targetToolName := range tool.Parameters.ToolRefNames() {
328323
noArgs, _ := types.SplitArg(targetToolName)
329324
localTool, ok := localTools[strings.ToLower(noArgs)]
330325
if ok {

pkg/parser/parser.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ func isParam(line string, tool *types.Tool) (_ bool, err error) {
104104
tool.Parameters.Export = append(tool.Parameters.Export, csv(value)...)
105105
case "tool", "tools":
106106
tool.Parameters.Tools = append(tool.Parameters.Tools, csv(value)...)
107+
case "agent", "agents":
108+
tool.Parameters.Agents = append(tool.Parameters.Agents, csv(value)...)
107109
case "globaltool", "globaltools":
108110
tool.Parameters.GlobalTools = append(tool.Parameters.GlobalTools, csv(value)...)
109111
case "exportcontext", "exportcontexts":

pkg/tests/runner_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,3 +778,31 @@ func TestExport(t *testing.T) {
778778
require.NoError(t, err)
779779
assert.Equal(t, "TEST RESULT CALL: 3", x)
780780
}
781+
782+
func TestAgents(t *testing.T) {
783+
r := tester.NewRunner(t)
784+
785+
prg, err := r.Load("")
786+
require.NoError(t, err)
787+
788+
r.RespondWith(tester.Result{
789+
Func: types.CompletionFunctionCall{
790+
Name: "agent1",
791+
},
792+
}, tester.Result{
793+
Func: types.CompletionFunctionCall{
794+
Name: "agent2",
795+
},
796+
}, tester.Result{
797+
Func: types.CompletionFunctionCall{
798+
Name: "agent3",
799+
},
800+
})
801+
802+
resp, err := r.Chat(context.Background(), nil, prg, nil, "Input 1")
803+
require.NoError(t, err)
804+
r.AssertResponded(t)
805+
assert.False(t, resp.Done)
806+
autogold.Expect("TEST RESULT CALL: 4").Equal(t, resp.Content)
807+
autogold.ExpectFile(t, toJSONString(t, resp), autogold.Name(t.Name()+"/step1"))
808+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
`{
2+
"role": "assistant",
3+
"content": [
4+
{
5+
"toolCall": {
6+
"index": 0,
7+
"id": "call_1",
8+
"function": {
9+
"name": "agent1"
10+
}
11+
}
12+
}
13+
],
14+
"usage": {}
15+
}`
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
`{
2+
"model": "gpt-4o",
3+
"internalSystemPrompt": false,
4+
"tools": [
5+
{
6+
"function": {
7+
"toolID": "testdata/TestAgents/test.gpt:agent1",
8+
"name": "agent1",
9+
"parameters": null
10+
}
11+
},
12+
{
13+
"function": {
14+
"toolID": "testdata/TestAgents/test.gpt:agent2",
15+
"name": "agent2",
16+
"parameters": null
17+
}
18+
}
19+
],
20+
"messages": [
21+
{
22+
"role": "system",
23+
"content": [
24+
{
25+
"text": "I'm the intro"
26+
}
27+
],
28+
"usage": {}
29+
},
30+
{
31+
"role": "user",
32+
"content": [
33+
{
34+
"text": "Input 1"
35+
}
36+
],
37+
"usage": {}
38+
}
39+
]
40+
}`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
`{
2+
"role": "assistant",
3+
"content": [
4+
{
5+
"toolCall": {
6+
"index": 0,
7+
"id": "call_2",
8+
"function": {
9+
"name": "agent2"
10+
}
11+
}
12+
}
13+
],
14+
"usage": {}
15+
}`
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
`{
2+
"model": "gpt-4o",
3+
"internalSystemPrompt": false,
4+
"tools": [
5+
{
6+
"function": {
7+
"toolID": "testdata/TestAgents/test.gpt:agent2",
8+
"name": "agent2",
9+
"parameters": null
10+
}
11+
}
12+
],
13+
"messages": [
14+
{
15+
"role": "system",
16+
"content": [
17+
{
18+
"text": "I am agent1"
19+
}
20+
],
21+
"usage": {}
22+
}
23+
]
24+
}`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
`{
2+
"role": "assistant",
3+
"content": [
4+
{
5+
"toolCall": {
6+
"index": 1,
7+
"id": "call_3",
8+
"function": {
9+
"name": "agent3"
10+
}
11+
}
12+
}
13+
],
14+
"usage": {}
15+
}`
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
`{
2+
"model": "gpt-4o",
3+
"internalSystemPrompt": false,
4+
"tools": [
5+
{
6+
"function": {
7+
"toolID": "testdata/TestAgents/test.gpt:agent1",
8+
"name": "agent1",
9+
"parameters": null
10+
}
11+
},
12+
{
13+
"function": {
14+
"toolID": "testdata/TestAgents/test.gpt:agent3",
15+
"name": "agent3",
16+
"parameters": null
17+
}
18+
}
19+
],
20+
"messages": [
21+
{
22+
"role": "system",
23+
"content": [
24+
{
25+
"text": "I am agent2"
26+
}
27+
],
28+
"usage": {}
29+
}
30+
]
31+
}`
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: 4"
6+
}
7+
],
8+
"usage": {}
9+
}`
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
`{
2+
"model": "gpt-4o",
3+
"internalSystemPrompt": false,
4+
"messages": [
5+
{
6+
"role": "system",
7+
"content": [
8+
{
9+
"text": "I am agent3"
10+
}
11+
],
12+
"usage": {}
13+
}
14+
]
15+
}`

0 commit comments

Comments
 (0)