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

Function TestConfirmation

internal/controller/executor/executor_test.go:178–262  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

176}
177
178func TestConfirmation(t *testing.T) {
179 ctx := context.Background()
180
181 var runCount int
182 eventLog := memoryEventLog()
183
184 confID := "test-conf-id"
185 var childDone atomic.Bool
186 registry := map[string]agent.Agent{
187 "root": AgentFunc(func(inputs []*proto.Message, tm agent.Executor, o agent.OutputHandler) {
188 if _, err := tm.Exec(ctx, "test-conv", "child-task", &proto.AgentStart{
189 AgentId: "child",
190 Messages: inputs,
191 }, o); err != nil {
192 t.Fatal(err)
193 }
194 }),
195 "child": AgentFunc(func(inputs []*proto.Message, tm agent.Executor, o agent.OutputHandler) {
196 if runCount == 0 {
197 runCount++
198 log.Println("Asking for the question...")
199 if o != nil {
200 o(&proto.AgentOutputs{
201 Messages: []*proto.Message{{
202 Role: "model",
203 Content: &proto.Content{
204 Type: &proto.Content_Confirmation{
205 Confirmation: &proto.ConfirmationContent{Id: confID, Question: "proceed?"},
206 },
207 },
208 }},
209 })
210 }
211 return
212 }
213
214 lastInput := inputs[len(inputs)-1]
215 if lastInput.GetContent().GetConfirmation() == nil || lastInput.GetContent().GetConfirmation().GetDecision() == nil {
216 t.Fatal("no decision in the incoming inputs")
217 }
218
219 childDone.Store(true)
220 if o != nil {
221 o(&proto.AgentOutputs{
222 Messages: []*proto.Message{text("assistant", "child done")},
223 })
224 }
225 }),
226 }
227
228 tm := DefaultExecutor(eventLog, registry)
229
230 // First run: child returns a confirmation request.
231 if _, err := tm.Exec(ctx, "test-conv", "root-task", &proto.AgentStart{
232 AgentId: "root",
233 Messages: []*proto.Message{text("user", "hello!")},
234 }, nil); err != nil {
235 t.Fatal(err)

Callers

nothing calls this directly

Calls 8

memoryEventLogFunction · 0.85
AgentFuncFunction · 0.85
textFunction · 0.85
DefaultExecutorFunction · 0.85
GetConfirmationMethod · 0.80
GetContentMethod · 0.80
GetDecisionMethod · 0.80
ExecMethod · 0.65

Tested by

no test coverage detected