From 8f9db008530951493aef8b74450eba779a76ec15 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Tue, 4 Jun 2024 12:52:05 -0700 Subject: [PATCH 1/3] feat: add agents field --- pkg/engine/engine.go | 17 +- pkg/loader/loader.go | 7 +- pkg/parser/parser.go | 2 + pkg/tests/runner_test.go | 28 ++ .../testdata/TestAgents/call1-resp.golden | 15 + pkg/tests/testdata/TestAgents/call1.golden | 40 +++ .../testdata/TestAgents/call2-resp.golden | 15 + pkg/tests/testdata/TestAgents/call2.golden | 24 ++ .../testdata/TestAgents/call3-resp.golden | 15 + pkg/tests/testdata/TestAgents/call3.golden | 31 +++ .../testdata/TestAgents/call4-resp.golden | 9 + pkg/tests/testdata/TestAgents/call4.golden | 15 + pkg/tests/testdata/TestAgents/step1.golden | 259 ++++++++++++++++++ pkg/tests/testdata/TestAgents/test.gpt | 23 ++ pkg/tests/tester/runner.go | 11 +- pkg/types/set.go | 9 + pkg/types/tool.go | 69 ++++- 17 files changed, 573 insertions(+), 16 deletions(-) create mode 100644 pkg/tests/testdata/TestAgents/call1-resp.golden create mode 100644 pkg/tests/testdata/TestAgents/call1.golden create mode 100644 pkg/tests/testdata/TestAgents/call2-resp.golden create mode 100644 pkg/tests/testdata/TestAgents/call2.golden create mode 100644 pkg/tests/testdata/TestAgents/call3-resp.golden create mode 100644 pkg/tests/testdata/TestAgents/call3.golden create mode 100644 pkg/tests/testdata/TestAgents/call4-resp.golden create mode 100644 pkg/tests/testdata/TestAgents/call4.golden create mode 100644 pkg/tests/testdata/TestAgents/step1.golden create mode 100644 pkg/tests/testdata/TestAgents/test.gpt diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 14647c0b..6f33ef3b 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -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 { @@ -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, @@ -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 } diff --git a/pkg/loader/loader.go b/pkg/loader/loader.go index 06370440..76ae0323 100644 --- a/pkg/loader/loader.go +++ b/pkg/loader/loader.go @@ -11,7 +11,6 @@ import ( "os" "path" "path/filepath" - "slices" "strconv" "strings" "time" @@ -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 { diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index ccc3dcb8..af06c95a 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -104,6 +104,8 @@ func isParam(line string, tool *types.Tool) (_ bool, err error) { 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": diff --git a/pkg/tests/runner_test.go b/pkg/tests/runner_test.go index 1f74beca..9470662c 100644 --- a/pkg/tests/runner_test.go +++ b/pkg/tests/runner_test.go @@ -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")) +} diff --git a/pkg/tests/testdata/TestAgents/call1-resp.golden b/pkg/tests/testdata/TestAgents/call1-resp.golden new file mode 100644 index 00000000..dd44bfcd --- /dev/null +++ b/pkg/tests/testdata/TestAgents/call1-resp.golden @@ -0,0 +1,15 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 0, + "id": "call_1", + "function": { + "name": "agent1" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestAgents/call1.golden b/pkg/tests/testdata/TestAgents/call1.golden new file mode 100644 index 00000000..a4c9d565 --- /dev/null +++ b/pkg/tests/testdata/TestAgents/call1.golden @@ -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": {} + } + ] +}` diff --git a/pkg/tests/testdata/TestAgents/call2-resp.golden b/pkg/tests/testdata/TestAgents/call2-resp.golden new file mode 100644 index 00000000..7601b7ae --- /dev/null +++ b/pkg/tests/testdata/TestAgents/call2-resp.golden @@ -0,0 +1,15 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 0, + "id": "call_2", + "function": { + "name": "agent2" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestAgents/call2.golden b/pkg/tests/testdata/TestAgents/call2.golden new file mode 100644 index 00000000..b7f53512 --- /dev/null +++ b/pkg/tests/testdata/TestAgents/call2.golden @@ -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": {} + } + ] +}` diff --git a/pkg/tests/testdata/TestAgents/call3-resp.golden b/pkg/tests/testdata/TestAgents/call3-resp.golden new file mode 100644 index 00000000..e2a65c99 --- /dev/null +++ b/pkg/tests/testdata/TestAgents/call3-resp.golden @@ -0,0 +1,15 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 1, + "id": "call_3", + "function": { + "name": "agent3" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestAgents/call3.golden b/pkg/tests/testdata/TestAgents/call3.golden new file mode 100644 index 00000000..5b6b3b87 --- /dev/null +++ b/pkg/tests/testdata/TestAgents/call3.golden @@ -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": {} + } + ] +}` diff --git a/pkg/tests/testdata/TestAgents/call4-resp.golden b/pkg/tests/testdata/TestAgents/call4-resp.golden new file mode 100644 index 00000000..8135a8c9 --- /dev/null +++ b/pkg/tests/testdata/TestAgents/call4-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 4" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestAgents/call4.golden b/pkg/tests/testdata/TestAgents/call4.golden new file mode 100644 index 00000000..038fa68c --- /dev/null +++ b/pkg/tests/testdata/TestAgents/call4.golden @@ -0,0 +1,15 @@ +`{ + "model": "gpt-4o", + "internalSystemPrompt": false, + "messages": [ + { + "role": "system", + "content": [ + { + "text": "I am agent3" + } + ], + "usage": {} + } + ] +}` diff --git a/pkg/tests/testdata/TestAgents/step1.golden b/pkg/tests/testdata/TestAgents/step1.golden new file mode 100644 index 00000000..59f11e22 --- /dev/null +++ b/pkg/tests/testdata/TestAgents/step1.golden @@ -0,0 +1,259 @@ +`{ + "done": false, + "content": "TEST RESULT CALL: 4", + "toolID": "testdata/TestAgents/test.gpt:agent3", + "state": { + "continuation": { + "state": { + "input": "Input 1", + "completion": { + "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": {} + }, + { + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 0, + "id": "call_1", + "function": { + "name": "agent1" + } + } + } + ], + "usage": {} + } + ] + }, + "pending": { + "call_1": { + "index": 0, + "id": "call_1", + "function": { + "name": "agent1" + } + } + } + }, + "calls": { + "call_1": { + "toolID": "testdata/TestAgents/test.gpt:agent1" + } + } + }, + "subCalls": [ + { + "toolId": "testdata/TestAgents/test.gpt:agent1", + "callId": "call_1", + "state": { + "continuation": { + "state": { + "completion": { + "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": {} + }, + { + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 0, + "id": "call_2", + "function": { + "name": "agent2" + } + } + } + ], + "usage": {} + } + ] + }, + "pending": { + "call_2": { + "index": 0, + "id": "call_2", + "function": { + "name": "agent2" + } + } + } + }, + "calls": { + "call_2": { + "toolID": "testdata/TestAgents/test.gpt:agent2" + } + } + }, + "subCalls": [ + { + "toolId": "testdata/TestAgents/test.gpt:agent2", + "callId": "call_2", + "state": { + "continuation": { + "state": { + "completion": { + "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": {} + }, + { + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 1, + "id": "call_3", + "function": { + "name": "agent3" + } + } + } + ], + "usage": {} + } + ] + }, + "pending": { + "call_3": { + "index": 1, + "id": "call_3", + "function": { + "name": "agent3" + } + } + } + }, + "calls": { + "call_3": { + "toolID": "testdata/TestAgents/test.gpt:agent3" + } + } + }, + "subCalls": [ + { + "toolId": "testdata/TestAgents/test.gpt:agent3", + "callId": "call_3", + "state": { + "continuation": { + "state": { + "completion": { + "model": "gpt-4o", + "internalSystemPrompt": false, + "messages": [ + { + "role": "system", + "content": [ + { + "text": "I am agent3" + } + ], + "usage": {} + }, + { + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 4" + } + ], + "usage": {} + } + ] + } + }, + "result": "TEST RESULT CALL: 4" + }, + "continuationToolID": "testdata/TestAgents/test.gpt:agent3" + } + } + ], + "subCallID": "call_3" + } + } + ], + "subCallID": "call_2" + } + } + ], + "subCallID": "call_1" + } +}` diff --git a/pkg/tests/testdata/TestAgents/test.gpt b/pkg/tests/testdata/TestAgents/test.gpt new file mode 100644 index 00000000..3f6f8e19 --- /dev/null +++ b/pkg/tests/testdata/TestAgents/test.gpt @@ -0,0 +1,23 @@ +agents: agent1, agent2 +chat: true + +I'm the intro + +---- +name: agent1 +chat: true + +I am agent1 + +---- +name: agent2 +chat: true +agents: agent3 + +I am agent2 + +--- +name: agent3 +chat: true + +I am agent3 \ No newline at end of file diff --git a/pkg/tests/tester/runner.go b/pkg/tests/tester/runner.go index 16c4d43e..cb3e58f2 100644 --- a/pkg/tests/tester/runner.go +++ b/pkg/tests/tester/runner.go @@ -28,7 +28,7 @@ type Result struct { Err error } -func (c *Client) Call(_ context.Context, messageRequest types.CompletionRequest, _ chan<- types.CompletionStatus) (*types.CompletionMessage, error) { +func (c *Client) Call(_ context.Context, messageRequest types.CompletionRequest, _ chan<- types.CompletionStatus) (resp *types.CompletionMessage, respErr error) { msgData, err := json.MarshalIndent(messageRequest, "", " ") require.NoError(c.t, err) @@ -39,6 +39,15 @@ func (c *Client) Call(_ context.Context, messageRequest types.CompletionRequest, c.t.Run(fmt.Sprintf("call%d", c.id), func(t *testing.T) { autogold.ExpectFile(t, string(msgData)) }) + defer func() { + if respErr == nil { + c.t.Run(fmt.Sprintf("call%d-resp", c.id), func(t *testing.T) { + msgData, err := json.MarshalIndent(resp, "", " ") + require.NoError(c.t, err) + autogold.ExpectFile(t, string(msgData)) + }) + } + }() } if len(c.result) == 0 { return &types.CompletionMessage{ diff --git a/pkg/types/set.go b/pkg/types/set.go index e8467b3a..9ff6b22e 100644 --- a/pkg/types/set.go +++ b/pkg/types/set.go @@ -19,6 +19,15 @@ func (t *toolRefSet) List() (result []ToolReference, err error) { return result, t.err } +func (t *toolRefSet) HasTool(toolID string) bool { + for _, ref := range t.set { + if ref.ToolID == toolID { + return true + } + } + return false +} + func (t *toolRefSet) AddAll(values []ToolReference, err error) { if t.err != nil { t.err = err diff --git a/pkg/types/tool.go b/pkg/types/tool.go index 612543fe..a7f7314d 100644 --- a/pkg/types/tool.go +++ b/pkg/types/tool.go @@ -124,10 +124,21 @@ type Parameters struct { Context []string `json:"context,omitempty"` ExportContext []string `json:"exportContext,omitempty"` Export []string `json:"export,omitempty"` + Agents []string `json:"agents,omitempty"` Credentials []string `json:"credentials,omitempty"` Blocking bool `json:"-"` } +func (p Parameters) ToolRefNames() []string { + return slices.Concat( + p.Tools, + p.Agents, + p.Export, + p.ExportContext, + p.Context, + p.Credentials) +} + type ToolDef struct { Parameters `json:",inline"` Instructions string `json:"instructions,omitempty"` @@ -240,7 +251,7 @@ func (t ToolDef) String() string { _, _ = fmt.Fprintf(buf, "Tools: %s\n", strings.Join(t.Parameters.Tools, ", ")) } if len(t.Parameters.Export) != 0 { - _, _ = fmt.Fprintf(buf, "Export: %s\n", strings.Join(t.Parameters.Export, ", ")) + _, _ = fmt.Fprintf(buf, "Export Tools: %s\n", strings.Join(t.Parameters.Export, ", ")) } if len(t.Parameters.ExportContext) != 0 { _, _ = fmt.Fprintf(buf, "Export Context: %s\n", strings.Join(t.Parameters.ExportContext, ", ")) @@ -346,14 +357,53 @@ func (t Tool) GetContextTools(prg Program) ([]ToolReference, error) { return result.List() } -func (t Tool) GetCompletionTools(prg Program) (result []CompletionTool, err error) { - refs, err := t.getCompletionToolRefs(prg) +func (t Tool) GetAgentGroup(agentGroup []ToolReference, toolID string) (result []ToolReference, _ error) { + newAgentGroup := toolRefSet{} + if err := t.addAgents(&newAgentGroup); err != nil { + return nil, err + } + + if newAgentGroup.HasTool(toolID) { + // Join new agent group + return newAgentGroup.List() + } + + existingAgentGroup := toolRefSet{} + existingAgentGroup.AddAll(agentGroup, nil) + + if existingAgentGroup.HasTool(toolID) { + return existingAgentGroup.List() + } + + // No group + return nil, nil +} + +func (t Tool) GetCompletionTools(prg Program, agentGroup ...ToolReference) (result []CompletionTool, err error) { + refs, err := t.getCompletionToolRefs(prg, agentGroup) if err != nil { return nil, err } return toolRefsToCompletionTools(refs, prg), nil } +func (t Tool) addAgents(result *toolRefSet) error { + subToolRefs, err := t.GetToolRefsFromNames(t.Parameters.Agents) + if err != nil { + return err + } + + for _, subToolRef := range subToolRefs { + // don't add yourself + if subToolRef.ToolID != t.ID { + // Add the tool itself and no exports + result.Add(subToolRef) + } + } + + return nil +} + func (t Tool) addReferencedTools(prg Program, result *toolRefSet) error { subToolRefs, err := t.GetToolRefsFromNames(t.Parameters.Tools) if err != nil { @@ -384,9 +434,16 @@ func (t Tool) addContextExportedTools(prg Program, result *toolRefSet) error { return nil } -func (t Tool) getCompletionToolRefs(prg Program) ([]ToolReference, error) { +func (t Tool) getCompletionToolRefs(prg Program, agentGroup []ToolReference) ([]ToolReference, error) { result := toolRefSet{} + for _, agent := range agentGroup { + // don't add yourself + if agent.ToolID != t.ID { + result.Add(agent) + } + } + if err := t.addReferencedTools(prg, &result); err != nil { return nil, err } @@ -395,6 +452,10 @@ func (t Tool) getCompletionToolRefs(prg Program) ([]ToolReference, error) { return nil, err } + if err := t.addAgents(&result); err != nil { + return nil, err + } + return result.List() } From f2972f765c9f11ccefa8e7595c28dbb9889919c3 Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Tue, 4 Jun 2024 12:53:13 -0700 Subject: [PATCH 2/3] chore: update tests --- .../testdata/TestAsterick/call1-resp.golden | 9 +++++++ pkg/tests/testdata/TestCase/call1-resp.golden | 9 +++++++ .../testdata/TestCase2/call1-resp.golden | 9 +++++++ pkg/tests/testdata/TestChat/call1-resp.golden | 9 +++++++ pkg/tests/testdata/TestChat/call2-resp.golden | 9 +++++++ .../TestChatRunNoError/call1-resp.golden | 9 +++++++ .../testdata/TestContext/call1-resp.golden | 9 +++++++ .../testdata/TestContextArg/call1-resp.golden | 9 +++++++ .../TestContextSubChat/call1-resp.golden | 16 ++++++++++++ .../TestContextSubChat/call10-resp.golden | 9 +++++++ .../TestContextSubChat/call2-resp.golden | 9 +++++++ .../TestContextSubChat/call3-resp.golden | 16 ++++++++++++ .../TestContextSubChat/call4-resp.golden | 9 +++++++ .../TestContextSubChat/call5-resp.golden | 9 +++++++ .../TestContextSubChat/call6-resp.golden | 16 ++++++++++++ .../TestContextSubChat/call7-resp.golden | 9 +++++++ .../TestContextSubChat/call8-resp.golden | 16 ++++++++++++ .../TestContextSubChat/call9-resp.golden | 9 +++++++ pkg/tests/testdata/TestCwd/call1-resp.golden | 15 +++++++++++ pkg/tests/testdata/TestCwd/call2-resp.golden | 15 +++++++++++ pkg/tests/testdata/TestCwd/call3-resp.golden | 9 +++++++ .../TestDualSubChat/call1-resp.golden | 26 +++++++++++++++++++ .../TestDualSubChat/call2-resp.golden | 9 +++++++ .../TestDualSubChat/call3-resp.golden | 9 +++++++ .../TestDualSubChat/call4-resp.golden | 16 ++++++++++++ .../TestDualSubChat/call5-resp.golden | 9 +++++++ .../TestDualSubChat/call6-resp.golden | 16 ++++++++++++ .../TestDualSubChat/call7-resp.golden | 9 +++++++ .../testdata/TestExport/call1-resp.golden | 15 +++++++++++ .../testdata/TestExport/call2-resp.golden | 9 +++++++ .../testdata/TestExport/call3-resp.golden | 9 +++++++ .../TestExportContext/call1-resp.golden | 9 +++++++ .../testdata/TestSubChat/call1-resp.golden | 15 +++++++++++ .../testdata/TestSubChat/call2-resp.golden | 9 +++++++ .../testdata/TestSubChat/call3-resp.golden | 9 +++++++ .../testdata/TestToolAs/call1-resp.golden | 9 +++++++ 36 files changed, 407 insertions(+) create mode 100644 pkg/tests/testdata/TestAsterick/call1-resp.golden create mode 100644 pkg/tests/testdata/TestCase/call1-resp.golden create mode 100644 pkg/tests/testdata/TestCase2/call1-resp.golden create mode 100644 pkg/tests/testdata/TestChat/call1-resp.golden create mode 100644 pkg/tests/testdata/TestChat/call2-resp.golden create mode 100644 pkg/tests/testdata/TestChatRunNoError/call1-resp.golden create mode 100644 pkg/tests/testdata/TestContext/call1-resp.golden create mode 100644 pkg/tests/testdata/TestContextArg/call1-resp.golden create mode 100644 pkg/tests/testdata/TestContextSubChat/call1-resp.golden create mode 100644 pkg/tests/testdata/TestContextSubChat/call10-resp.golden create mode 100644 pkg/tests/testdata/TestContextSubChat/call2-resp.golden create mode 100644 pkg/tests/testdata/TestContextSubChat/call3-resp.golden create mode 100644 pkg/tests/testdata/TestContextSubChat/call4-resp.golden create mode 100644 pkg/tests/testdata/TestContextSubChat/call5-resp.golden create mode 100644 pkg/tests/testdata/TestContextSubChat/call6-resp.golden create mode 100644 pkg/tests/testdata/TestContextSubChat/call7-resp.golden create mode 100644 pkg/tests/testdata/TestContextSubChat/call8-resp.golden create mode 100644 pkg/tests/testdata/TestContextSubChat/call9-resp.golden create mode 100644 pkg/tests/testdata/TestCwd/call1-resp.golden create mode 100644 pkg/tests/testdata/TestCwd/call2-resp.golden create mode 100644 pkg/tests/testdata/TestCwd/call3-resp.golden create mode 100644 pkg/tests/testdata/TestDualSubChat/call1-resp.golden create mode 100644 pkg/tests/testdata/TestDualSubChat/call2-resp.golden create mode 100644 pkg/tests/testdata/TestDualSubChat/call3-resp.golden create mode 100644 pkg/tests/testdata/TestDualSubChat/call4-resp.golden create mode 100644 pkg/tests/testdata/TestDualSubChat/call5-resp.golden create mode 100644 pkg/tests/testdata/TestDualSubChat/call6-resp.golden create mode 100644 pkg/tests/testdata/TestDualSubChat/call7-resp.golden create mode 100644 pkg/tests/testdata/TestExport/call1-resp.golden create mode 100644 pkg/tests/testdata/TestExport/call2-resp.golden create mode 100644 pkg/tests/testdata/TestExport/call3-resp.golden create mode 100644 pkg/tests/testdata/TestExportContext/call1-resp.golden create mode 100644 pkg/tests/testdata/TestSubChat/call1-resp.golden create mode 100644 pkg/tests/testdata/TestSubChat/call2-resp.golden create mode 100644 pkg/tests/testdata/TestSubChat/call3-resp.golden create mode 100644 pkg/tests/testdata/TestToolAs/call1-resp.golden diff --git a/pkg/tests/testdata/TestAsterick/call1-resp.golden b/pkg/tests/testdata/TestAsterick/call1-resp.golden new file mode 100644 index 00000000..90a65f4c --- /dev/null +++ b/pkg/tests/testdata/TestAsterick/call1-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "hi" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestCase/call1-resp.golden b/pkg/tests/testdata/TestCase/call1-resp.golden new file mode 100644 index 00000000..2861a036 --- /dev/null +++ b/pkg/tests/testdata/TestCase/call1-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 1" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestCase2/call1-resp.golden b/pkg/tests/testdata/TestCase2/call1-resp.golden new file mode 100644 index 00000000..2861a036 --- /dev/null +++ b/pkg/tests/testdata/TestCase2/call1-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 1" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestChat/call1-resp.golden b/pkg/tests/testdata/TestChat/call1-resp.golden new file mode 100644 index 00000000..9b71977e --- /dev/null +++ b/pkg/tests/testdata/TestChat/call1-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "Assistant 1" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestChat/call2-resp.golden b/pkg/tests/testdata/TestChat/call2-resp.golden new file mode 100644 index 00000000..7949ebe2 --- /dev/null +++ b/pkg/tests/testdata/TestChat/call2-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "Assistant 2" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestChatRunNoError/call1-resp.golden b/pkg/tests/testdata/TestChatRunNoError/call1-resp.golden new file mode 100644 index 00000000..2861a036 --- /dev/null +++ b/pkg/tests/testdata/TestChatRunNoError/call1-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 1" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestContext/call1-resp.golden b/pkg/tests/testdata/TestContext/call1-resp.golden new file mode 100644 index 00000000..2861a036 --- /dev/null +++ b/pkg/tests/testdata/TestContext/call1-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 1" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestContextArg/call1-resp.golden b/pkg/tests/testdata/TestContextArg/call1-resp.golden new file mode 100644 index 00000000..2861a036 --- /dev/null +++ b/pkg/tests/testdata/TestContextArg/call1-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 1" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestContextSubChat/call1-resp.golden b/pkg/tests/testdata/TestContextSubChat/call1-resp.golden new file mode 100644 index 00000000..77a4c315 --- /dev/null +++ b/pkg/tests/testdata/TestContextSubChat/call1-resp.golden @@ -0,0 +1,16 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 0, + "id": "call_1", + "function": { + "name": "chatbot", + "arguments": "Input to chatbot1" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestContextSubChat/call10-resp.golden b/pkg/tests/testdata/TestContextSubChat/call10-resp.golden new file mode 100644 index 00000000..144ca8d9 --- /dev/null +++ b/pkg/tests/testdata/TestContextSubChat/call10-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "Assistant Response 6 - from main chat tool resume" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestContextSubChat/call2-resp.golden b/pkg/tests/testdata/TestContextSubChat/call2-resp.golden new file mode 100644 index 00000000..3e889cbf --- /dev/null +++ b/pkg/tests/testdata/TestContextSubChat/call2-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "Assistant Response 1 - from chatbot1" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestContextSubChat/call3-resp.golden b/pkg/tests/testdata/TestContextSubChat/call3-resp.golden new file mode 100644 index 00000000..b116d066 --- /dev/null +++ b/pkg/tests/testdata/TestContextSubChat/call3-resp.golden @@ -0,0 +1,16 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 0, + "id": "call_2", + "function": { + "name": "chatFinish", + "arguments": "Response from context chatbot" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestContextSubChat/call4-resp.golden b/pkg/tests/testdata/TestContextSubChat/call4-resp.golden new file mode 100644 index 00000000..a86ae187 --- /dev/null +++ b/pkg/tests/testdata/TestContextSubChat/call4-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "Assistant Response 2 - from context tool" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestContextSubChat/call5-resp.golden b/pkg/tests/testdata/TestContextSubChat/call5-resp.golden new file mode 100644 index 00000000..e49a8481 --- /dev/null +++ b/pkg/tests/testdata/TestContextSubChat/call5-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "Assistant Response 3 - from main chat tool" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestContextSubChat/call6-resp.golden b/pkg/tests/testdata/TestContextSubChat/call6-resp.golden new file mode 100644 index 00000000..6807fce9 --- /dev/null +++ b/pkg/tests/testdata/TestContextSubChat/call6-resp.golden @@ -0,0 +1,16 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 0, + "id": "call_3", + "function": { + "name": "chatbot", + "arguments": "Input to chatbot1 on resume" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestContextSubChat/call7-resp.golden b/pkg/tests/testdata/TestContextSubChat/call7-resp.golden new file mode 100644 index 00000000..3e0c5f3c --- /dev/null +++ b/pkg/tests/testdata/TestContextSubChat/call7-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "Assistant Response 4 - from chatbot1" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestContextSubChat/call8-resp.golden b/pkg/tests/testdata/TestContextSubChat/call8-resp.golden new file mode 100644 index 00000000..2e608b31 --- /dev/null +++ b/pkg/tests/testdata/TestContextSubChat/call8-resp.golden @@ -0,0 +1,16 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 0, + "id": "call_4", + "function": { + "name": "chatFinish", + "arguments": "Response from context chatbot after resume" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestContextSubChat/call9-resp.golden b/pkg/tests/testdata/TestContextSubChat/call9-resp.golden new file mode 100644 index 00000000..4424246d --- /dev/null +++ b/pkg/tests/testdata/TestContextSubChat/call9-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "Assistant Response 5 - from context tool resume" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestCwd/call1-resp.golden b/pkg/tests/testdata/TestCwd/call1-resp.golden new file mode 100644 index 00000000..5432061d --- /dev/null +++ b/pkg/tests/testdata/TestCwd/call1-resp.golden @@ -0,0 +1,15 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 0, + "id": "call_1", + "function": { + "name": "test" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestCwd/call2-resp.golden b/pkg/tests/testdata/TestCwd/call2-resp.golden new file mode 100644 index 00000000..b1e6cc34 --- /dev/null +++ b/pkg/tests/testdata/TestCwd/call2-resp.golden @@ -0,0 +1,15 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 1, + "id": "call_2", + "function": { + "name": "local" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestCwd/call3-resp.golden b/pkg/tests/testdata/TestCwd/call3-resp.golden new file mode 100644 index 00000000..5914e98d --- /dev/null +++ b/pkg/tests/testdata/TestCwd/call3-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 3" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestDualSubChat/call1-resp.golden b/pkg/tests/testdata/TestDualSubChat/call1-resp.golden new file mode 100644 index 00000000..4e9b9bd6 --- /dev/null +++ b/pkg/tests/testdata/TestDualSubChat/call1-resp.golden @@ -0,0 +1,26 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 0, + "id": "call_1", + "function": { + "name": "chatbot", + "arguments": "Input to chatbot1" + } + } + }, + { + "toolCall": { + "index": 1, + "id": "call_2", + "function": { + "name": "chatbot2", + "arguments": "Input to chatbot2" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestDualSubChat/call2-resp.golden b/pkg/tests/testdata/TestDualSubChat/call2-resp.golden new file mode 100644 index 00000000..3e889cbf --- /dev/null +++ b/pkg/tests/testdata/TestDualSubChat/call2-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "Assistant Response 1 - from chatbot1" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestDualSubChat/call3-resp.golden b/pkg/tests/testdata/TestDualSubChat/call3-resp.golden new file mode 100644 index 00000000..986f6c69 --- /dev/null +++ b/pkg/tests/testdata/TestDualSubChat/call3-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "Assistent Response 2 - from chatbot2" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestDualSubChat/call4-resp.golden b/pkg/tests/testdata/TestDualSubChat/call4-resp.golden new file mode 100644 index 00000000..12a37ebb --- /dev/null +++ b/pkg/tests/testdata/TestDualSubChat/call4-resp.golden @@ -0,0 +1,16 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 0, + "id": "call_4", + "function": { + "name": "chatFinish", + "arguments": "{\"return\":\"Chat done\"}" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestDualSubChat/call5-resp.golden b/pkg/tests/testdata/TestDualSubChat/call5-resp.golden new file mode 100644 index 00000000..e29d9d1e --- /dev/null +++ b/pkg/tests/testdata/TestDualSubChat/call5-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "Assistant 3" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestDualSubChat/call6-resp.golden b/pkg/tests/testdata/TestDualSubChat/call6-resp.golden new file mode 100644 index 00000000..ab8aba96 --- /dev/null +++ b/pkg/tests/testdata/TestDualSubChat/call6-resp.golden @@ -0,0 +1,16 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 0, + "id": "call_6", + "function": { + "name": "chatFinish", + "arguments": "{\"return\":\"Chat done2\"}" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestDualSubChat/call7-resp.golden b/pkg/tests/testdata/TestDualSubChat/call7-resp.golden new file mode 100644 index 00000000..694aac27 --- /dev/null +++ b/pkg/tests/testdata/TestDualSubChat/call7-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "And we're done" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestExport/call1-resp.golden b/pkg/tests/testdata/TestExport/call1-resp.golden new file mode 100644 index 00000000..8462d188 --- /dev/null +++ b/pkg/tests/testdata/TestExport/call1-resp.golden @@ -0,0 +1,15 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 2, + "id": "call_1", + "function": { + "name": "transient" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestExport/call2-resp.golden b/pkg/tests/testdata/TestExport/call2-resp.golden new file mode 100644 index 00000000..997ca1b9 --- /dev/null +++ b/pkg/tests/testdata/TestExport/call2-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 2" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestExport/call3-resp.golden b/pkg/tests/testdata/TestExport/call3-resp.golden new file mode 100644 index 00000000..5914e98d --- /dev/null +++ b/pkg/tests/testdata/TestExport/call3-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 3" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestExportContext/call1-resp.golden b/pkg/tests/testdata/TestExportContext/call1-resp.golden new file mode 100644 index 00000000..2861a036 --- /dev/null +++ b/pkg/tests/testdata/TestExportContext/call1-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 1" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestSubChat/call1-resp.golden b/pkg/tests/testdata/TestSubChat/call1-resp.golden new file mode 100644 index 00000000..0b016a6d --- /dev/null +++ b/pkg/tests/testdata/TestSubChat/call1-resp.golden @@ -0,0 +1,15 @@ +`{ + "role": "assistant", + "content": [ + { + "toolCall": { + "index": 0, + "id": "call_1", + "function": { + "name": "chatbot" + } + } + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestSubChat/call2-resp.golden b/pkg/tests/testdata/TestSubChat/call2-resp.golden new file mode 100644 index 00000000..9b71977e --- /dev/null +++ b/pkg/tests/testdata/TestSubChat/call2-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "Assistant 1" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestSubChat/call3-resp.golden b/pkg/tests/testdata/TestSubChat/call3-resp.golden new file mode 100644 index 00000000..7949ebe2 --- /dev/null +++ b/pkg/tests/testdata/TestSubChat/call3-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "Assistant 2" + } + ], + "usage": {} +}` diff --git a/pkg/tests/testdata/TestToolAs/call1-resp.golden b/pkg/tests/testdata/TestToolAs/call1-resp.golden new file mode 100644 index 00000000..2861a036 --- /dev/null +++ b/pkg/tests/testdata/TestToolAs/call1-resp.golden @@ -0,0 +1,9 @@ +`{ + "role": "assistant", + "content": [ + { + "text": "TEST RESULT CALL: 1" + } + ], + "usage": {} +}` From bd7c4fa78edcf2add4062bae52ad0227d580a8ef Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Tue, 4 Jun 2024 13:25:46 -0700 Subject: [PATCH 3/3] chore: switch to share syntax --- pkg/parser/parser.go | 4 ++-- pkg/types/tool.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/parser/parser.go b/pkg/parser/parser.go index af06c95a..d0d1585f 100644 --- a/pkg/parser/parser.go +++ b/pkg/parser/parser.go @@ -100,7 +100,7 @@ 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)...) @@ -108,7 +108,7 @@ func isParam(line string, tool *types.Tool) (_ bool, err error) { 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)...) diff --git a/pkg/types/tool.go b/pkg/types/tool.go index a7f7314d..b93b0eb6 100644 --- a/pkg/types/tool.go +++ b/pkg/types/tool.go @@ -251,10 +251,10 @@ func (t ToolDef) String() string { _, _ = fmt.Fprintf(buf, "Tools: %s\n", strings.Join(t.Parameters.Tools, ", ")) } if len(t.Parameters.Export) != 0 { - _, _ = fmt.Fprintf(buf, "Export Tools: %s\n", strings.Join(t.Parameters.Export, ", ")) + _, _ = fmt.Fprintf(buf, "Share Tools: %s\n", strings.Join(t.Parameters.Export, ", ")) } if len(t.Parameters.ExportContext) != 0 { - _, _ = fmt.Fprintf(buf, "Export Context: %s\n", strings.Join(t.Parameters.ExportContext, ", ")) + _, _ = fmt.Fprintf(buf, "Share Context: %s\n", strings.Join(t.Parameters.ExportContext, ", ")) } if len(t.Parameters.Context) != 0 { _, _ = fmt.Fprintf(buf, "Context: %s\n", strings.Join(t.Parameters.Context, ", "))