(ctx context.Context, conversationID string, execID string, agentID string, agentConfig []byte, history []*proto.Message, newInputs []*proto.Message, registry map[string]agent.Agent, handler ExecHandler)
| 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) |
| 211 | outputCapturer := func(outgoing *proto.AgentOutputs) error { |
| 212 | // Filter out internal-only messages. |
| 213 | var outputs []*proto.Message |
| 214 | for _, m := range outgoing.Messages { |
| 215 | if m.GetInternalOnly() { |
| 216 | continue |
| 217 | } |
| 218 | outputs = append(outputs, m) |
| 219 | } |
| 220 | if len(outputs) == 0 { |
| 221 | return nil |
| 222 | } |
| 223 | msg := &proto.ConversationEvent{ |
| 224 | ConversationId: conversationID, |
| 225 | ExecId: execID, |
| 226 | Messages: outputs, |
| 227 | State: proto.State_STATE_PENDING, |
| 228 | } |
| 229 | seq, err := d.eventLog.Append(ctx, msg) |
| 230 | if err != nil { |
| 231 | return err |
| 232 | } |
| 233 | return handler(&proto.ExecResponse{ |
| 234 | Outputs: msg.Messages, |
| 235 | Seq: seq, |
| 236 | }) |
| 237 | } |
| 238 | if _, err := d.eventLog.Append(ctx, &proto.ConversationEvent{ |
| 239 | ConversationId: conversationID, |
| 240 | ExecId: execID, |
| 241 | Messages: newInputs, |
| 242 | State: proto.State_STATE_PENDING, |
| 243 | }); err != nil { |
| 244 | return err |
| 245 | } |
| 246 | state, err := e.Exec(ctx, conversationID, execID, &proto.AgentStart{ |
| 247 | AgentId: agentID, |
| 248 | AgentConfig: agentConfig, |
| 249 | Messages: append(history, newInputs...), |
| 250 | }, outputCapturer) |
| 251 | if err != nil { |
| 252 | return err |
| 253 | } |
| 254 | _, err = d.eventLog.Append(ctx, &proto.ConversationEvent{ |
| 255 | ConversationId: conversationID, |
| 256 | ExecId: execID, |
| 257 | State: state, |
| 258 | }) |
| 259 | return err |
| 260 | } |
| 261 | |
| 262 | // Delete deletes all events for a specific conversation ID. |
| 263 | func (d *Controller) Delete(ctx context.Context, conversationID string) error { |
no test coverage detected