(ctx context.Context, conversationID string, execID string, start *proto.AgentStart, o agent.OutputHandler)
| 51 | } |
| 52 | |
| 53 | func (ae *agentExecutor) Exec(ctx context.Context, conversationID string, execID string, start *proto.AgentStart, o agent.OutputHandler) (proto.State, error) { |
| 54 | execID = newExecID(ae.execID, execID) |
| 55 | a, ok := ae.registry[start.AgentId] |
| 56 | if !ok { |
| 57 | return proto.State_STATE_UNSPECIFIED, errors.New("no agent found: " + start.AgentId) |
| 58 | } |
| 59 | |
| 60 | // Log pending execution event with inputs for debuggability. |
| 61 | if err := ae.eventLog.AppendExec(ctx, &proto.ExecutionEvent{ |
| 62 | Timestamp: timestamppb.Now(), |
| 63 | ExecId: execID, |
| 64 | AgentId: start.AgentId, |
| 65 | Inputs: start.Messages, |
| 66 | State: proto.State_STATE_PENDING, |
| 67 | }); err != nil { |
| 68 | return proto.State_STATE_UNSPECIFIED, err |
| 69 | } |
| 70 | |
| 71 | var allOutputs []*proto.Message |
| 72 | outputBuffer := func(outgoing *proto.AgentOutputs) error { |
| 73 | allOutputs = append(allOutputs, outgoing.Messages...) |
| 74 | if o != nil { |
| 75 | return o(outgoing) |
| 76 | } |
| 77 | return nil |
| 78 | } |
| 79 | |
| 80 | if err := a.Connect(ctx, conversationID, execID, start, &agentExecutor{execID: execID, eventLog: ae.eventLog, registry: ae.registry}, outputBuffer); err != nil { |
| 81 | return proto.State_STATE_UNSPECIFIED, err |
| 82 | } |
| 83 | |
| 84 | // Log outputs. |
| 85 | if len(allOutputs) > 0 { |
| 86 | if err := ae.eventLog.AppendExec(ctx, &proto.ExecutionEvent{ |
| 87 | Timestamp: timestamppb.Now(), |
| 88 | ExecId: execID, |
| 89 | AgentId: start.AgentId, |
| 90 | Outputs: allOutputs, |
| 91 | State: proto.State_STATE_PENDING, |
| 92 | }); err != nil { |
| 93 | return proto.State_STATE_UNSPECIFIED, err |
| 94 | } |
| 95 | |
| 96 | if historyutil.WaitsForConfirmation(allOutputs) != nil { |
| 97 | return proto.State_STATE_PENDING, nil |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // Log completed. |
| 102 | if err := ae.eventLog.AppendExec(ctx, &proto.ExecutionEvent{ |
| 103 | Timestamp: timestamppb.Now(), |
| 104 | ExecId: execID, |
| 105 | AgentId: start.AgentId, |
| 106 | State: proto.State_STATE_COMPLETED, |
| 107 | }); err != nil { |
| 108 | return proto.State_STATE_UNSPECIFIED, err |
| 109 | } |
| 110 | return proto.State_STATE_COMPLETED, nil |
nothing calls this directly
no test coverage detected