Skip to content

Commit

Permalink
exclude output of cred tools in CallFinish events
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Linville <[email protected]>
  • Loading branch information
g-linville committed Jun 14, 2024
1 parent bf402f9 commit 89343d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
19 changes: 0 additions & 19 deletions pkg/runner/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,3 @@ func (n noopMonitor) Stop(string, error) {}
func (n noopMonitor) Pause() func() {
return func() {}
}

type credWrapper struct {
m Monitor
}

func (c credWrapper) Event(e Event) {
if e.Type == EventTypeCallFinish {
e.Content = "credential tool output redacted"
}
c.m.Event(e)
}

func (c credWrapper) Stop(s string, err error) {
c.m.Stop(s, err)
}

func (c credWrapper) Pause() func() {
return c.m.Pause()
}
12 changes: 10 additions & 2 deletions pkg/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ func (r *Runner) resume(callCtx engine.Context, monitor Monitor, env []string, s
Time: time.Now(),
CallContext: callCtx.GetCallContext(),
Type: EventTypeCallFinish,
Content: *state.Continuation.Result,
Content: getFinishEventContent(*state, callCtx),
})
if callCtx.Tool.Chat {
return &State{
Expand Down Expand Up @@ -786,6 +786,14 @@ func (r *Runner) subCalls(callCtx engine.Context, monitor Monitor, env []string,
return state, callResults, nil
}

func getFinishEventContent(state State, callCtx engine.Context) string {
if callCtx.ToolCategory == engine.CredentialToolCategory {
return ""
}

return *state.Continuation.Result
}

func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env []string) ([]string, error) {
// Since credential tools (usually) prompt the user, we want to only run one at a time.
r.credMutex.Lock()
Expand Down Expand Up @@ -858,7 +866,7 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
return nil, fmt.Errorf("failed to create subcall context for tool %s: %w", credToolName, err)
}

res, err := r.call(subCtx, credWrapper{monitor}, env, input)
res, err := r.call(subCtx, monitor, env, input)
if err != nil {
return nil, fmt.Errorf("failed to run credential tool %s: %w", credToolName, err)
}
Expand Down

0 comments on commit 89343d2

Please sign in to comment.