refactor(runs): one conclude step ends an investigation, keeping Investigate under the complexity limit
This commit is contained in:
1 file changed
+12
-15
+12
-15
@@ -168,27 +168,21 @@ func Investigate(settings Settings, box Toolbox, judge Judge, ask Approver, noti
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, err := rc.Step("notify", func(ctx context.Context, key string) (bool, error) {
|
||||
return true, notify.Notify(ctx, findings(rc.RunID(), key, res, outcomes, review))
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out, err := json.Marshal(res)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("encode findings: %w", err)
|
||||
}
|
||||
if !res.Completed {
|
||||
return out, fmt.Errorf("investigation stopped: %s", res.StopReason)
|
||||
}
|
||||
return out, nil
|
||||
return conclude(rc, notify, res, outcomes, review)
|
||||
}
|
||||
}
|
||||
|
||||
// stopUnknown ends an investigation that stopped on an action whose outcome
|
||||
// can't be confirmed. Nothing further is proposed or run; the owner is told.
|
||||
func stopUnknown(rc *Context, notify Notifier, res AgentResult) (jsontext.Value, error) {
|
||||
return conclude(rc, notify, res, nil, memory.Review{})
|
||||
}
|
||||
|
||||
// conclude tells the owner what the investigation found and returns it as the
|
||||
// run's output, failing the run when the agent did not complete.
|
||||
func conclude(rc *Context, notify Notifier, res AgentResult, outcomes []approvalOutcome, review memory.Review) (jsontext.Value, error) {
|
||||
if _, err := rc.Step("notify", func(ctx context.Context, key string) (bool, error) {
|
||||
return true, notify.Notify(ctx, findings(rc.RunID(), key, res, nil, memory.Review{}))
|
||||
return true, notify.Notify(ctx, findings(rc.RunID(), key, res, outcomes, review))
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -196,7 +190,10 @@ func stopUnknown(rc *Context, notify Notifier, res AgentResult) (jsontext.Value,
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("encode findings: %w", err)
|
||||
}
|
||||
return out, fmt.Errorf("investigation stopped: %s", res.StopReason)
|
||||
if !res.Completed {
|
||||
return out, fmt.Errorf("investigation stopped: %s", res.StopReason)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// begun records that an action is about to run. It fails with an unknown
|
||||
|
||||
Reference in new issue
Block a user