Drop workflow kinds, deliver reviews when done, rename/delete workflows
This commit is contained in:
@@ -85,11 +85,11 @@ func (m *Manager) recoverMergeAfterReviews(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
for _, id := range ids {
|
||||
m.reviewFinished(id)
|
||||
m.reviewFinished(id, false)
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) reviewFinished(reviewID string) {
|
||||
func (m *Manager) reviewFinished(reviewID string, deliver bool) {
|
||||
ctx := context.Background()
|
||||
r, err := m.store.GetReview(ctx, reviewID)
|
||||
if err != nil {
|
||||
@@ -112,6 +112,9 @@ func (m *Manager) reviewFinished(reviewID string) {
|
||||
if !settled {
|
||||
return
|
||||
}
|
||||
if deliver {
|
||||
m.deliverFindings(ctx, r, reviews)
|
||||
}
|
||||
ids := []string{}
|
||||
for _, sr := range reviews {
|
||||
ids = append(ids, sr.Id)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Workflow files
|
||||
|
||||
A workflow's file is YAML: an optional `description`, an optional `kind`, then `steps`, which run in order. The workflow's name is not in the file. Unknown fields are refused.
|
||||
A workflow's file is YAML: an optional `description`, then `steps`, which run in order. The workflow's name is not in the file. Unknown fields are refused.
|
||||
|
||||
`kind` is `task` (the default) or `review`. A task workflow runs on a brief, each stage as its own task. A review workflow is what a project names (with `set_review_workflow`) to review its tasks' snapshots: each stage is one reviewer agent on its `model`, given the task's change and its stage's `prompt` (what to look for); a stage after others also gets their reviews. Its stages can't use `agents`, and it may end with several stages.
|
||||
Any workflow can run on a brief, each stage as its own task, and any workflow whose stages are single agents can be a project's review workflow (set with `set_review_workflow`), which reviews its tasks' snapshots: each stage is then one reviewer agent on its `model`, given the task's change and its stage's `prompt` (what to look for), and a stage after others also gets their reviews. A project can't review with a workflow that has a team stage (`agents`).
|
||||
|
||||
Each step is exactly one of:
|
||||
|
||||
@@ -20,7 +20,7 @@ A stage gets the outputs of the stages that end the step before it: the last sta
|
||||
| `prompt` | The stage agent's instructions. |
|
||||
| `agents` | In place of `model`: a list of at least two, each with `name`, `model` and `prompt`, that runs the stage as a team. They work in the stage's one task and worktree and talk through a shared board; each gets the stage's `prompt` and then its own, and the first agent finishes the stage. |
|
||||
|
||||
Where a stage's task branches from follows from the shape. A stage after exactly one stage starts from the commit that stage finished at. A stage after a `parallel` starts from the default branch and is told the branches it can merge. A stage with nothing before it starts where the workflow was started. The workflow must end with one stage, which finishes it. An `order` or `parallel` can't be empty.
|
||||
Where a stage's task branches from follows from the shape. A stage after exactly one stage starts from the commit that stage finished at. A stage after a `parallel` starts from the default branch and is told the branches it can merge. A stage with nothing before it starts where the workflow was started. A workflow is finished once every stage has finished; when it ends with a `parallel`, each branch's last stage keeps its task to merge, and the run's other stage tasks are discarded. A review is delivered to the task's agent, every stage's findings in one message, once every stage has reviewed. An `order` or `parallel` can't be empty.
|
||||
|
||||
```yaml
|
||||
description: Build a change, review and test it in parallel, then fix what they found.
|
||||
|
||||
@@ -29,11 +29,11 @@ const leadGuidance = `You are the human's lead agent in byre, shown in the left
|
||||
- Questions from task agents: answer one yourself with answer_question only when the answer is clear, for example the agent's recommendation is plainly right given what the human has said, the human already decided it, or one of your notes settles it outright. Otherwise show it to the human with your recommendation and wait. When the human tells you an answer, give it with answer_question. Say which questions you answered and how, naming the note by its id when one decided it.
|
||||
- Notes: you learn how the human works and keep it with remember, forget and list_notes. byre adds every note to your instructions at the start of each lead session, so they outlast compaction; the human can read and delete them in the Settings tab. Write a note when the human shows a priority, a preference or the reasoning behind a choice that will recur: an answer that departs from the agent's recommendation (the answered signal shows both), a correction or overrule of you or a task agent, or a statement of how they want things done. Record the choice and the why, in their terms, general enough to apply to the next case and specific enough to act on, for example "Prefers replacing a state label over adding a tag beside it: keeps the picker uncluttered." File each note under the project it is about with project_id when it concerns that project's code, UI, docs or process, and with no project_id only when it holds for how the human works everywhere; apply a project's notes only to that project's tasks. Task agents start with their creator's every-project notes and their project's, and suggest new ones with suggest_note, which reaches you as a signal: save a suggestion only when it holds and your notes don't already cover it, choosing its project yourself, and otherwise drop it; neither needs a word to the human. Don't note one-off facts about a single task, and don't duplicate: update an existing note with remember and its id instead. When the human contradicts a note, update it or forget it. Before recommending anything, check your notes, and when one shaped the recommendation, cite its id.
|
||||
- Finished turns: read them and show the human only what matters: work finished and ready to merge, problems, decisions made. Stay quiet about routine progress.
|
||||
- Reviews: after each new snapshot of a task, the stages of its project's review workflow (a workflow of kind review, set per project with set_review_workflow) review the change, each a reviewer agent on its stage's model; a stage after others gets their reviews. A project with no review workflow isn't reviewed. The results are in the task's transcript, where its agent answers each finding with respond_to_finding (fixing, or ignoring with a reason), and read_transcript shows each review's findings. They are for the human to look at when they want; mention one only when its findings matter to what the human is deciding.
|
||||
- Reviews: after each new snapshot of a task, the stages of its project's review workflow (any saved workflow, set per project with set_review_workflow) review the change, each a reviewer agent on its stage's model; a stage after others gets their reviews. A project with no review workflow isn't reviewed. Once every stage has reviewed the snapshot, the task's agent gets all their findings in one message. The results are in the task's transcript, where its agent answers each finding with respond_to_finding (fixing, or ignoring with a reason), and read_transcript shows each review's findings. They are for the human to look at when they want; mention one only when its findings matter to what the human is deciding.
|
||||
- Dig into context with list_tasks, read_transcript, read_inbox and read_status (vendor rate limits and agent health), and with your own Read, Grep and Bash on a task's worktree path (from list_tasks). Don't edit files in task worktrees; ask the task's agent with send_message.
|
||||
- You can create tasks, start TODO items, message, interrupt and compact task agents, and merge or discard tasks. Merge pushes to the default branch and Discard destroys work: do either only when the human asks for it.
|
||||
- Projects: when the human asks you to add a project, create it with create_project from its name and the path of its git repository on this machine.
|
||||
- Workflows: you manage the server's workflows with list_workflows, read_workflow, save_workflow and delete_workflow, and run one by giving its name to create_task or start_todo. A workflow is a tree of steps run in order, each a stage, an order or a parallel; every stage runs as its own task on the stage's model once the step before it has finished, so stages fan out (a parallel after a stage) and fan in (a stage after a parallel); a stage's agent calls finish_stage to hand its output to the stages after it, signals tell you when a stage starts and when the workflow finishes, and when the final stage finishes byre discards the run's other stage tasks, leaving the final one to merge. Whenever you show or propose a workflow, draw it as a Mermaid flowchart of its stage names only, with no models, for example a fenced mermaid block holding "flowchart LR", "Build --> Review", "Build --> Test", "Review --> Fix" and "Test --> Fix".
|
||||
- Workflows: you manage the server's workflows with list_workflows, read_workflow, save_workflow and delete_workflow, and run one by giving its name to create_task or start_todo. A workflow is a tree of steps run in order, each a stage, an order or a parallel; every stage runs as its own task on the stage's model once the step before it has finished, so stages fan out (a parallel after a stage) and fan in (a stage after a parallel); a stage's agent calls finish_stage to hand its output to the stages after it, signals tell you when a stage starts and when the workflow finishes, and the workflow finishes once every stage has; byre then discards the run's other stage tasks, leaving the task of each last stage (one per branch when it ends in a parallel) to merge. Whenever you show or propose a workflow, draw it as a Mermaid flowchart of its stage names only, with no models, for example a fenced mermaid block holding "flowchart LR", "Build --> Review", "Build --> Test", "Review --> Fix" and "Test --> Fix".
|
||||
- Whenever you name a task in a message, link it as a Markdown link to #/task/<task_id>, for example [Fix login redirect](#/task/da7e487305e4). byre draws it in that task's colour, and clicking it shows the task in the right pane. To open a specific tab, append it: #/task/<task_id>/<tab>. When you point the human at a question to answer or a finished turn, link to #/task/<task_id>/transcript.
|
||||
- Keep messages short; the human reads them in half the screen. Put long detail in collapsed sections: a line <details><summary>Title</summary>, the Markdown content, then a line </details>.
|
||||
- You are long-running. Your context window is large. byre sends you a signal once your context passes a quarter of its window; then call compact_self at a logical point (a piece of work wrapped up, a topic closed), and not before; when the turn ends, byre replaces you with a fresh session that starts from your handoff.
|
||||
@@ -363,7 +363,10 @@ func (m *Manager) Observe(events []api.Event) {
|
||||
go m.promptReady(*ev.TaskId, ev.Payload["from"])
|
||||
}
|
||||
if ev.Kind == "task.workflow_finished" && ev.TaskId != nil {
|
||||
go m.promptReady(*ev.TaskId, nil)
|
||||
kept, _ := ev.Payload["kept"].([]string)
|
||||
for _, id := range kept {
|
||||
go m.promptReady(id, nil)
|
||||
}
|
||||
}
|
||||
switch ev.Kind {
|
||||
case "inbox.created", "inbox.updated", "task.created", "task.merge_queued", "task.merge_after_review", "task.merge_after_review_cancelled", "task.merge_after_review_dropped", "task.merge_started", "task.merged", "task.discarded", "turn.ended", "task.workflow_stage", "task.workflow_finished", "review.started", "review.finished", "task.state", "task.ready", "task.discard_suggested":
|
||||
|
||||
+56
-41
@@ -196,8 +196,8 @@ func (m *Manager) startReviews(ctx context.Context, task api.Task, snap api.Snap
|
||||
}
|
||||
|
||||
def, err := m.store.GetWorkflow(ctx, project.ReviewWorkflow)
|
||||
if err == nil && def.Kind != api.WorkflowKindReview {
|
||||
err = fmt.Errorf("it is a task workflow, not a review workflow")
|
||||
if err == nil {
|
||||
err = reviewProblem(def)
|
||||
}
|
||||
if err != nil {
|
||||
return m.store.CreateReview(ctx, api.Review{
|
||||
@@ -310,7 +310,7 @@ func (m *Manager) startReviewer(ctx context.Context, task api.Task, project api.
|
||||
slog.Error("record review that didn't start", "task", task.Id, "stage", stage, "err", rerr)
|
||||
return
|
||||
}
|
||||
go m.reviewFinished(reviewID)
|
||||
go m.reviewFinished(reviewID, true)
|
||||
}()
|
||||
|
||||
prompt, err := m.reviewPrompt(ctx, task, project, snap, def, stage, inputs)
|
||||
@@ -472,66 +472,81 @@ func (m *Manager) submitReview(ctx context.Context, l *live, raw json.RawMessage
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(findings) > 0 {
|
||||
go m.forwardFindings(l.taskID, l.reviewID)
|
||||
}
|
||||
go m.reviewFinished(l.reviewID)
|
||||
go m.reviewFinished(l.reviewID, true)
|
||||
return "Review recorded. End your turn now with one line.", nil
|
||||
}
|
||||
|
||||
func (m *Manager) forwardFindings(taskID, reviewID string) {
|
||||
ctx := context.Background()
|
||||
r, err := m.store.GetReview(ctx, reviewID)
|
||||
if err != nil {
|
||||
slog.Error("load review to forward", "review", reviewID, "err", err)
|
||||
func (m *Manager) deliverFindings(ctx context.Context, r api.Review, reviews []api.Review) {
|
||||
last := r
|
||||
for _, sr := range reviews {
|
||||
if sr.FinishedAt != nil && last.FinishedAt != nil && (sr.FinishedAt.After(*last.FinishedAt) || sr.FinishedAt.Equal(*last.FinishedAt) && sr.Id > last.Id) {
|
||||
last = sr
|
||||
}
|
||||
}
|
||||
if last.Id != r.Id {
|
||||
return
|
||||
}
|
||||
s, found, err := m.liveSession(ctx, taskID)
|
||||
latest, err := m.store.LastReviewable(ctx, r.TaskId)
|
||||
if err != nil || latest.N != r.SnapshotN {
|
||||
return
|
||||
}
|
||||
text := findingsMessage(r.SnapshotN, reviews)
|
||||
if text == "" {
|
||||
return
|
||||
}
|
||||
s, found, err := m.liveSession(ctx, r.TaskId)
|
||||
if err != nil {
|
||||
slog.Error("list sessions to forward review", "review", reviewID, "err", err)
|
||||
slog.Error("list sessions to deliver findings", "task", r.TaskId, "err", err)
|
||||
return
|
||||
}
|
||||
if !found {
|
||||
slog.Info("review findings not forwarded, task has no live agent", "review", reviewID, "task", taskID)
|
||||
slog.Info("review findings not delivered, task has no live agent", "task", r.TaskId, "snapshot", r.SnapshotN)
|
||||
return
|
||||
}
|
||||
_, _, err = m.Message(ctx, s.Id, "byre", findingsMessage(r), "", "")
|
||||
_, _, err = m.Message(ctx, s.Id, "byre", text, "", "")
|
||||
if err != nil {
|
||||
slog.Error("forward review findings", "review", reviewID, "session", s.Id, "err", err)
|
||||
slog.Error("deliver review findings", "task", r.TaskId, "snapshot", r.SnapshotN, "session", s.Id, "err", err)
|
||||
return
|
||||
}
|
||||
slog.Info("review findings forwarded", "review", reviewID, "session", s.Id)
|
||||
slog.Info("review findings delivered", "task", r.TaskId, "snapshot", r.SnapshotN, "session", s.Id)
|
||||
}
|
||||
|
||||
const findingsPreamble = "A reviewer looked at snapshot #"
|
||||
const findingsPreamble = "The review of snapshot #"
|
||||
|
||||
func isFindingsMessage(actor, text string) bool {
|
||||
return actor == "byre" && strings.HasPrefix(text, findingsPreamble)
|
||||
}
|
||||
|
||||
func findingsMessage(r api.Review) string {
|
||||
res := map[string]any{}
|
||||
if r.Result != nil {
|
||||
res = *r.Result
|
||||
}
|
||||
func findingsMessage(n int, reviews []api.Review) string {
|
||||
b := &strings.Builder{}
|
||||
fmt.Fprintf(b, findingsPreamble+"%d of your work as reviewer %q and raised the findings below. Reviewers can be wrong or miss context: check each one against the code and your brief. "+
|
||||
"Before you change anything, answer each finding with respond_to_finding (snapshot %d, reviewer %q and the finding's number): fixing if it holds up and you'll act on it, ignoring with your reason if you're leaving it. "+
|
||||
"The human sees your answers on the findings and can overrule an ignore.", r.SnapshotN, r.Stage, r.SnapshotN, r.Stage)
|
||||
findings, _ := res["findings"].([]any)
|
||||
for i, f := range findings {
|
||||
fm, _ := f.(map[string]any)
|
||||
where := ""
|
||||
if p, ok := fm["path"].(string); ok && p != "" {
|
||||
where = p
|
||||
if line, ok := fm["line"].(float64); ok && line > 0 {
|
||||
where += fmt.Sprintf(":%d", int(line))
|
||||
}
|
||||
where = " (`" + where + "`)"
|
||||
for _, r := range reviews {
|
||||
if r.State != api.ReviewStateDone || r.Result == nil {
|
||||
continue
|
||||
}
|
||||
findings, _ := (*r.Result)["findings"].([]any)
|
||||
if len(findings) == 0 {
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(b, "\n\n## Reviewer %q", r.Stage)
|
||||
for i, f := range findings {
|
||||
fm, _ := f.(map[string]any)
|
||||
where := ""
|
||||
if p, ok := fm["path"].(string); ok && p != "" {
|
||||
where = p
|
||||
if line, ok := fm["line"].(float64); ok && line > 0 {
|
||||
where += fmt.Sprintf(":%d", int(line))
|
||||
}
|
||||
where = " (`" + where + "`)"
|
||||
}
|
||||
fmt.Fprintf(b, "\n\n**Finding %d: [%v] %v**%s\n\n%s", i+1, fm["severity"], fm["title"], where, strings.TrimSpace(fmt.Sprint(fm["detail"])))
|
||||
}
|
||||
fmt.Fprintf(b, "\n\n**Finding %d: [%v] %v**%s\n\n%s", i+1, fm["severity"], fm["title"], where, strings.TrimSpace(fmt.Sprint(fm["detail"])))
|
||||
}
|
||||
return b.String()
|
||||
if b.Len() == 0 {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf(findingsPreamble+"%d of your work has finished, and its reviewers raised the findings below. Reviewers can be wrong or miss context: check each one against the code and your brief. "+
|
||||
"Before you change anything, answer each finding with respond_to_finding (snapshot %d, the reviewer's name and the finding's number): fixing if it holds up and you'll act on it, ignoring with your reason if you're leaving it. "+
|
||||
"The human sees your answers on the findings and can overrule an ignore.", n, n) + b.String()
|
||||
}
|
||||
|
||||
type findingResponseArgs struct {
|
||||
@@ -722,7 +737,7 @@ func (m *Manager) failReview(ctx context.Context, reviewID, reason string) {
|
||||
return
|
||||
}
|
||||
slog.Info("review failed", "review", reviewID, "reason", reason)
|
||||
go m.reviewFinished(reviewID)
|
||||
go m.reviewFinished(reviewID, true)
|
||||
}
|
||||
|
||||
func (m *Manager) cancelReviews(ctx context.Context, task api.Task, project api.Project) {
|
||||
@@ -824,7 +839,7 @@ func (m *Manager) recoverReviews(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
for _, id := range done {
|
||||
go m.reviewFinished(id)
|
||||
go m.reviewFinished(id, false)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"g.fc.run/ai/byre/internal/workflow"
|
||||
)
|
||||
|
||||
func (m *Manager) SaveWorkflow(ctx context.Context, name string, file []byte, actor string) (api.WorkflowSummary, error) {
|
||||
func (m *Manager) SaveWorkflow(ctx context.Context, name, from string, file []byte, actor string) (api.WorkflowSummary, error) {
|
||||
name, err := workflow.CleanName(name)
|
||||
if err != nil {
|
||||
return api.WorkflowSummary{}, err
|
||||
@@ -24,15 +24,14 @@ func (m *Manager) SaveWorkflow(ctx context.Context, name string, file []byte, ac
|
||||
if err != nil {
|
||||
return api.WorkflowSummary{}, err
|
||||
}
|
||||
err = m.store.PutWorkflow(ctx, name, def, actor)
|
||||
err = m.store.PutWorkflow(ctx, name, from, def, actor)
|
||||
if errors.Is(err, store.ErrWorkflowExists) {
|
||||
return api.WorkflowSummary{}, fmt.Errorf("%w: %w", ErrConflict, err)
|
||||
}
|
||||
if err != nil {
|
||||
return api.WorkflowSummary{}, err
|
||||
}
|
||||
kind := api.WorkflowSummaryKindTask
|
||||
if def.Kind == api.WorkflowKindReview {
|
||||
kind = api.WorkflowSummaryKindReview
|
||||
}
|
||||
return api.WorkflowSummary{Name: name, Description: def.Description, Kind: kind}, nil
|
||||
return api.WorkflowSummary{Name: name, Description: def.Description}, nil
|
||||
}
|
||||
|
||||
func (m *Manager) SetReviewWorkflow(ctx context.Context, projectID, name, actor string) (api.Project, error) {
|
||||
@@ -42,13 +41,23 @@ func (m *Manager) SetReviewWorkflow(ctx context.Context, projectID, name, actor
|
||||
if err != nil {
|
||||
return api.Project{}, err
|
||||
}
|
||||
if def.Kind != api.WorkflowKindReview {
|
||||
return api.Project{}, fmt.Errorf("%w: workflow %q is a task workflow; a project reviews with a workflow of kind review", ErrInvalid, name)
|
||||
err = reviewProblem(def)
|
||||
if err != nil {
|
||||
return api.Project{}, fmt.Errorf("%w: workflow %q can't review: %w", ErrInvalid, name, err)
|
||||
}
|
||||
}
|
||||
return m.store.SetReviewWorkflow(ctx, projectID, name, actor)
|
||||
}
|
||||
|
||||
func reviewProblem(def api.WorkflowDefinition) error {
|
||||
for _, s := range workflow.Stages(def) {
|
||||
if s.Agents != nil {
|
||||
return fmt.Errorf("stage %q is a team, and each review stage is one reviewer", s.Stage)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *Manager) WorkflowFile(ctx context.Context, name string) ([]byte, error) {
|
||||
def, err := m.store.GetWorkflow(ctx, name)
|
||||
if err != nil {
|
||||
@@ -230,9 +239,6 @@ func (m *Manager) StartWorkflow(ctx context.Context, project api.Project, creato
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if frozen.Definition.Kind == api.WorkflowKindReview {
|
||||
return nil, fmt.Errorf("%w: workflow %q is a review workflow, which a project names to review its snapshots; it doesn't run on a brief", ErrInvalid, name)
|
||||
}
|
||||
frozen.Brief = brief
|
||||
frozen.Title = title
|
||||
|
||||
@@ -405,11 +411,40 @@ func (m *Manager) nextStage(ctx context.Context, sessionID string) ([]string, er
|
||||
|
||||
next := workflow.Next(frozen.Definition, *task.WorkflowStage)
|
||||
if len(next) == 0 {
|
||||
err = m.discardStages(ctx, task)
|
||||
finished, err := m.store.WorkflowFinished(ctx, *task.WorkflowRun)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, m.store.FinishWorkflow(ctx, task, sess.Id, frozen.Name, output)
|
||||
if finished {
|
||||
return nil, m.store.ClearStage(ctx, sess.Id)
|
||||
}
|
||||
tasks, err := m.store.RunTasks(ctx, *task.WorkflowRun)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
keep := map[string]bool{}
|
||||
kept := []string{}
|
||||
outputs := []string{}
|
||||
for _, end := range workflow.Ends(frozen.Definition) {
|
||||
p, found, err := m.finishedStage(ctx, tasks, end)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !found {
|
||||
return nil, m.store.ClearStage(ctx, sess.Id)
|
||||
}
|
||||
keep[p.task.Id] = true
|
||||
kept = append(kept, p.task.Id)
|
||||
outputs = append(outputs, fmt.Sprintf("## %s\n\n%s", end, strings.TrimSpace(p.output)))
|
||||
}
|
||||
if len(outputs) > 1 {
|
||||
output = strings.Join(outputs, "\n\n")
|
||||
}
|
||||
err = m.discardStages(ctx, tasks, keep)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, m.store.FinishWorkflow(ctx, task, sess.Id, frozen.Name, output, kept)
|
||||
}
|
||||
|
||||
started := []string{}
|
||||
@@ -555,16 +590,12 @@ func teamMember(members []api.TeamMember, name string) (api.TeamMember, error) {
|
||||
return api.TeamMember{}, fmt.Errorf("the stage's frozen workflow has no agent %q", name)
|
||||
}
|
||||
|
||||
func (m *Manager) discardStages(ctx context.Context, final api.Task) error {
|
||||
tasks, err := m.store.RunTasks(ctx, *final.WorkflowRun)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
func (m *Manager) discardStages(ctx context.Context, tasks []api.Task, keep map[string]bool) error {
|
||||
for _, t := range tasks {
|
||||
if t.Id == final.Id || t.Status != api.TaskStatusActive {
|
||||
if keep[t.Id] || t.Status != api.TaskStatusActive {
|
||||
continue
|
||||
}
|
||||
_, err = m.Discard(ctx, t, "byre")
|
||||
_, err := m.Discard(ctx, t, "byre")
|
||||
if errors.Is(err, ErrConflict) {
|
||||
slog.Info("stage task not discarded", "task", t.Id, "err", err)
|
||||
continue
|
||||
@@ -599,12 +630,12 @@ func (m *Manager) finishStageTool(l *live) mcp.Tool {
|
||||
return mcp.Tool{
|
||||
Name: "finish_stage",
|
||||
Description: "Finish this task's stage of its workflow. Call it once the stage's work is done; when this turn ends, byre hands the output to the stages that come after this one, " +
|
||||
"each of which starts in its own task once every stage it comes after has finished (after the final stage, the workflow is finished). Calling it again in the same turn replaces the output. " +
|
||||
"each of which starts in its own task once every stage it comes after has finished (once every stage has finished, the workflow is finished). Calling it again in the same turn replaces the output. " +
|
||||
"The call counts only for the turn that makes it: if that turn ends in an error or is interrupted, it is discarded, and you call it again once the stage's work is done.",
|
||||
InputSchema: json.RawMessage(`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"output": {"type": "string", "description": "What the stages after this one start from: everything they need from this stage, since they see nothing else of your context. For the final stage, what the workflow produced."}
|
||||
"output": {"type": "string", "description": "What the stages after this one start from: everything they need from this stage, since they see nothing else of your context. For a last stage, what this branch of the workflow produced."}
|
||||
},
|
||||
"required": ["output"]
|
||||
}`),
|
||||
@@ -636,7 +667,7 @@ func (m *Manager) finishStageTool(l *live) mcp.Tool {
|
||||
}
|
||||
next := workflow.Next(frozen.Definition, l.stage)
|
||||
if len(next) == 0 {
|
||||
return "This is the workflow's final stage: it finishes when this turn ends, and byre discards the workflow's other stage tasks. End your turn now with your summary.", nil
|
||||
return lastStageText(frozen.Definition) + " End your turn now with your summary.", nil
|
||||
}
|
||||
return fmt.Sprintf("When this turn ends, byre hands the output to %s. End your turn now with your summary.", quoteList(next)), nil
|
||||
},
|
||||
@@ -659,9 +690,17 @@ func quoteList(names []string) string {
|
||||
return strings.Join(quoted, ", ")
|
||||
}
|
||||
|
||||
func lastStageText(def api.WorkflowDefinition) string {
|
||||
ends := workflow.Ends(def)
|
||||
if len(ends) == 1 {
|
||||
return "This is the workflow's last stage: the workflow finishes when this turn ends, and byre discards its other stage tasks."
|
||||
}
|
||||
return fmt.Sprintf("This is one of the workflow's last stages (%s): the workflow finishes once all of them have, and byre then discards its other stage tasks, keeping each last stage's task.", quoteList(ends))
|
||||
}
|
||||
|
||||
func stageGuidance(frozen store.FrozenWorkflow, stage string) string {
|
||||
next := workflow.Next(frozen.Definition, stage)
|
||||
then := "it is the workflow's final stage, so the workflow then finishes and byre discards its other stage tasks"
|
||||
then := strings.TrimSuffix(lastStageText(frozen.Definition), ".")
|
||||
if len(next) > 0 {
|
||||
then = fmt.Sprintf("byre then hands the output to %s, each in its own task, which gets the output and nothing else of your context", quoteList(next))
|
||||
}
|
||||
@@ -740,7 +779,7 @@ func (m *Manager) workflowTools(tool func(name, description, schema string, run
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
w, err := m.SaveWorkflow(ctx, args.Name, []byte(args.Definition), leadActor(user.Login))
|
||||
w, err := m.SaveWorkflow(ctx, args.Name, "", []byte(args.Definition), leadActor(user.Login))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -748,7 +787,7 @@ func (m *Manager) workflowTools(tool func(name, description, schema string, run
|
||||
}),
|
||||
|
||||
tool("set_review_workflow",
|
||||
"Set the review workflow (a saved workflow of kind review) whose stages review every snapshot of a project's tasks, from the next snapshot on; an empty workflow turns reviews off for the project. Only when the human asks.",
|
||||
"Set the review workflow (any saved workflow whose stages are single agents, not teams) whose stages review every snapshot of a project's tasks, from the next snapshot on; an empty workflow turns reviews off for the project. Only when the human asks.",
|
||||
`{"type": "object", "properties": {
|
||||
"project_id": {"type": "string"},
|
||||
"workflow": {"type": "string"}
|
||||
|
||||
Reference in New Issue
Block a user