Skip to content

feat: add agents field #434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ type CallResult struct {
}

type commonContext struct {
ID string `json:"id"`
Tool types.Tool `json:"tool"`
InputContext []InputContext `json:"inputContext"`
ToolCategory ToolCategory `json:"toolCategory,omitempty"`
ID string `json:"id"`
Tool types.Tool `json:"tool"`
AgentGroup []types.ToolReference `json:"agentGroup,omitempty"`
InputContext []InputContext `json:"inputContext"`
ToolCategory ToolCategory `json:"toolCategory,omitempty"`
}

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

agentGroup, err := c.Tool.GetAgentGroup(c.AgentGroup, toolID)
if err != nil {
return Context{}, err
}

return Context{
commonContext: commonContext{
ID: callID,
Tool: tool,
AgentGroup: agentGroup,
ToolCategory: toolCategory,
},
Ctx: ctx,
Expand Down Expand Up @@ -240,7 +247,7 @@ func (e *Engine) Start(ctx Context, input string) (ret *Return, _ error) {
}

var err error
completion.Tools, err = tool.GetCompletionTools(*ctx.Program)
completion.Tools, err = tool.GetCompletionTools(*ctx.Program, ctx.AgentGroup...)
if err != nil {
return nil, err
}
Expand Down
7 changes: 1 addition & 6 deletions pkg/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"os"
"path"
"path/filepath"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -320,11 +319,7 @@ func link(ctx context.Context, cache *cache.Client, prg *types.Program, base *so
// The below is done in two loops so that local names stay as the tool names
// and don't get mangled by external references

for _, targetToolName := range slices.Concat(tool.Parameters.Tools,
tool.Parameters.Export,
tool.Parameters.ExportContext,
tool.Parameters.Context,
tool.Parameters.Credentials) {
for _, targetToolName := range tool.Parameters.ToolRefNames() {
noArgs, _ := types.SplitArg(targetToolName)
localTool, ok := localTools[strings.ToLower(noArgs)]
if ok {
Expand Down
6 changes: 4 additions & 2 deletions pkg/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,15 @@ func isParam(line string, tool *types.Tool) (_ bool, err error) {
return false, err
}
tool.Parameters.Chat = v
case "export", "exporttool", "exports", "exporttools":
case "export", "exporttool", "exports", "exporttools", "sharetool", "sharetools":
tool.Parameters.Export = append(tool.Parameters.Export, csv(value)...)
case "tool", "tools":
tool.Parameters.Tools = append(tool.Parameters.Tools, csv(value)...)
case "agent", "agents":
tool.Parameters.Agents = append(tool.Parameters.Agents, csv(value)...)
case "globaltool", "globaltools":
tool.Parameters.GlobalTools = append(tool.Parameters.GlobalTools, csv(value)...)
case "exportcontext", "exportcontexts":
case "exportcontext", "exportcontexts", "sharecontext", "sharecontexts":
tool.Parameters.ExportContext = append(tool.Parameters.ExportContext, csv(value)...)
case "context":
tool.Parameters.Context = append(tool.Parameters.Context, csv(value)...)
Expand Down
28 changes: 28 additions & 0 deletions pkg/tests/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,3 +778,31 @@ func TestExport(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, "TEST RESULT CALL: 3", x)
}

func TestAgents(t *testing.T) {
r := tester.NewRunner(t)

prg, err := r.Load("")
require.NoError(t, err)

r.RespondWith(tester.Result{
Func: types.CompletionFunctionCall{
Name: "agent1",
},
}, tester.Result{
Func: types.CompletionFunctionCall{
Name: "agent2",
},
}, tester.Result{
Func: types.CompletionFunctionCall{
Name: "agent3",
},
})

resp, err := r.Chat(context.Background(), nil, prg, nil, "Input 1")
require.NoError(t, err)
r.AssertResponded(t)
assert.False(t, resp.Done)
autogold.Expect("TEST RESULT CALL: 4").Equal(t, resp.Content)
autogold.ExpectFile(t, toJSONString(t, resp), autogold.Name(t.Name()+"/step1"))
}
15 changes: 15 additions & 0 deletions pkg/tests/testdata/TestAgents/call1-resp.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
`{
"role": "assistant",
"content": [
{
"toolCall": {
"index": 0,
"id": "call_1",
"function": {
"name": "agent1"
}
}
}
],
"usage": {}
}`
40 changes: 40 additions & 0 deletions pkg/tests/testdata/TestAgents/call1.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
`{
"model": "gpt-4o",
"internalSystemPrompt": false,
"tools": [
{
"function": {
"toolID": "testdata/TestAgents/test.gpt:agent1",
"name": "agent1",
"parameters": null
}
},
{
"function": {
"toolID": "testdata/TestAgents/test.gpt:agent2",
"name": "agent2",
"parameters": null
}
}
],
"messages": [
{
"role": "system",
"content": [
{
"text": "I'm the intro"
}
],
"usage": {}
},
{
"role": "user",
"content": [
{
"text": "Input 1"
}
],
"usage": {}
}
]
}`
15 changes: 15 additions & 0 deletions pkg/tests/testdata/TestAgents/call2-resp.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
`{
"role": "assistant",
"content": [
{
"toolCall": {
"index": 0,
"id": "call_2",
"function": {
"name": "agent2"
}
}
}
],
"usage": {}
}`
24 changes: 24 additions & 0 deletions pkg/tests/testdata/TestAgents/call2.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
`{
"model": "gpt-4o",
"internalSystemPrompt": false,
"tools": [
{
"function": {
"toolID": "testdata/TestAgents/test.gpt:agent2",
"name": "agent2",
"parameters": null
}
}
],
"messages": [
{
"role": "system",
"content": [
{
"text": "I am agent1"
}
],
"usage": {}
}
]
}`
15 changes: 15 additions & 0 deletions pkg/tests/testdata/TestAgents/call3-resp.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
`{
"role": "assistant",
"content": [
{
"toolCall": {
"index": 1,
"id": "call_3",
"function": {
"name": "agent3"
}
}
}
],
"usage": {}
}`
31 changes: 31 additions & 0 deletions pkg/tests/testdata/TestAgents/call3.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
`{
"model": "gpt-4o",
"internalSystemPrompt": false,
"tools": [
{
"function": {
"toolID": "testdata/TestAgents/test.gpt:agent1",
"name": "agent1",
"parameters": null
}
},
{
"function": {
"toolID": "testdata/TestAgents/test.gpt:agent3",
"name": "agent3",
"parameters": null
}
}
],
"messages": [
{
"role": "system",
"content": [
{
"text": "I am agent2"
}
],
"usage": {}
}
]
}`
9 changes: 9 additions & 0 deletions pkg/tests/testdata/TestAgents/call4-resp.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
`{
"role": "assistant",
"content": [
{
"text": "TEST RESULT CALL: 4"
}
],
"usage": {}
}`
15 changes: 15 additions & 0 deletions pkg/tests/testdata/TestAgents/call4.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
`{
"model": "gpt-4o",
"internalSystemPrompt": false,
"messages": [
{
"role": "system",
"content": [
{
"text": "I am agent3"
}
],
"usage": {}
}
]
}`
Loading