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)
| 164 | // If id is empty, a UUID will be generated. |
| 165 | // If the execution already exists, it will be resumed with optional new inputs. |
| 166 | func (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 | |
| 209 | func (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) |
nothing calls this directly
no test coverage detected