MCPcopy Index your code
hub / github.com/google/ax / Exec

Method Exec

internal/controller/controller.go:166–207  ·  view source on GitHub ↗

Exec executes a new agentic loop execution or resumes an existing one. If id is empty, a UUID will be generated. If the execution already exists, it will be resumed with optional new inputs.

(ctx context.Context, req *proto.ExecRequest, handler ExecHandler)

Source from the content-addressed store, hash-verified

164// If id is empty, a UUID will be generated.
165// If the execution already exists, it will be resumed with optional new inputs.
166func (d *Controller) Exec(ctx context.Context, req *proto.ExecRequest, handler ExecHandler) error {
167 if req.ConversationId == "" {
168 return fmt.Errorf("conversation_id is required")
169 }
170
171 planner, err := d.plannerBuilder(ctx, d.registry)
172 if err != nil {
173 return fmt.Errorf("failed to create planner: %w", err)
174 }
175
176 registry := maps.Clone(d.registry.Map())
177 registry[plannerAgentID] = planner
178
179 // TODO(lhuan): consider remove this.
180 registry[geminiAgentID] = gemini.NewGeminiAgent()
181
182 if req.AgentId == "" {
183 req.AgentId = plannerAgentID
184 }
185
186 // Replay the execution history if any.
187 history, done, err := d.tryResuming(ctx, req, d.eventLog, registry, handler)
188 if err != nil {
189 return err
190 }
191 if done {
192 // Nothing else to do, new inputs are used in the replay.
193 return nil
194 }
195
196 return d.execute(
197 ctx,
198 req.ConversationId,
199 uuid.NewString(),
200 req.AgentId,
201 req.AgentConfig,
202 history,
203 req.Inputs,
204 registry,
205 handler,
206 )
207}
208
209func (d *Controller) execute(ctx context.Context, conversationID string, execID string, agentID string, agentConfig []byte, history []*proto.Message, newInputs []*proto.Message, registry map[string]agent.Agent, handler ExecHandler) error {
210 e := executor.DefaultExecutor(d.eventLog, registry)

Callers

nothing calls this directly

Calls 4

tryResumingMethod · 0.95
executeMethod · 0.95
NewGeminiAgentFunction · 0.92
MapMethod · 0.80

Tested by

no test coverage detected