Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ type Context struct {
type ToolCategory string

const (
ProviderToolCategory ToolCategory = "provider"
CredentialToolCategory ToolCategory = "credential"
ContextToolCategory ToolCategory = "context"
NoCategory ToolCategory = ""
Expand Down Expand Up @@ -120,11 +121,20 @@ func (c *Context) MarshalJSON() ([]byte, error) {
return json.Marshal(c.GetCallContext())
}

type toolCategoryKey struct{}

func WithToolCategory(ctx context.Context, toolCategory ToolCategory) context.Context {
return context.WithValue(ctx, toolCategoryKey{}, toolCategory)
}

func NewContext(ctx context.Context, prg *types.Program) Context {
category, _ := ctx.Value(toolCategoryKey{}).(ToolCategory)

callCtx := Context{
commonContext: commonContext{
ID: counter.Next(),
Tool: prg.ToolSet[prg.EntryToolID],
ID: counter.Next(),
Tool: prg.ToolSet[prg.EntryToolID],
ToolCategory: category,
},
Ctx: ctx,
Program: prg,
Expand Down
3 changes: 2 additions & 1 deletion pkg/remote/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sync"

"github.com/gptscript-ai/gptscript/pkg/cache"
"github.com/gptscript-ai/gptscript/pkg/engine"
env2 "github.com/gptscript-ai/gptscript/pkg/env"
"github.com/gptscript-ai/gptscript/pkg/loader"
"github.com/gptscript-ai/gptscript/pkg/mvl"
Expand Down Expand Up @@ -144,7 +145,7 @@ func (c *Client) load(ctx context.Context, toolName string) (*openai.Client, err
return nil, err
}

url, err := c.runner.Run(ctx, prg.SetBlocking(), c.envs, "")
url, err := c.runner.Run(engine.WithToolCategory(ctx, engine.ProviderToolCategory), prg.SetBlocking(), c.envs, "")
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func (r *Runner) resume(callCtx engine.Context, monitor Monitor, env []string, s
err error
)

state, callResults, err = r.subCalls(callCtx, monitor, env, state, engine.NoCategory)
state, callResults, err = r.subCalls(callCtx, monitor, env, state, callCtx.ToolCategory)
if errMessage := (*builtin.ErrChatFinish)(nil); errors.As(err, &errMessage) && callCtx.Tool.Chat {
return &State{
Result: &errMessage.Message,
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (in CompletionMessage) String() string {
}
buf.WriteString(content.Text)
if content.ToolCall != nil {
buf.WriteString(fmt.Sprintf("tool call %s -> %s", color.GreenString(content.ToolCall.Function.Name), content.ToolCall.Function.Arguments))
buf.WriteString(fmt.Sprintf("<tool call> %s -> %s", color.GreenString(content.ToolCall.Function.Name), content.ToolCall.Function.Arguments))
}
}
return buf.String()
Expand Down