Skip to content

Commit a8c8c79

Browse files
committed
Add break tools
1 parent 5ccfe66 commit a8c8c79

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

Diff for: pkg/engine/control.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package engine
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
"github.com/gptscript-ai/gptscript/pkg/types"
8+
)
9+
10+
func (e *Engine) runBreak(tool types.Tool, input string) (cmdOut *Return, cmdErr error) {
11+
info, err := json.Marshal(tool)
12+
if err != nil {
13+
return nil, err
14+
}
15+
var dict map[string]interface{}
16+
json.Unmarshal(info, &dict)
17+
dict["input"] = input
18+
info, err = json.Marshal(dict)
19+
return nil, fmt.Errorf("TOOL_BREAK: %s", info)
20+
}

Diff for: pkg/engine/engine.go

+2
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ func (e *Engine) Start(ctx Context, input string) (ret *Return, _ error) {
279279
return e.runOpenAPI(tool, input)
280280
} else if tool.IsEcho() {
281281
return e.runEcho(tool)
282+
} else if tool.IsBreak() {
283+
return e.runBreak(tool, input)
282284
}
283285
s, err := e.runCommand(ctx, tool, input, ctx.ToolCategory)
284286
if err != nil {

Diff for: pkg/types/tool.go

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const (
1919
DaemonPrefix = "#!sys.daemon"
2020
OpenAPIPrefix = "#!sys.openapi"
2121
EchoPrefix = "#!sys.echo"
22+
BreakPrefix = "#!sys.break"
2223
CommandPrefix = "#!"
2324
)
2425

@@ -732,6 +733,10 @@ func (t Tool) IsEcho() bool {
732733
return strings.HasPrefix(t.Instructions, EchoPrefix)
733734
}
734735

736+
func (t Tool) IsBreak() bool {
737+
return strings.HasPrefix(t.Instructions, BreakPrefix)
738+
}
739+
735740
func (t Tool) IsHTTP() bool {
736741
return strings.HasPrefix(t.Instructions, "#!http://") ||
737742
strings.HasPrefix(t.Instructions, "#!https://")

0 commit comments

Comments
 (0)