@@ -408,6 +408,11 @@ func (r *Runner) start(callCtx engine.Context, state *State, monitor Monitor, en
408408 Content : input ,
409409 })
410410
411+ input , err := r .handleInput (callCtx , monitor , env , input )
412+ if err != nil {
413+ return nil , err
414+ }
415+
411416 if len (callCtx .Tool .Credentials ) > 0 {
412417 var err error
413418 env , err = r .handleCredentials (callCtx , monitor , env )
@@ -417,7 +422,6 @@ func (r *Runner) start(callCtx engine.Context, state *State, monitor Monitor, en
417422 }
418423
419424 var (
420- err error
421425 newState * State
422426 )
423427 callCtx .InputContext , newState , err = r .getContext (callCtx , state , monitor , env , input )
@@ -446,7 +450,10 @@ func (r *Runner) start(callCtx engine.Context, state *State, monitor Monitor, en
446450 }
447451
448452 if ! authResp .Accept {
449- msg := fmt .Sprintf ("[AUTHORIZATION ERROR]: %s" , authResp .Message )
453+ msg := authResp .Message
454+ if msg == "" {
455+ msg = "Tool call request has been denied"
456+ }
450457 return & State {
451458 Continuation : & engine.Return {
452459 Result : & msg ,
@@ -631,8 +638,12 @@ func (r *Runner) resume(callCtx engine.Context, monitor Monitor, env []string, s
631638 }
632639
633640 if state .ResumeInput != nil {
641+ input , err := r .handleInput (callCtx , monitor , env , * state .ResumeInput )
642+ if err != nil {
643+ return state , err
644+ }
634645 engineResults = append (engineResults , engine.CallResult {
635- User : * state . ResumeInput ,
646+ User : input ,
636647 })
637648 }
638649
@@ -689,16 +700,22 @@ func streamProgress(callCtx *engine.Context, monitor Monitor) (chan<- types.Comp
689700}
690701
691702func (r * Runner ) subCall (ctx context.Context , parentContext engine.Context , monitor Monitor , env []string , toolID , input , callID string , toolCategory engine.ToolCategory ) (* State , error ) {
692- callCtx , err := parentContext .SubCall (ctx , input , toolID , callID , toolCategory )
703+ callCtx , err := parentContext .SubCallContext (ctx , input , toolID , callID , toolCategory )
693704 if err != nil {
694705 return nil , err
695706 }
696707
708+ if toolCategory == engine .ContextToolCategory && callCtx .Tool .IsNoop () {
709+ return & State {
710+ Result : new (string ),
711+ }, nil
712+ }
713+
697714 return r .call (callCtx , monitor , env , input )
698715}
699716
700717func (r * Runner ) subCallResume (ctx context.Context , parentContext engine.Context , monitor Monitor , env []string , toolID , callID string , state * State , toolCategory engine.ToolCategory ) (* State , error ) {
701- callCtx , err := parentContext .SubCall (ctx , "" , toolID , callID , toolCategory )
718+ callCtx , err := parentContext .SubCallContext (ctx , "" , toolID , callID , toolCategory )
702719 if err != nil {
703720 return nil , err
704721 }
@@ -882,12 +899,7 @@ func (r *Runner) handleCredentials(callCtx engine.Context, monitor Monitor, env
882899 input = string (inputBytes )
883900 }
884901
885- subCtx , err := callCtx .SubCall (callCtx .Ctx , input , credToolRefs [0 ].ToolID , "" , engine .CredentialToolCategory ) // leaving callID as "" will cause it to be set by the engine
886- if err != nil {
887- return nil , fmt .Errorf ("failed to create subcall context for tool %s: %w" , credToolName , err )
888- }
889-
890- res , err := r .call (subCtx , monitor , env , input )
902+ res , err := r .subCall (callCtx .Ctx , callCtx , monitor , env , credToolRefs [0 ].ToolID , input , "" , engine .CredentialToolCategory )
891903 if err != nil {
892904 return nil , fmt .Errorf ("failed to run credential tool %s: %w" , credToolName , err )
893905 }
0 commit comments