MCPcopy
hub / github.com/google/ax / execLoop

Function execLoop

cmd/ax/exec.go:111–226  ·  view source on GitHub ↗
(ctx context.Context, id string, agentID string, input string, lastSeq int32)

Source from the content-addressed store, hash-verified

109}
110
111func execLoop(ctx context.Context, id string, agentID string, input string, lastSeq int32) error {
112 d := internal.NewDisplay(id)
113 d.DisplayHeader()
114
115 var inputs []*proto.Message
116 if !execResume {
117 var quit bool
118 var err error
119 input, quit, err = promptUser(d, input)
120 if err != nil {
121 return err
122 }
123 if quit {
124 return nil
125 }
126 inputs = []*proto.Message{
127 {
128 Role: "user",
129 Content: &proto.Content{
130 Type: &proto.Content_Text{
131 Text: &proto.TextContent{
132 Text: input,
133 },
134 },
135 },
136 },
137 }
138 }
139
140 for {
141 conf, err := runAutoExec(ctx, d, &proto.ExecRequest{
142 ConversationId: id,
143 AgentId: agentID,
144 Inputs: inputs,
145 LastSeq: lastSeq,
146 })
147 lastSeq = 0 // disable resuming from sequence, user sees the seq on the screen
148 if err != nil {
149 return err
150 }
151
152 if conf != nil {
153 for {
154 approved, err := d.PromptForApproval(conf.Question)
155 if err != nil {
156 return err
157 }
158 var decision []*proto.Message
159 if approved {
160 decision = []*proto.Message{{
161 Role: "user",
162 Content: &proto.Content{
163 Type: &proto.Content_Confirmation{
164 Confirmation: &proto.ConfirmationContent{
165 Id: conf.Id,
166 Decision: &proto.ConfirmationContent_Approval{
167 Approval: &proto.ApprovalDecision{Approved: true},
168 },

Callers 1

runExecFunction · 0.85

Calls 5

DisplayHeaderMethod · 0.95
PromptForApprovalMethod · 0.95
NewDisplayFunction · 0.92
promptUserFunction · 0.85
runAutoExecFunction · 0.85

Tested by

no test coverage detected