Skip to content

Commit c25c7be

Browse files
Merge pull request #527 from ibuildthecloud/syscontext
feat: add sys.context to introspect your current tools and agents
2 parents d7d9ca6 + 19bd176 commit c25c7be

File tree

15 files changed

+301
-31
lines changed

15 files changed

+301
-31
lines changed

pkg/builtin/builtin.go

+27-10
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var SafeTools = map[string]struct{}{
3232
"sys.echo": {},
3333
"sys.prompt": {},
3434
"sys.time.now": {},
35+
"sys.context": {},
3536
}
3637

3738
var tools = map[string]types.Tool{
@@ -228,16 +229,15 @@ var tools = map[string]types.Tool{
228229
BuiltinFunc: SysChatHistory,
229230
},
230231
},
231-
}
232-
233-
func SysProgram() *types.Program {
234-
result := &types.Program{
235-
ToolSet: types.ToolSet{},
236-
}
237-
for _, tool := range ListTools() {
238-
result.ToolSet[tool.ID] = tool
239-
}
240-
return result
232+
"sys.context": {
233+
ToolDef: types.ToolDef{
234+
Parameters: types.Parameters{
235+
Description: "Retrieves the current internal GPTScript tool call context information",
236+
Arguments: types.ObjectSchema(),
237+
},
238+
BuiltinFunc: SysContext,
239+
},
240+
},
241241
}
242242

243243
func ListTools() (result []types.Tool) {
@@ -626,6 +626,23 @@ func invalidArgument(input string, err error) string {
626626
return fmt.Sprintf("Failed to parse arguments %s: %v", input, err)
627627
}
628628

629+
func SysContext(ctx context.Context, _ []string, _ string, _ chan<- string) (string, error) {
630+
engineContext, _ := engine.FromContext(ctx)
631+
632+
callContext := *engineContext.GetCallContext()
633+
callContext.ID = ""
634+
callContext.ParentID = ""
635+
data, err := json.Marshal(map[string]any{
636+
"program": engineContext.Program,
637+
"call": callContext,
638+
})
639+
if err != nil {
640+
return invalidArgument("", err), nil
641+
}
642+
643+
return string(data), nil
644+
}
645+
629646
func SysChatHistory(ctx context.Context, _ []string, _ string, _ chan<- string) (string, error) {
630647
engineContext, _ := engine.FromContext(ctx)
631648

pkg/embedded/embed.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package embedded
33
import (
44
"io/fs"
55
"os"
6-
"strings"
76

87
"github.com/gptscript-ai/gptscript/internal"
98
"github.com/gptscript-ai/gptscript/pkg/cli"
@@ -22,10 +21,11 @@ func Run(opts ...Options) bool {
2221
}
2322

2423
system.SetBinToSelf()
25-
if len(os.Args) > 1 && strings.HasPrefix(os.Args[1], "sys.") {
24+
if os.Getenv("GPTSCRIPT_EMBEDDED") == "true" {
2625
cli.Main()
2726
return true
2827
}
2928

29+
_ = os.Setenv("GPTSCRIPT_EMBEDDED", "true")
3030
return false
3131
}

pkg/engine/engine.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func WithToolCategory(ctx context.Context, toolCategory ToolCategory) context.Co
165165
return context.WithValue(ctx, toolCategoryKey{}, toolCategory)
166166
}
167167

168-
func NewContext(ctx context.Context, prg *types.Program, input string) Context {
168+
func NewContext(ctx context.Context, prg *types.Program, input string) (Context, error) {
169169
category, _ := ctx.Value(toolCategoryKey{}).(ToolCategory)
170170

171171
callCtx := Context{
@@ -178,7 +178,14 @@ func NewContext(ctx context.Context, prg *types.Program, input string) Context {
178178
Program: prg,
179179
Input: input,
180180
}
181-
return callCtx
181+
182+
agentGroup, err := callCtx.Tool.GetAgents(*prg)
183+
if err != nil {
184+
return callCtx, err
185+
}
186+
187+
callCtx.AgentGroup = agentGroup
188+
return callCtx, nil
182189
}
183190

184191
func (c *Context) SubCallContext(ctx context.Context, input, toolID, callID string, toolCategory ToolCategory) (Context, error) {
@@ -191,7 +198,7 @@ func (c *Context) SubCallContext(ctx context.Context, input, toolID, callID stri
191198
callID = counter.Next()
192199
}
193200

194-
agentGroup, err := c.Tool.GetAgentGroup(c.AgentGroup, toolID)
201+
agentGroup, err := c.Tool.GetNextAgentGroup(*c.Program, c.AgentGroup, toolID)
195202
if err != nil {
196203
return Context{}, err
197204
}

pkg/runner/runner.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,11 @@ func (r *Runner) Chat(ctx context.Context, prevState ChatState, prg types.Progra
165165
monitor.Stop(resp.Content, err)
166166
}()
167167

168-
callCtx := engine.NewContext(ctx, &prg, input)
168+
callCtx, err := engine.NewContext(ctx, &prg, input)
169+
if err != nil {
170+
return resp, err
171+
}
172+
169173
if state == nil || state.StartContinuation {
170174
if state != nil {
171175
state = state.WithResumeInput(&input)

pkg/tests/runner_test.go

+31
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"runtime"
88
"testing"
99

10+
"github.com/gptscript-ai/gptscript/pkg/engine"
1011
"github.com/gptscript-ai/gptscript/pkg/tests/tester"
1112
"github.com/gptscript-ai/gptscript/pkg/types"
1213
"github.com/hexops/autogold/v2"
@@ -847,3 +848,33 @@ func TestInput(t *testing.T) {
847848
autogold.Expect("TEST RESULT CALL: 2").Equal(t, resp.Content)
848849
autogold.ExpectFile(t, toJSONString(t, resp), autogold.Name(t.Name()+"/step2"))
849850
}
851+
852+
func TestSysContext(t *testing.T) {
853+
if runtime.GOOS == "windows" {
854+
t.Skip()
855+
}
856+
857+
r := tester.NewRunner(t)
858+
859+
prg, err := r.Load("")
860+
require.NoError(t, err)
861+
862+
resp, err := r.Chat(context.Background(), nil, prg, nil, "input 1")
863+
require.NoError(t, err)
864+
r.AssertResponded(t)
865+
assert.False(t, resp.Done)
866+
autogold.Expect("TEST RESULT CALL: 1").Equal(t, resp.Content)
867+
autogold.ExpectFile(t, toJSONString(t, resp), autogold.Name(t.Name()+"/step1"))
868+
869+
data, err := os.ReadFile("testdata/TestSysContext/context.json")
870+
require.NoError(t, err)
871+
872+
context := struct {
873+
Call engine.CallContext `json:"call"`
874+
}{}
875+
err = json.Unmarshal(data, &context)
876+
require.NoError(t, err)
877+
878+
require.Len(t, context.Call.AgentGroup, 1)
879+
assert.Equal(t, context.Call.AgentGroup[0].Named, "iAmSuperman")
880+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
`{
2+
"role": "assistant",
3+
"content": [
4+
{
5+
"text": "TEST RESULT CALL: 1"
6+
}
7+
],
8+
"usage": {}
9+
}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
`{
2+
"model": "gpt-4o",
3+
"internalSystemPrompt": false,
4+
"tools": [
5+
{
6+
"function": {
7+
"toolID": "testdata/TestSysContext/file.gpt:I am Superman Agent",
8+
"name": "iAmSuperman",
9+
"parameters": {
10+
"properties": {
11+
"prompt": {
12+
"description": "Prompt to send to the tool. This may be an instruction or question.",
13+
"type": "string"
14+
}
15+
},
16+
"type": "object"
17+
}
18+
}
19+
}
20+
],
21+
"messages": [
22+
{
23+
"role": "system",
24+
"content": [
25+
{
26+
"text": "{\"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"
27+
}
28+
],
29+
"usage": {}
30+
},
31+
{
32+
"role": "user",
33+
"content": [
34+
{
35+
"text": "input 1"
36+
}
37+
],
38+
"usage": {}
39+
}
40+
]
41+
}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
`{
2+
"model": "gpt-4o",
3+
"internalSystemPrompt": false,
4+
"tools": [
5+
{
6+
"function": {
7+
"toolID": "testdata/TestSysContext/test.gpt:foo",
8+
"name": "foo",
9+
"parameters": {
10+
"properties": {
11+
"prompt": {
12+
"description": "Prompt to send to the tool. This may be an instruction or question.",
13+
"type": "string"
14+
}
15+
},
16+
"type": "object"
17+
}
18+
}
19+
}
20+
],
21+
"messages": [
22+
{
23+
"role": "system",
24+
"content": [
25+
{
26+
"text": "{\"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\":{}},\"inputContext\":null,\"toolCategory\":\"context\",\"toolName\":\"sys.context\",\"parentID\":\"1718924874\",\"displayText\":\"Running 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/test.gpt:\":{\"modelName\":\"gpt-4o\",\"chat\":true,\"internalPrompt\":null,\"context\":[\"agents\"],\"agents\":[\"foo\"],\"instructions\":\"Tool body\",\"id\":\"testdata/TestSysContext/test.gpt:\",\"toolMapping\":{\"agents\":[{\"reference\":\"agents\",\"toolID\":\"testdata/TestSysContext/test.gpt:agents\"}],\"foo\":[{\"reference\":\"foo\",\"toolID\":\"testdata/TestSysContext/test.gpt:foo\"}]},\"localTools\":{\"\":\"testdata/TestSysContext/test.gpt:\",\"agents\":\"testdata/TestSysContext/test.gpt:agents\",\"foo\":\"testdata/TestSysContext/test.gpt:foo\"},\"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\",\"foo\":\"testdata/TestSysContext/test.gpt:foo\"},\"source\":{\"location\":\"testdata/TestSysContext/test.gpt\",\"lineNo\":13},\"workingDir\":\"testdata/TestSysContext\"},\"testdata/TestSysContext/test.gpt:foo\":{\"name\":\"foo\",\"modelName\":\"gpt-4o\",\"internalPrompt\":null,\"instructions\":\"I'm an agent\",\"id\":\"testdata/TestSysContext/test.gpt:foo\",\"localTools\":{\"\":\"testdata/TestSysContext/test.gpt:\",\"agents\":\"testdata/TestSysContext/test.gpt:agents\",\"foo\":\"testdata/TestSysContext/test.gpt:foo\"},\"source\":{\"location\":\"testdata/TestSysContext/test.gpt\",\"lineNo\":8},\"workingDir\":\"testdata/TestSysContext\"}}}}\n\nTool body"
27+
}
28+
],
29+
"usage": {}
30+
},
31+
{
32+
"role": "user",
33+
"content": [
34+
{
35+
"text": "input 1"
36+
}
37+
],
38+
"usage": {}
39+
}
40+
]
41+
}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +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"}}}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
name: I am Superman Agent
2+
3+
I'm super
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
`{
2+
"done": false,
3+
"content": "TEST RESULT CALL: 1",
4+
"toolID": "testdata/TestSysContext/test.gpt:",
5+
"state": {
6+
"continuation": {
7+
"state": {
8+
"input": "input 1",
9+
"completion": {
10+
"model": "gpt-4o",
11+
"internalSystemPrompt": false,
12+
"tools": [
13+
{
14+
"function": {
15+
"toolID": "testdata/TestSysContext/file.gpt:I am Superman Agent",
16+
"name": "iAmSuperman",
17+
"parameters": {
18+
"properties": {
19+
"prompt": {
20+
"description": "Prompt to send to the tool. This may be an instruction or question.",
21+
"type": "string"
22+
}
23+
},
24+
"type": "object"
25+
}
26+
}
27+
}
28+
],
29+
"messages": [
30+
{
31+
"role": "system",
32+
"content": [
33+
{
34+
"text": "{\"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"
35+
}
36+
],
37+
"usage": {}
38+
},
39+
{
40+
"role": "user",
41+
"content": [
42+
{
43+
"text": "input 1"
44+
}
45+
],
46+
"usage": {}
47+
},
48+
{
49+
"role": "assistant",
50+
"content": [
51+
{
52+
"text": "TEST RESULT CALL: 1"
53+
}
54+
],
55+
"usage": {}
56+
}
57+
]
58+
}
59+
},
60+
"result": "TEST RESULT CALL: 1"
61+
},
62+
"continuationToolID": "testdata/TestSysContext/test.gpt:"
63+
}
64+
}`
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"os"
7+
8+
"github.com/gptscript-ai/gptscript/pkg/engine"
9+
)
10+
11+
func main() {
12+
data := struct {
13+
Call engine.CallContext `json:"call,omitempty"`
14+
}{}
15+
if err := json.Unmarshal([]byte(os.Getenv("GPTSCRIPT_CONTEXT")), &data); err != nil {
16+
panic(err)
17+
}
18+
19+
for _, agent := range data.Call.AgentGroup {
20+
fmt.Println(agent.Reference, agent.ToolID)
21+
}
22+
}
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
context: agents
2+
agents: ./file.gpt
3+
chat: true
4+
5+
Tool body
6+
7+
---
8+
name: agents
9+
context: sys.context
10+
11+
#!/bin/bash
12+
13+
echo "${GPTSCRIPT_CONTEXT}"
14+
echo "${GPTSCRIPT_CONTEXT}" > ${GPTSCRIPT_TOOL_DIR}/context.json

0 commit comments

Comments
 (0)