( ctx context.Context, conversationID string, execID string, start *proto.AgentStart, el EventLog, a agent.Agent, history []*proto.Message, o agent.OutputHandler)
| 82 | } |
| 83 | |
| 84 | func (de *defaultExecutor) exec( |
| 85 | ctx context.Context, |
| 86 | conversationID string, |
| 87 | execID string, |
| 88 | start *proto.AgentStart, |
| 89 | el EventLog, |
| 90 | a agent.Agent, |
| 91 | history []*proto.Message, |
| 92 | o agent.OutputHandler) (proto.State, error) { |
| 93 | child := &agentExecutor{ |
| 94 | execID: execID, |
| 95 | eventLog: de.eventLog, |
| 96 | registry: de.registry, |
| 97 | } |
| 98 | |
| 99 | var allOutputs []*proto.Message |
| 100 | outputBuffer := func(outgoing *proto.AgentOutputs) error { |
| 101 | allOutputs = append(allOutputs, outgoing.Messages...) |
| 102 | if o != nil { |
| 103 | return o(outgoing) |
| 104 | } |
| 105 | return nil |
| 106 | } |
| 107 | |
| 108 | history = append(history, start.Messages...) |
| 109 | if len(history) == 0 { |
| 110 | return proto.State_STATE_UNSPECIFIED, errors.New("no inputs") |
| 111 | } |
| 112 | if err := logPending(ctx, el, execID, start); err != nil { |
| 113 | return proto.State_STATE_UNSPECIFIED, err |
| 114 | } |
| 115 | |
| 116 | start.Messages = history |
| 117 | if err := a.Connect(ctx, conversationID, execID, start, child, outputBuffer); err != nil { |
| 118 | // _ = logFailed(ctx, el, execID, start) // Attempt to log failure, but prioritize returning the original error. |
| 119 | return proto.State_STATE_UNSPECIFIED, err |
| 120 | } |
| 121 | |
| 122 | if len(allOutputs) > 0 { |
| 123 | // Log all the outputs at once. |
| 124 | // TODO: Log only at checkpoints. |
| 125 | if err := logOutputs(ctx, el, execID, start, allOutputs); err != nil { |
| 126 | return proto.State_STATE_UNSPECIFIED, err |
| 127 | } |
| 128 | |
| 129 | last := allOutputs[len(allOutputs)-1] |
| 130 | if last.GetContent().GetConfirmation() == nil || last.GetContent().GetConfirmation().GetQuestion() == "" { |
| 131 | // Log completed only if we are not waiting |
| 132 | // for an answer to a confirmation. |
| 133 | if err := logCompleted(ctx, el, execID, start); err != nil { |
| 134 | return proto.State_STATE_UNSPECIFIED, err |
| 135 | } |
| 136 | return proto.State_STATE_COMPLETED, nil |
| 137 | } |
| 138 | } |
| 139 | return proto.State_STATE_PENDING, nil |
| 140 | } |
| 141 |
no test coverage detected