From 22c5d9b597a835aef6aa5c2bdb8bd82cedeca45b Mon Sep 17 00:00:00 2001 From: Darren Shepherd Date: Mon, 24 Jun 2024 16:01:35 -0700 Subject: [PATCH] chore: add sys.chat.current --- go.mod | 3 +- go.sum | 6 +- pkg/builtin/builtin.go | 32 +++++++++++ pkg/cli/gptscript.go | 2 +- pkg/engine/engine.go | 37 +++++++++--- pkg/openai/client.go | 5 ++ pkg/openai/count.go | 57 +++++++++++++++++++ pkg/runner/output.go | 1 - pkg/runner/runner.go | 2 + pkg/tests/runner_test.go | 18 +++--- pkg/tests/testdata/TestAgents/call1.golden | 3 +- pkg/tests/testdata/TestAgents/call2.golden | 3 +- pkg/tests/testdata/TestAgents/call3.golden | 3 +- pkg/tests/testdata/TestAgents/call4.golden | 3 +- pkg/tests/testdata/TestAgents/step1.golden | 12 ++-- pkg/tests/testdata/TestChat/call1.golden | 3 +- pkg/tests/testdata/TestChat/call2.golden | 3 +- .../testdata/TestChatRunNoError/call1.golden | 3 +- .../testdata/TestContextSubChat/call10.golden | 3 +- .../testdata/TestContextSubChat/call2.golden | 3 +- .../testdata/TestContextSubChat/call3.golden | 3 +- .../testdata/TestContextSubChat/call5.golden | 3 +- .../testdata/TestContextSubChat/call7.golden | 3 +- .../testdata/TestContextSubChat/call8.golden | 3 +- .../testdata/TestContextSubChat/step1.golden | 3 +- .../testdata/TestContextSubChat/step2.golden | 3 +- .../testdata/TestContextSubChat/step3.golden | 6 +- .../testdata/TestContextSubChat/step4.golden | 3 +- .../testdata/TestDualSubChat/call2.golden | 3 +- .../testdata/TestDualSubChat/call3.golden | 3 +- .../testdata/TestDualSubChat/call4.golden | 3 +- .../testdata/TestDualSubChat/call5.golden | 3 +- .../testdata/TestDualSubChat/call6.golden | 3 +- .../testdata/TestDualSubChat/step1.golden | 6 +- .../testdata/TestDualSubChat/step2.golden | 3 +- .../testdata/TestDualSubChat/step3.golden | 3 +- pkg/tests/testdata/TestInput/call1.golden | 3 +- pkg/tests/testdata/TestInput/call2.golden | 3 +- pkg/tests/testdata/TestInput/step1.golden | 3 +- pkg/tests/testdata/TestInput/step2.golden | 3 +- pkg/tests/testdata/TestOutput/call1.golden | 3 +- pkg/tests/testdata/TestOutput/call2.golden | 3 +- pkg/tests/testdata/TestOutput/call3.golden | 3 +- pkg/tests/testdata/TestOutput/step1.golden | 7 ++- pkg/tests/testdata/TestOutput/step2.golden | 7 ++- pkg/tests/testdata/TestOutput/step3.golden | 2 +- pkg/tests/testdata/TestOutput/test.gpt | 1 - pkg/tests/testdata/TestSubChat/call2.golden | 3 +- pkg/tests/testdata/TestSubChat/call3.golden | 3 +- .../testdata/TestSysContext/call1.golden | 5 +- .../testdata/TestSysContext/context.json | 2 +- .../testdata/TestSysContext/step1.golden | 5 +- pkg/types/completion.go | 1 + pkg/types/toolstring.go | 2 +- 54 files changed, 240 insertions(+), 75 deletions(-) create mode 100644 pkg/openai/count.go diff --git a/go.mod b/go.mod index c5eba627..1609ae4c 100644 --- a/go.mod +++ b/go.mod @@ -16,7 +16,7 @@ require ( github.com/gptscript-ai/broadcaster v0.0.0-20240625175512-c43682019b86 github.com/gptscript-ai/chat-completion-client v0.0.0-20240531200700-af8e7ecf0379 github.com/gptscript-ai/cmd v0.0.0-20240625175447-4250b42feb7d - github.com/gptscript-ai/tui v0.0.0-20240625175717-1e6eca7a66c1 + github.com/gptscript-ai/tui v0.0.0-20240627001757-8b452fa47eb5 github.com/hexops/autogold/v2 v2.2.1 github.com/hexops/valast v1.4.4 github.com/jaytaylor/html2text v0.0.0-20230321000545-74c2419ad056 @@ -94,6 +94,7 @@ require ( github.com/pterm/pterm v0.12.79 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect + github.com/sourcegraph/go-diff-patch v0.0.0-20240223163233-798fd1e94a8e // indirect github.com/ssor/bom v0.0.0-20170718123548-6386211fdfcf // indirect github.com/therootcompany/xz v1.0.1 // indirect github.com/tidwall/match v1.1.1 // indirect diff --git a/go.sum b/go.sum index c61794f1..c13d872a 100644 --- a/go.sum +++ b/go.sum @@ -173,8 +173,8 @@ github.com/gptscript-ai/cmd v0.0.0-20240625175447-4250b42feb7d h1:sKf7T7twhGXs6A github.com/gptscript-ai/cmd v0.0.0-20240625175447-4250b42feb7d/go.mod h1:DJAo1xTht1LDkNYFNydVjTHd576TC7MlpsVRl3oloVw= github.com/gptscript-ai/go-gptscript v0.0.0-20240625134437-4b83849794cc h1:ABV7VAK65YBkqL7VlNp5ryVXnRqkKQ+U/NZfUO3ypqA= github.com/gptscript-ai/go-gptscript v0.0.0-20240625134437-4b83849794cc/go.mod h1:Dh6vYRAiVcyC3ElZIGzTvNF1FxtYwA07BHfSiFKQY7s= -github.com/gptscript-ai/tui v0.0.0-20240625175717-1e6eca7a66c1 h1:sx/dJ0IRh3P9Ehr1g1TQ/jEw83KISmQyjrssVgPGUbE= -github.com/gptscript-ai/tui v0.0.0-20240625175717-1e6eca7a66c1/go.mod h1:R33cfOnNaqsEn9es5jLKR39wvDyHvsIVgeTMNqtzCb8= +github.com/gptscript-ai/tui v0.0.0-20240627001757-8b452fa47eb5 h1:knDhTTJNqaZB1XMudXJuVVnTqj9USrXzNfsl1nTqKXA= +github.com/gptscript-ai/tui v0.0.0-20240627001757-8b452fa47eb5/go.mod h1:NwFdBDmGQvjLFFDnSRBRakkhw0MIO1sSdRnWNk4cCQ0= github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= @@ -308,6 +308,8 @@ github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ= github.com/sergi/go-diff v1.2.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= +github.com/sourcegraph/go-diff-patch v0.0.0-20240223163233-798fd1e94a8e h1:H+jDTUeF+SVd4ApwnSFoew8ZwGNRfgb9EsZc7LcocAg= +github.com/sourcegraph/go-diff-patch v0.0.0-20240223163233-798fd1e94a8e/go.mod h1:VsUklG6OQo7Ctunu0gS3AtEOCEc2kMB6r5rKzxAes58= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= diff --git a/pkg/builtin/builtin.go b/pkg/builtin/builtin.go index 56630369..f6811549 100644 --- a/pkg/builtin/builtin.go +++ b/pkg/builtin/builtin.go @@ -29,6 +29,7 @@ var SafeTools = map[string]struct{}{ "sys.abort": {}, "sys.chat.finish": {}, "sys.chat.history": {}, + "sys.chat.current": {}, "sys.echo": {}, "sys.prompt": {}, "sys.time.now": {}, @@ -229,6 +230,15 @@ var tools = map[string]types.Tool{ BuiltinFunc: SysChatHistory, }, }, + "sys.chat.current": { + ToolDef: types.ToolDef{ + Parameters: types.Parameters{ + Description: "Retrieves the current chat dialog", + Arguments: types.ObjectSchema(), + }, + BuiltinFunc: SysChatCurrent, + }, + }, "sys.context": { ToolDef: types.ToolDef{ Parameters: types.Parameters{ @@ -715,6 +725,28 @@ func writeHistory(ctx *engine.Context) (result []engine.ChatHistoryCall) { return } +func SysChatCurrent(ctx context.Context, _ []string, _ string, _ chan<- string) (string, error) { + engineContext, _ := engine.FromContext(ctx) + + var call any + if engineContext != nil && engineContext.CurrentReturn != nil && engineContext.CurrentReturn.State != nil { + call = engine.ChatHistoryCall{ + ID: engineContext.ID, + Tool: engineContext.Tool, + Completion: engineContext.CurrentReturn.State.Completion, + } + } else { + call = map[string]any{} + } + + data, err := json.Marshal(call) + if err != nil { + return invalidArgument("", err), nil + } + + return string(data), nil +} + func SysChatFinish(_ context.Context, _ []string, input string, _ chan<- string) (string, error) { var params struct { Message string `json:"return,omitempty"` diff --git a/pkg/cli/gptscript.go b/pkg/cli/gptscript.go index 5a44c5fb..9faa7109 100644 --- a/pkg/cli/gptscript.go +++ b/pkg/cli/gptscript.go @@ -467,7 +467,7 @@ func (r *GPTScript) Run(cmd *cobra.Command, args []string) (retErr error) { DefaultModel: r.DefaultModel, TrustedRepoPrefixes: []string{"github.com/gptscript-ai"}, DisableCache: r.DisableCache, - Input: strings.Join(args[1:], " "), + Input: toolInput, CacheDir: r.CacheDir, SubTool: r.SubTool, Workspace: r.Workspace, diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 5cbc87a8..b0a6e4eb 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -59,6 +59,7 @@ type CallResult struct { type commonContext struct { ID string `json:"id"` Tool types.Tool `json:"tool"` + CurrentAgent types.ToolReference `json:"currentAgent,omitempty"` AgentGroup []types.ToolReference `json:"agentGroup,omitempty"` InputContext []InputContext `json:"inputContext"` ToolCategory ToolCategory `json:"toolCategory,omitempty"` @@ -73,10 +74,11 @@ type CallContext struct { type Context struct { commonContext - Ctx context.Context - Parent *Context - LastReturn *Return - Program *types.Program + Ctx context.Context + Parent *Context + LastReturn *Return + CurrentReturn *Return + Program *types.Program // Input is saved only so that we can render display text, don't use otherwise Input string } @@ -129,6 +131,18 @@ func (c *Context) ParentID() string { return c.Parent.ID } +func (c *Context) CurrentAgent() types.ToolReference { + for _, ref := range c.AgentGroup { + if ref.ToolID == c.Tool.ID { + return ref + } + } + if c.Parent != nil { + return c.Parent.CurrentAgent() + } + return types.ToolReference{} +} + func (c *Context) GetCallContext() *CallContext { var toolName string if c.Parent != nil { @@ -143,12 +157,15 @@ func (c *Context) GetCallContext() *CallContext { } } - return &CallContext{ + result := &CallContext{ commonContext: c.commonContext, ParentID: c.ParentID(), ToolName: toolName, DisplayText: types.ToDisplayText(c.Tool, c.Input), } + + result.CurrentAgent = c.CurrentAgent() + return result } func (c *Context) UnmarshalJSON([]byte) error { @@ -215,10 +232,11 @@ func (c *Context) SubCallContext(ctx context.Context, input, toolID, callID stri AgentGroup: agentGroup, ToolCategory: toolCategory, }, - Ctx: ctx, - Parent: c, - Program: c.Program, - Input: input, + Ctx: ctx, + Parent: c, + Program: c.Program, + CurrentReturn: c.CurrentReturn, + Input: input, }, nil } @@ -270,6 +288,7 @@ func (e *Engine) Start(ctx Context, input string) (ret *Return, _ error) { MaxTokens: tool.Parameters.MaxTokens, JSONResponse: tool.Parameters.JSONResponse, Cache: tool.Parameters.Cache, + Chat: tool.Parameters.Chat, Temperature: tool.Parameters.Temperature, InternalSystemPrompt: tool.Parameters.InternalPrompt, } diff --git a/pkg/openai/client.go b/pkg/openai/client.go index 6e3c9c60..897fb880 100644 --- a/pkg/openai/client.go +++ b/pkg/openai/client.go @@ -300,11 +300,16 @@ func (c *Client) Call(ctx context.Context, messageRequest types.CompletionReques if messageRequest.Model == "" { messageRequest.Model = c.defaultModel } + msgs, err := toMessages(messageRequest, !c.setSeed) if err != nil { return nil, err } + if messageRequest.Chat { + msgs = dropMessagesOverCount(messageRequest.MaxTokens, msgs) + } + if len(msgs) == 0 { log.Errorf("invalid request, no messages to send to LLM") return &types.CompletionMessage{ diff --git a/pkg/openai/count.go b/pkg/openai/count.go new file mode 100644 index 00000000..47c5c9bd --- /dev/null +++ b/pkg/openai/count.go @@ -0,0 +1,57 @@ +package openai + +import openai "github.com/gptscript-ai/chat-completion-client" + +func dropMessagesOverCount(maxTokens int, msgs []openai.ChatCompletionMessage) (result []openai.ChatCompletionMessage) { + var ( + lastSystem int + withinBudget int + budget = maxTokens + ) + + if maxTokens == 0 { + budget = 300_000 + } else { + budget *= 3 + } + + for i, msg := range msgs { + if msg.Role == openai.ChatMessageRoleSystem { + budget -= countMessage(msg) + lastSystem = i + result = append(result, msg) + } else { + break + } + } + + for i := len(msgs) - 1; i > lastSystem; i-- { + withinBudget = i + budget -= countMessage(msgs[i]) + if budget <= 0 { + break + } + } + + if withinBudget == len(msgs)-1 { + // We are going to drop all non system messages, which seems useless, so just return them + // all and let it fail + return msgs + } + + return append(result, msgs[withinBudget:]...) +} + +func countMessage(msg openai.ChatCompletionMessage) (count int) { + count += len(msg.Role) + count += len(msg.Content) + for _, content := range msg.MultiContent { + count += len(content.Text) + } + for _, tool := range msg.ToolCalls { + count += len(tool.Function.Name) + count += len(tool.Function.Arguments) + } + count += len(msg.ToolCallID) + return count / 3 +} diff --git a/pkg/runner/output.go b/pkg/runner/output.go index 858d106c..d4cb4b9b 100644 --- a/pkg/runner/output.go +++ b/pkg/runner/output.go @@ -41,7 +41,6 @@ func (r *Runner) handleOutput(callCtx engine.Context, monitor Monitor, env []str for _, outputToolRef := range outputToolRefs { inputData, err := json.Marshal(map[string]any{ "output": output, - "chatFinish": chatFinish, "continuation": continuation, "chat": callCtx.Tool.Chat, }) diff --git a/pkg/runner/runner.go b/pkg/runner/runner.go index cecc7afd..41e4f058 100644 --- a/pkg/runner/runner.go +++ b/pkg/runner/runner.go @@ -559,6 +559,8 @@ func (r *Runner) resume(callCtx engine.Context, monitor Monitor, env []string, s } for { + callCtx.CurrentReturn = state.Continuation + if state.Continuation.Result != nil && len(state.Continuation.Calls) == 0 && state.SubCallID == "" && state.ResumeInput == nil { progressClose() monitor.Event(Event{ diff --git a/pkg/tests/runner_test.go b/pkg/tests/runner_test.go index db185d75..deced81c 100644 --- a/pkg/tests/runner_test.go +++ b/pkg/tests/runner_test.go @@ -413,7 +413,8 @@ func TestSubChat(t *testing.T) { ], "usage": {} } - ] + ], + "chat": true } }, "result": "Assistant 1" @@ -555,7 +556,8 @@ func TestSubChat(t *testing.T) { ], "usage": {} } - ] + ], + "chat": true } }, "result": "Assistant 2" @@ -622,7 +624,8 @@ func TestChat(t *testing.T) { ], "usage": {} } - ] + ], + "chat": true } }, "result": "Assistant 1" @@ -691,7 +694,8 @@ func TestChat(t *testing.T) { ], "usage": {} } - ] + ], + "chat": true } }, "result": "Assistant 2" @@ -866,7 +870,7 @@ func TestOutput(t *testing.T) { require.NoError(t, err) r.AssertResponded(t) assert.False(t, resp.Done) - autogold.Expect(`CHAT: true CONTENT: Response 1 CONTINUATION: true FINISH: false suffix + autogold.Expect(`CHAT: true CONTENT: Response 1 CONTINUATION: true suffix `).Equal(t, resp.Content) autogold.ExpectFile(t, toJSONString(t, resp), autogold.Name(t.Name()+"/step1")) @@ -877,7 +881,7 @@ func TestOutput(t *testing.T) { require.NoError(t, err) r.AssertResponded(t) assert.False(t, resp.Done) - autogold.Expect(`CHAT: true CONTENT: Response 2 CONTINUATION: true FINISH: false suffix + autogold.Expect(`CHAT: true CONTENT: Response 2 CONTINUATION: true suffix `).Equal(t, resp.Content) autogold.ExpectFile(t, toJSONString(t, resp), autogold.Name(t.Name()+"/step2")) @@ -890,7 +894,7 @@ func TestOutput(t *testing.T) { require.NoError(t, err) r.AssertResponded(t) assert.True(t, resp.Done) - autogold.Expect(`CHAT FINISH: CHAT: true CONTENT: Chat Done CONTINUATION: false FINISH: true suffix + autogold.Expect(`CHAT FINISH: CHAT: true CONTENT: Chat Done CONTINUATION: false suffix `).Equal(t, resp.Content) autogold.ExpectFile(t, toJSONString(t, resp), autogold.Name(t.Name()+"/step3")) } diff --git a/pkg/tests/testdata/TestAgents/call1.golden b/pkg/tests/testdata/TestAgents/call1.golden index c0465ac7..a1a0dcaa 100644 --- a/pkg/tests/testdata/TestAgents/call1.golden +++ b/pkg/tests/testdata/TestAgents/call1.golden @@ -52,5 +52,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestAgents/call2.golden b/pkg/tests/testdata/TestAgents/call2.golden index a4b53537..6b59830a 100644 --- a/pkg/tests/testdata/TestAgents/call2.golden +++ b/pkg/tests/testdata/TestAgents/call2.golden @@ -28,5 +28,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestAgents/call3.golden b/pkg/tests/testdata/TestAgents/call3.golden index 4a001215..29d5462e 100644 --- a/pkg/tests/testdata/TestAgents/call3.golden +++ b/pkg/tests/testdata/TestAgents/call3.golden @@ -43,5 +43,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestAgents/call4.golden b/pkg/tests/testdata/TestAgents/call4.golden index 038fa68c..d43474ca 100644 --- a/pkg/tests/testdata/TestAgents/call4.golden +++ b/pkg/tests/testdata/TestAgents/call4.golden @@ -11,5 +11,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestAgents/step1.golden b/pkg/tests/testdata/TestAgents/step1.golden index 423069b5..a259bf0f 100644 --- a/pkg/tests/testdata/TestAgents/step1.golden +++ b/pkg/tests/testdata/TestAgents/step1.golden @@ -75,7 +75,8 @@ ], "usage": {} } - ] + ], + "chat": true }, "pending": { "call_1": { @@ -145,7 +146,8 @@ ], "usage": {} } - ] + ], + "chat": true }, "pending": { "call_2": { @@ -230,7 +232,8 @@ ], "usage": {} } - ] + ], + "chat": true }, "pending": { "call_3": { @@ -277,7 +280,8 @@ ], "usage": {} } - ] + ], + "chat": true } }, "result": "TEST RESULT CALL: 4" diff --git a/pkg/tests/testdata/TestChat/call1.golden b/pkg/tests/testdata/TestChat/call1.golden index 0fef0adb..34bb12cf 100644 --- a/pkg/tests/testdata/TestChat/call1.golden +++ b/pkg/tests/testdata/TestChat/call1.golden @@ -20,5 +20,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestChat/call2.golden b/pkg/tests/testdata/TestChat/call2.golden index ff513bb2..e67862cb 100644 --- a/pkg/tests/testdata/TestChat/call2.golden +++ b/pkg/tests/testdata/TestChat/call2.golden @@ -38,5 +38,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestChatRunNoError/call1.golden b/pkg/tests/testdata/TestChatRunNoError/call1.golden index 5fdf4ff8..ac6d5325 100644 --- a/pkg/tests/testdata/TestChatRunNoError/call1.golden +++ b/pkg/tests/testdata/TestChatRunNoError/call1.golden @@ -11,5 +11,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestContextSubChat/call10.golden b/pkg/tests/testdata/TestContextSubChat/call10.golden index b4433d52..c8c98651 100644 --- a/pkg/tests/testdata/TestContextSubChat/call10.golden +++ b/pkg/tests/testdata/TestContextSubChat/call10.golden @@ -38,5 +38,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestContextSubChat/call2.golden b/pkg/tests/testdata/TestContextSubChat/call2.golden index c3843cb9..a6cf25c6 100644 --- a/pkg/tests/testdata/TestContextSubChat/call2.golden +++ b/pkg/tests/testdata/TestContextSubChat/call2.golden @@ -38,5 +38,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestContextSubChat/call3.golden b/pkg/tests/testdata/TestContextSubChat/call3.golden index da02aace..55ad402f 100644 --- a/pkg/tests/testdata/TestContextSubChat/call3.golden +++ b/pkg/tests/testdata/TestContextSubChat/call3.golden @@ -56,5 +56,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestContextSubChat/call5.golden b/pkg/tests/testdata/TestContextSubChat/call5.golden index 25249ec2..2b8cf41e 100644 --- a/pkg/tests/testdata/TestContextSubChat/call5.golden +++ b/pkg/tests/testdata/TestContextSubChat/call5.golden @@ -20,5 +20,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestContextSubChat/call7.golden b/pkg/tests/testdata/TestContextSubChat/call7.golden index 7c1c9a19..b0ef4e39 100644 --- a/pkg/tests/testdata/TestContextSubChat/call7.golden +++ b/pkg/tests/testdata/TestContextSubChat/call7.golden @@ -38,5 +38,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestContextSubChat/call8.golden b/pkg/tests/testdata/TestContextSubChat/call8.golden index e1350cdc..3d0db61b 100644 --- a/pkg/tests/testdata/TestContextSubChat/call8.golden +++ b/pkg/tests/testdata/TestContextSubChat/call8.golden @@ -56,5 +56,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestContextSubChat/step1.golden b/pkg/tests/testdata/TestContextSubChat/step1.golden index 464efb36..5f9a3c6f 100644 --- a/pkg/tests/testdata/TestContextSubChat/step1.golden +++ b/pkg/tests/testdata/TestContextSubChat/step1.golden @@ -128,7 +128,8 @@ ], "usage": {} } - ] + ], + "chat": true } }, "result": "Assistant Response 1 - from chatbot1" diff --git a/pkg/tests/testdata/TestContextSubChat/step2.golden b/pkg/tests/testdata/TestContextSubChat/step2.golden index d9631971..dfcb2b96 100644 --- a/pkg/tests/testdata/TestContextSubChat/step2.golden +++ b/pkg/tests/testdata/TestContextSubChat/step2.golden @@ -37,7 +37,8 @@ ], "usage": {} } - ] + ], + "chat": true } }, "result": "Assistant Response 3 - from main chat tool" diff --git a/pkg/tests/testdata/TestContextSubChat/step3.golden b/pkg/tests/testdata/TestContextSubChat/step3.golden index 3c365c54..e50b04a0 100644 --- a/pkg/tests/testdata/TestContextSubChat/step3.golden +++ b/pkg/tests/testdata/TestContextSubChat/step3.golden @@ -37,7 +37,8 @@ ], "usage": {} } - ] + ], + "chat": true } }, "result": "Assistant Response 3 - from main chat tool" @@ -169,7 +170,8 @@ ], "usage": {} } - ] + ], + "chat": true } }, "result": "Assistant Response 4 - from chatbot1" diff --git a/pkg/tests/testdata/TestContextSubChat/step4.golden b/pkg/tests/testdata/TestContextSubChat/step4.golden index 40798cf6..5e95d626 100644 --- a/pkg/tests/testdata/TestContextSubChat/step4.golden +++ b/pkg/tests/testdata/TestContextSubChat/step4.golden @@ -55,7 +55,8 @@ ], "usage": {} } - ] + ], + "chat": true } }, "result": "Assistant Response 6 - from main chat tool resume" diff --git a/pkg/tests/testdata/TestDualSubChat/call2.golden b/pkg/tests/testdata/TestDualSubChat/call2.golden index c3843cb9..a6cf25c6 100644 --- a/pkg/tests/testdata/TestDualSubChat/call2.golden +++ b/pkg/tests/testdata/TestDualSubChat/call2.golden @@ -38,5 +38,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestDualSubChat/call3.golden b/pkg/tests/testdata/TestDualSubChat/call3.golden index 755dda31..ddcc81c9 100644 --- a/pkg/tests/testdata/TestDualSubChat/call3.golden +++ b/pkg/tests/testdata/TestDualSubChat/call3.golden @@ -38,5 +38,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestDualSubChat/call4.golden b/pkg/tests/testdata/TestDualSubChat/call4.golden index 45b6648b..600e3ba5 100644 --- a/pkg/tests/testdata/TestDualSubChat/call4.golden +++ b/pkg/tests/testdata/TestDualSubChat/call4.golden @@ -56,5 +56,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestDualSubChat/call5.golden b/pkg/tests/testdata/TestDualSubChat/call5.golden index 2aa21e94..54823934 100644 --- a/pkg/tests/testdata/TestDualSubChat/call5.golden +++ b/pkg/tests/testdata/TestDualSubChat/call5.golden @@ -56,5 +56,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestDualSubChat/call6.golden b/pkg/tests/testdata/TestDualSubChat/call6.golden index 6194daed..a9a8a1c4 100644 --- a/pkg/tests/testdata/TestDualSubChat/call6.golden +++ b/pkg/tests/testdata/TestDualSubChat/call6.golden @@ -74,5 +74,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestDualSubChat/step1.golden b/pkg/tests/testdata/TestDualSubChat/step1.golden index 46932939..6a04614b 100644 --- a/pkg/tests/testdata/TestDualSubChat/step1.golden +++ b/pkg/tests/testdata/TestDualSubChat/step1.golden @@ -174,7 +174,8 @@ ], "usage": {} } - ] + ], + "chat": true } }, "result": "Assistant Response 1 - from chatbot1" @@ -238,7 +239,8 @@ ], "usage": {} } - ] + ], + "chat": true } }, "result": "Assistent Response 2 - from chatbot2" diff --git a/pkg/tests/testdata/TestDualSubChat/step2.golden b/pkg/tests/testdata/TestDualSubChat/step2.golden index 2e1511c7..da3e8403 100644 --- a/pkg/tests/testdata/TestDualSubChat/step2.golden +++ b/pkg/tests/testdata/TestDualSubChat/step2.golden @@ -181,7 +181,8 @@ ], "usage": {} } - ] + ], + "chat": true } }, "result": "Assistent Response 2 - from chatbot2" diff --git a/pkg/tests/testdata/TestDualSubChat/step3.golden b/pkg/tests/testdata/TestDualSubChat/step3.golden index d21249c3..028f9cd9 100644 --- a/pkg/tests/testdata/TestDualSubChat/step3.golden +++ b/pkg/tests/testdata/TestDualSubChat/step3.golden @@ -199,7 +199,8 @@ ], "usage": {} } - ] + ], + "chat": true } }, "result": "Assistant 3" diff --git a/pkg/tests/testdata/TestInput/call1.golden b/pkg/tests/testdata/TestInput/call1.golden index 8f9b629c..a3b78c42 100644 --- a/pkg/tests/testdata/TestInput/call1.golden +++ b/pkg/tests/testdata/TestInput/call1.golden @@ -20,5 +20,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestInput/call2.golden b/pkg/tests/testdata/TestInput/call2.golden index 8da96da8..63c469f4 100644 --- a/pkg/tests/testdata/TestInput/call2.golden +++ b/pkg/tests/testdata/TestInput/call2.golden @@ -38,5 +38,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestInput/step1.golden b/pkg/tests/testdata/TestInput/step1.golden index a617d41a..72e36ecb 100644 --- a/pkg/tests/testdata/TestInput/step1.golden +++ b/pkg/tests/testdata/TestInput/step1.golden @@ -37,7 +37,8 @@ ], "usage": {} } - ] + ], + "chat": true } }, "result": "TEST RESULT CALL: 1" diff --git a/pkg/tests/testdata/TestInput/step2.golden b/pkg/tests/testdata/TestInput/step2.golden index e085edb2..73b89d76 100644 --- a/pkg/tests/testdata/TestInput/step2.golden +++ b/pkg/tests/testdata/TestInput/step2.golden @@ -55,7 +55,8 @@ ], "usage": {} } - ] + ], + "chat": true } }, "result": "TEST RESULT CALL: 2" diff --git a/pkg/tests/testdata/TestOutput/call1.golden b/pkg/tests/testdata/TestOutput/call1.golden index 9430afee..6b1e1362 100644 --- a/pkg/tests/testdata/TestOutput/call1.golden +++ b/pkg/tests/testdata/TestOutput/call1.golden @@ -20,5 +20,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestOutput/call2.golden b/pkg/tests/testdata/TestOutput/call2.golden index 32bb7039..e7e17359 100644 --- a/pkg/tests/testdata/TestOutput/call2.golden +++ b/pkg/tests/testdata/TestOutput/call2.golden @@ -38,5 +38,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestOutput/call3.golden b/pkg/tests/testdata/TestOutput/call3.golden index 01aed5eb..b81d2d26 100644 --- a/pkg/tests/testdata/TestOutput/call3.golden +++ b/pkg/tests/testdata/TestOutput/call3.golden @@ -56,5 +56,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestOutput/step1.golden b/pkg/tests/testdata/TestOutput/step1.golden index 46f1b8e8..3d77ecec 100644 --- a/pkg/tests/testdata/TestOutput/step1.golden +++ b/pkg/tests/testdata/TestOutput/step1.golden @@ -1,6 +1,6 @@ `{ "done": false, - "content": "CHAT: true CONTENT: Response 1 CONTINUATION: true FINISH: false suffix\n", + "content": "CHAT: true CONTENT: Response 1 CONTINUATION: true suffix\n", "toolID": "testdata/TestOutput/test.gpt:", "state": { "continuation": { @@ -37,10 +37,11 @@ ], "usage": {} } - ] + ], + "chat": true } }, - "result": "CHAT: true CONTENT: Response 1 CONTINUATION: true FINISH: false suffix\n" + "result": "CHAT: true CONTENT: Response 1 CONTINUATION: true suffix\n" }, "continuationToolID": "testdata/TestOutput/test.gpt:" } diff --git a/pkg/tests/testdata/TestOutput/step2.golden b/pkg/tests/testdata/TestOutput/step2.golden index d5fd89a0..80baf7e4 100644 --- a/pkg/tests/testdata/TestOutput/step2.golden +++ b/pkg/tests/testdata/TestOutput/step2.golden @@ -1,6 +1,6 @@ `{ "done": false, - "content": "CHAT: true CONTENT: Response 2 CONTINUATION: true FINISH: false suffix\n", + "content": "CHAT: true CONTENT: Response 2 CONTINUATION: true suffix\n", "toolID": "testdata/TestOutput/test.gpt:", "state": { "continuation": { @@ -55,10 +55,11 @@ ], "usage": {} } - ] + ], + "chat": true } }, - "result": "CHAT: true CONTENT: Response 2 CONTINUATION: true FINISH: false suffix\n" + "result": "CHAT: true CONTENT: Response 2 CONTINUATION: true suffix\n" }, "continuationToolID": "testdata/TestOutput/test.gpt:" } diff --git a/pkg/tests/testdata/TestOutput/step3.golden b/pkg/tests/testdata/TestOutput/step3.golden index c4e63adc..b357ebb8 100644 --- a/pkg/tests/testdata/TestOutput/step3.golden +++ b/pkg/tests/testdata/TestOutput/step3.golden @@ -1,6 +1,6 @@ `{ "done": true, - "content": "CHAT FINISH: CHAT: true CONTENT: Chat Done CONTINUATION: false FINISH: true suffix\n", + "content": "CHAT FINISH: CHAT: true CONTENT: Chat Done CONTINUATION: false suffix\n", "toolID": "", "state": null }` diff --git a/pkg/tests/testdata/TestOutput/test.gpt b/pkg/tests/testdata/TestOutput/test.gpt index cc35faa0..9bccc2db 100644 --- a/pkg/tests/testdata/TestOutput/test.gpt +++ b/pkg/tests/testdata/TestOutput/test.gpt @@ -20,7 +20,6 @@ args: chatFinish: chat finish message echo CHAT: ${CHAT} echo CONTENT: ${OUTPUT} echo CONTINUATION: ${CONTINUATION} -echo FINISH: ${CHATFINISH} --- name: suffix diff --git a/pkg/tests/testdata/TestSubChat/call2.golden b/pkg/tests/testdata/TestSubChat/call2.golden index 5fdf4ff8..ac6d5325 100644 --- a/pkg/tests/testdata/TestSubChat/call2.golden +++ b/pkg/tests/testdata/TestSubChat/call2.golden @@ -11,5 +11,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestSubChat/call3.golden b/pkg/tests/testdata/TestSubChat/call3.golden index b1b4b3a9..0bf5dbab 100644 --- a/pkg/tests/testdata/TestSubChat/call3.golden +++ b/pkg/tests/testdata/TestSubChat/call3.golden @@ -29,5 +29,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestSysContext/call1.golden b/pkg/tests/testdata/TestSysContext/call1.golden index c315d381..c92b704f 100644 --- a/pkg/tests/testdata/TestSysContext/call1.golden +++ b/pkg/tests/testdata/TestSysContext/call1.golden @@ -23,7 +23,7 @@ "role": "system", "content": [ { - "text": "{\"call\":{\"id\":\"\",\"tool\":{\"name\":\"sys.context\",\"description\":\"Retrieves the current internal GPTScript tool call context information\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"arguments\":{\"type\":\"object\"},\"instructions\":\"#!sys.context\",\"id\":\"sys.context\",\"source\":{}},\"agentGroup\":[{\"named\":\"iAmSuperman\",\"reference\":\"./file.gpt\",\"toolID\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\"}],\"inputContext\":null,\"toolCategory\":\"context\",\"toolName\":\"sys.context\"},\"program\":{\"name\":\"testdata/TestSysContext/test.gpt\",\"entryToolId\":\"testdata/TestSysContext/test.gpt:\",\"toolSet\":{\"sys.context\":{\"name\":\"sys.context\",\"description\":\"Retrieves the current internal GPTScript tool call context information\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"arguments\":{\"type\":\"object\"},\"instructions\":\"#!sys.context\",\"id\":\"sys.context\",\"source\":{}},\"testdata/TestSysContext/file.gpt:I am Superman Agent\":{\"name\":\"I am Superman Agent\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"instructions\":\"I'm super\",\"id\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\",\"localTools\":{\"i am superman agent\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\"},\"source\":{\"location\":\"testdata/TestSysContext/file.gpt\",\"lineNo\":1},\"workingDir\":\"testdata/TestSysContext\"},\"testdata/TestSysContext/test.gpt:\":{\"modelName\":\"gpt-4o\",\"chat\":true,\"internalPrompt\":null,\"context\":[\"agents\"],\"agents\":[\"./file.gpt\"],\"instructions\":\"Tool body\",\"id\":\"testdata/TestSysContext/test.gpt:\",\"toolMapping\":{\"./file.gpt\":[{\"reference\":\"./file.gpt\",\"toolID\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\"}],\"agents\":[{\"reference\":\"agents\",\"toolID\":\"testdata/TestSysContext/test.gpt:agents\"}]},\"localTools\":{\"\":\"testdata/TestSysContext/test.gpt:\",\"agents\":\"testdata/TestSysContext/test.gpt:agents\"},\"source\":{\"location\":\"testdata/TestSysContext/test.gpt\",\"lineNo\":1},\"workingDir\":\"testdata/TestSysContext\"},\"testdata/TestSysContext/test.gpt:agents\":{\"name\":\"agents\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"context\":[\"sys.context\"],\"instructions\":\"#!/bin/bash\\n\\necho \\\"${GPTSCRIPT_CONTEXT}\\\"\\necho \\\"${GPTSCRIPT_CONTEXT}\\\" \\u003e ${GPTSCRIPT_TOOL_DIR}/context.json\",\"id\":\"testdata/TestSysContext/test.gpt:agents\",\"toolMapping\":{\"sys.context\":[{\"reference\":\"sys.context\",\"toolID\":\"sys.context\"}]},\"localTools\":{\"\":\"testdata/TestSysContext/test.gpt:\",\"agents\":\"testdata/TestSysContext/test.gpt:agents\"},\"source\":{\"location\":\"testdata/TestSysContext/test.gpt\",\"lineNo\":8},\"workingDir\":\"testdata/TestSysContext\"}}}}\n\nTool body" + "text": "{\"call\":{\"id\":\"\",\"tool\":{\"name\":\"sys.context\",\"description\":\"Retrieves the current internal GPTScript tool call context information\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"arguments\":{\"type\":\"object\"},\"instructions\":\"#!sys.context\",\"id\":\"sys.context\",\"source\":{}},\"currentAgent\":{},\"agentGroup\":[{\"named\":\"iAmSuperman\",\"reference\":\"./file.gpt\",\"toolID\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\"}],\"inputContext\":null,\"toolCategory\":\"context\",\"toolName\":\"sys.context\"},\"program\":{\"name\":\"testdata/TestSysContext/test.gpt\",\"entryToolId\":\"testdata/TestSysContext/test.gpt:\",\"toolSet\":{\"sys.context\":{\"name\":\"sys.context\",\"description\":\"Retrieves the current internal GPTScript tool call context information\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"arguments\":{\"type\":\"object\"},\"instructions\":\"#!sys.context\",\"id\":\"sys.context\",\"source\":{}},\"testdata/TestSysContext/file.gpt:I am Superman Agent\":{\"name\":\"I am Superman Agent\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"instructions\":\"I'm super\",\"id\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\",\"localTools\":{\"i am superman agent\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\"},\"source\":{\"location\":\"testdata/TestSysContext/file.gpt\",\"lineNo\":1},\"workingDir\":\"testdata/TestSysContext\"},\"testdata/TestSysContext/test.gpt:\":{\"modelName\":\"gpt-4o\",\"chat\":true,\"internalPrompt\":null,\"context\":[\"agents\"],\"agents\":[\"./file.gpt\"],\"instructions\":\"Tool body\",\"id\":\"testdata/TestSysContext/test.gpt:\",\"toolMapping\":{\"./file.gpt\":[{\"reference\":\"./file.gpt\",\"toolID\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\"}],\"agents\":[{\"reference\":\"agents\",\"toolID\":\"testdata/TestSysContext/test.gpt:agents\"}]},\"localTools\":{\"\":\"testdata/TestSysContext/test.gpt:\",\"agents\":\"testdata/TestSysContext/test.gpt:agents\"},\"source\":{\"location\":\"testdata/TestSysContext/test.gpt\",\"lineNo\":1},\"workingDir\":\"testdata/TestSysContext\"},\"testdata/TestSysContext/test.gpt:agents\":{\"name\":\"agents\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"context\":[\"sys.context\"],\"instructions\":\"#!/bin/bash\\n\\necho \\\"${GPTSCRIPT_CONTEXT}\\\"\\necho \\\"${GPTSCRIPT_CONTEXT}\\\" \\u003e ${GPTSCRIPT_TOOL_DIR}/context.json\",\"id\":\"testdata/TestSysContext/test.gpt:agents\",\"toolMapping\":{\"sys.context\":[{\"reference\":\"sys.context\",\"toolID\":\"sys.context\"}]},\"localTools\":{\"\":\"testdata/TestSysContext/test.gpt:\",\"agents\":\"testdata/TestSysContext/test.gpt:agents\"},\"source\":{\"location\":\"testdata/TestSysContext/test.gpt\",\"lineNo\":8},\"workingDir\":\"testdata/TestSysContext\"}}}}\n\nTool body" } ], "usage": {} @@ -37,5 +37,6 @@ ], "usage": {} } - ] + ], + "chat": true }` diff --git a/pkg/tests/testdata/TestSysContext/context.json b/pkg/tests/testdata/TestSysContext/context.json index c5608ec4..b6d62218 100644 --- a/pkg/tests/testdata/TestSysContext/context.json +++ b/pkg/tests/testdata/TestSysContext/context.json @@ -1 +1 @@ -{"call":{"id":"","tool":{"name":"sys.context","description":"Retrieves the current internal GPTScript tool call context information","modelName":"gpt-4o","internalPrompt":null,"arguments":{"type":"object"},"instructions":"#!sys.context","id":"sys.context","source":{}},"agentGroup":[{"named":"iAmSuperman","reference":"./file.gpt","toolID":"testdata/TestSysContext/file.gpt:I am Superman Agent"}],"inputContext":null,"toolCategory":"context","toolName":"sys.context"},"program":{"name":"testdata/TestSysContext/test.gpt","entryToolId":"testdata/TestSysContext/test.gpt:","toolSet":{"sys.context":{"name":"sys.context","description":"Retrieves the current internal GPTScript tool call context information","modelName":"gpt-4o","internalPrompt":null,"arguments":{"type":"object"},"instructions":"#!sys.context","id":"sys.context","source":{}},"testdata/TestSysContext/file.gpt:I am Superman Agent":{"name":"I am Superman Agent","modelName":"gpt-4o","internalPrompt":null,"instructions":"I'm super","id":"testdata/TestSysContext/file.gpt:I am Superman Agent","localTools":{"i am superman agent":"testdata/TestSysContext/file.gpt:I am Superman Agent"},"source":{"location":"testdata/TestSysContext/file.gpt","lineNo":1},"workingDir":"testdata/TestSysContext"},"testdata/TestSysContext/test.gpt:":{"modelName":"gpt-4o","chat":true,"internalPrompt":null,"context":["agents"],"agents":["./file.gpt"],"instructions":"Tool body","id":"testdata/TestSysContext/test.gpt:","toolMapping":{"./file.gpt":[{"reference":"./file.gpt","toolID":"testdata/TestSysContext/file.gpt:I am Superman Agent"}],"agents":[{"reference":"agents","toolID":"testdata/TestSysContext/test.gpt:agents"}]},"localTools":{"":"testdata/TestSysContext/test.gpt:","agents":"testdata/TestSysContext/test.gpt:agents"},"source":{"location":"testdata/TestSysContext/test.gpt","lineNo":1},"workingDir":"testdata/TestSysContext"},"testdata/TestSysContext/test.gpt:agents":{"name":"agents","modelName":"gpt-4o","internalPrompt":null,"context":["sys.context"],"instructions":"#!/bin/bash\n\necho \"${GPTSCRIPT_CONTEXT}\"\necho \"${GPTSCRIPT_CONTEXT}\" \u003e ${GPTSCRIPT_TOOL_DIR}/context.json","id":"testdata/TestSysContext/test.gpt:agents","toolMapping":{"sys.context":[{"reference":"sys.context","toolID":"sys.context"}]},"localTools":{"":"testdata/TestSysContext/test.gpt:","agents":"testdata/TestSysContext/test.gpt:agents"},"source":{"location":"testdata/TestSysContext/test.gpt","lineNo":8},"workingDir":"testdata/TestSysContext"}}}} +{"call":{"id":"","tool":{"name":"sys.context","description":"Retrieves the current internal GPTScript tool call context information","modelName":"gpt-4o","internalPrompt":null,"arguments":{"type":"object"},"instructions":"#!sys.context","id":"sys.context","source":{}},"currentAgent":{},"agentGroup":[{"named":"iAmSuperman","reference":"./file.gpt","toolID":"testdata/TestSysContext/file.gpt:I am Superman Agent"}],"inputContext":null,"toolCategory":"context","toolName":"sys.context"},"program":{"name":"testdata/TestSysContext/test.gpt","entryToolId":"testdata/TestSysContext/test.gpt:","toolSet":{"sys.context":{"name":"sys.context","description":"Retrieves the current internal GPTScript tool call context information","modelName":"gpt-4o","internalPrompt":null,"arguments":{"type":"object"},"instructions":"#!sys.context","id":"sys.context","source":{}},"testdata/TestSysContext/file.gpt:I am Superman Agent":{"name":"I am Superman Agent","modelName":"gpt-4o","internalPrompt":null,"instructions":"I'm super","id":"testdata/TestSysContext/file.gpt:I am Superman Agent","localTools":{"i am superman agent":"testdata/TestSysContext/file.gpt:I am Superman Agent"},"source":{"location":"testdata/TestSysContext/file.gpt","lineNo":1},"workingDir":"testdata/TestSysContext"},"testdata/TestSysContext/test.gpt:":{"modelName":"gpt-4o","chat":true,"internalPrompt":null,"context":["agents"],"agents":["./file.gpt"],"instructions":"Tool body","id":"testdata/TestSysContext/test.gpt:","toolMapping":{"./file.gpt":[{"reference":"./file.gpt","toolID":"testdata/TestSysContext/file.gpt:I am Superman Agent"}],"agents":[{"reference":"agents","toolID":"testdata/TestSysContext/test.gpt:agents"}]},"localTools":{"":"testdata/TestSysContext/test.gpt:","agents":"testdata/TestSysContext/test.gpt:agents"},"source":{"location":"testdata/TestSysContext/test.gpt","lineNo":1},"workingDir":"testdata/TestSysContext"},"testdata/TestSysContext/test.gpt:agents":{"name":"agents","modelName":"gpt-4o","internalPrompt":null,"context":["sys.context"],"instructions":"#!/bin/bash\n\necho \"${GPTSCRIPT_CONTEXT}\"\necho \"${GPTSCRIPT_CONTEXT}\" \u003e ${GPTSCRIPT_TOOL_DIR}/context.json","id":"testdata/TestSysContext/test.gpt:agents","toolMapping":{"sys.context":[{"reference":"sys.context","toolID":"sys.context"}]},"localTools":{"":"testdata/TestSysContext/test.gpt:","agents":"testdata/TestSysContext/test.gpt:agents"},"source":{"location":"testdata/TestSysContext/test.gpt","lineNo":8},"workingDir":"testdata/TestSysContext"}}}} diff --git a/pkg/tests/testdata/TestSysContext/step1.golden b/pkg/tests/testdata/TestSysContext/step1.golden index 26b75508..fa773fda 100644 --- a/pkg/tests/testdata/TestSysContext/step1.golden +++ b/pkg/tests/testdata/TestSysContext/step1.golden @@ -31,7 +31,7 @@ "role": "system", "content": [ { - "text": "{\"call\":{\"id\":\"\",\"tool\":{\"name\":\"sys.context\",\"description\":\"Retrieves the current internal GPTScript tool call context information\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"arguments\":{\"type\":\"object\"},\"instructions\":\"#!sys.context\",\"id\":\"sys.context\",\"source\":{}},\"agentGroup\":[{\"named\":\"iAmSuperman\",\"reference\":\"./file.gpt\",\"toolID\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\"}],\"inputContext\":null,\"toolCategory\":\"context\",\"toolName\":\"sys.context\"},\"program\":{\"name\":\"testdata/TestSysContext/test.gpt\",\"entryToolId\":\"testdata/TestSysContext/test.gpt:\",\"toolSet\":{\"sys.context\":{\"name\":\"sys.context\",\"description\":\"Retrieves the current internal GPTScript tool call context information\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"arguments\":{\"type\":\"object\"},\"instructions\":\"#!sys.context\",\"id\":\"sys.context\",\"source\":{}},\"testdata/TestSysContext/file.gpt:I am Superman Agent\":{\"name\":\"I am Superman Agent\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"instructions\":\"I'm super\",\"id\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\",\"localTools\":{\"i am superman agent\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\"},\"source\":{\"location\":\"testdata/TestSysContext/file.gpt\",\"lineNo\":1},\"workingDir\":\"testdata/TestSysContext\"},\"testdata/TestSysContext/test.gpt:\":{\"modelName\":\"gpt-4o\",\"chat\":true,\"internalPrompt\":null,\"context\":[\"agents\"],\"agents\":[\"./file.gpt\"],\"instructions\":\"Tool body\",\"id\":\"testdata/TestSysContext/test.gpt:\",\"toolMapping\":{\"./file.gpt\":[{\"reference\":\"./file.gpt\",\"toolID\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\"}],\"agents\":[{\"reference\":\"agents\",\"toolID\":\"testdata/TestSysContext/test.gpt:agents\"}]},\"localTools\":{\"\":\"testdata/TestSysContext/test.gpt:\",\"agents\":\"testdata/TestSysContext/test.gpt:agents\"},\"source\":{\"location\":\"testdata/TestSysContext/test.gpt\",\"lineNo\":1},\"workingDir\":\"testdata/TestSysContext\"},\"testdata/TestSysContext/test.gpt:agents\":{\"name\":\"agents\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"context\":[\"sys.context\"],\"instructions\":\"#!/bin/bash\\n\\necho \\\"${GPTSCRIPT_CONTEXT}\\\"\\necho \\\"${GPTSCRIPT_CONTEXT}\\\" \\u003e ${GPTSCRIPT_TOOL_DIR}/context.json\",\"id\":\"testdata/TestSysContext/test.gpt:agents\",\"toolMapping\":{\"sys.context\":[{\"reference\":\"sys.context\",\"toolID\":\"sys.context\"}]},\"localTools\":{\"\":\"testdata/TestSysContext/test.gpt:\",\"agents\":\"testdata/TestSysContext/test.gpt:agents\"},\"source\":{\"location\":\"testdata/TestSysContext/test.gpt\",\"lineNo\":8},\"workingDir\":\"testdata/TestSysContext\"}}}}\n\nTool body" + "text": "{\"call\":{\"id\":\"\",\"tool\":{\"name\":\"sys.context\",\"description\":\"Retrieves the current internal GPTScript tool call context information\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"arguments\":{\"type\":\"object\"},\"instructions\":\"#!sys.context\",\"id\":\"sys.context\",\"source\":{}},\"currentAgent\":{},\"agentGroup\":[{\"named\":\"iAmSuperman\",\"reference\":\"./file.gpt\",\"toolID\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\"}],\"inputContext\":null,\"toolCategory\":\"context\",\"toolName\":\"sys.context\"},\"program\":{\"name\":\"testdata/TestSysContext/test.gpt\",\"entryToolId\":\"testdata/TestSysContext/test.gpt:\",\"toolSet\":{\"sys.context\":{\"name\":\"sys.context\",\"description\":\"Retrieves the current internal GPTScript tool call context information\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"arguments\":{\"type\":\"object\"},\"instructions\":\"#!sys.context\",\"id\":\"sys.context\",\"source\":{}},\"testdata/TestSysContext/file.gpt:I am Superman Agent\":{\"name\":\"I am Superman Agent\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"instructions\":\"I'm super\",\"id\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\",\"localTools\":{\"i am superman agent\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\"},\"source\":{\"location\":\"testdata/TestSysContext/file.gpt\",\"lineNo\":1},\"workingDir\":\"testdata/TestSysContext\"},\"testdata/TestSysContext/test.gpt:\":{\"modelName\":\"gpt-4o\",\"chat\":true,\"internalPrompt\":null,\"context\":[\"agents\"],\"agents\":[\"./file.gpt\"],\"instructions\":\"Tool body\",\"id\":\"testdata/TestSysContext/test.gpt:\",\"toolMapping\":{\"./file.gpt\":[{\"reference\":\"./file.gpt\",\"toolID\":\"testdata/TestSysContext/file.gpt:I am Superman Agent\"}],\"agents\":[{\"reference\":\"agents\",\"toolID\":\"testdata/TestSysContext/test.gpt:agents\"}]},\"localTools\":{\"\":\"testdata/TestSysContext/test.gpt:\",\"agents\":\"testdata/TestSysContext/test.gpt:agents\"},\"source\":{\"location\":\"testdata/TestSysContext/test.gpt\",\"lineNo\":1},\"workingDir\":\"testdata/TestSysContext\"},\"testdata/TestSysContext/test.gpt:agents\":{\"name\":\"agents\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"context\":[\"sys.context\"],\"instructions\":\"#!/bin/bash\\n\\necho \\\"${GPTSCRIPT_CONTEXT}\\\"\\necho \\\"${GPTSCRIPT_CONTEXT}\\\" \\u003e ${GPTSCRIPT_TOOL_DIR}/context.json\",\"id\":\"testdata/TestSysContext/test.gpt:agents\",\"toolMapping\":{\"sys.context\":[{\"reference\":\"sys.context\",\"toolID\":\"sys.context\"}]},\"localTools\":{\"\":\"testdata/TestSysContext/test.gpt:\",\"agents\":\"testdata/TestSysContext/test.gpt:agents\"},\"source\":{\"location\":\"testdata/TestSysContext/test.gpt\",\"lineNo\":8},\"workingDir\":\"testdata/TestSysContext\"}}}}\n\nTool body" } ], "usage": {} @@ -54,7 +54,8 @@ ], "usage": {} } - ] + ], + "chat": true } }, "result": "TEST RESULT CALL: 1" diff --git a/pkg/types/completion.go b/pkg/types/completion.go index 7665a51f..dd70ad50 100644 --- a/pkg/types/completion.go +++ b/pkg/types/completion.go @@ -14,6 +14,7 @@ type CompletionRequest struct { Tools []CompletionTool `json:"tools,omitempty"` Messages []CompletionMessage `json:"messages,omitempty"` MaxTokens int `json:"maxTokens,omitempty"` + Chat bool `json:"chat,omitempty"` Temperature *float32 `json:"temperature,omitempty"` JSONResponse bool `json:"jsonResponse,omitempty"` Cache *bool `json:"cache,omitempty"` diff --git a/pkg/types/toolstring.go b/pkg/types/toolstring.go index ede3401e..64f53638 100644 --- a/pkg/types/toolstring.go +++ b/pkg/types/toolstring.go @@ -74,7 +74,7 @@ func ToSysDisplayString(id string, args map[string]string) (string, error) { return fmt.Sprintf("Removing `%s`", args["location"]), nil case "sys.write": return fmt.Sprintf("Writing `%s`", args["filename"]), nil - case "sys.context", "sys.stat", "sys.getenv", "sys.abort", "sys.chat.finish", "sys.chat.history", "sys.echo", "sys.prompt", "sys.time.now": + case "sys.context", "sys.stat", "sys.getenv", "sys.abort", "sys.chat.current", "sys.chat.finish", "sys.chat.history", "sys.echo", "sys.prompt", "sys.time.now": return "", nil default: return "", fmt.Errorf("unknown tool for display string: %s", id)