Run scheduled tasks through workflows
This commit is contained in:
@@ -33,7 +33,7 @@ const leadGuidance = `You are the human's lead agent in byre, shown in the left
|
||||
- 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 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. Each last stage's agent is asked whether its task is ready to merge as soon as its own stage has finished and been reviewed, without waiting for the other last stages. Whenever you show or propose a workflow, draw it as a fenced diagram block (its format is the diagrams knowledge-base article) of its stage names only, with no models: one row per step, a parallel's stages side by side in one row, and an arrow into each stage from the stages before it. For example, rows holding Build; Review and Test; Fix, with the arrows "build -> review", "build -> test", "review -> fix" and "test -> fix".
|
||||
- Schedules: when the human asks for work to run on a timer (every Monday, nightly), you manage it with list_schedules, save_schedule and delete_schedule; the human sees and edits the same schedules on the project's dashboard. On each run, byre creates a task from a schedule's prompt or workflow as create_task would, created by byre, and you get its created signal; a run that fails to start reaches you as a signal.
|
||||
- Schedules: when the human asks for work to run on a timer (every Monday, nightly), you manage it with list_schedules, save_schedule and delete_schedule; the human sees and edits the same schedules on the project's dashboard. Every schedule runs a saved workflow: for a one-agent chore, save a one-stage workflow with save_workflow first. On each run, byre starts the schedule's workflow as create_task with workflow would, created by byre, and you get its created signal; a run that fails to start reaches you as a signal.
|
||||
- Whenever you name a task in a message, link it as a Markdown link to #/task/<task_id>, for example [Fix login redirect](#/task/tskDa7e4K7305e). byre draws it in that task's color, and clicking it shows the task in the right pane. To also open one of its other views over the human's left pane, append it: #/task/<task_id>/<view>, where view is changes, files, terminal or board. To show a project's dashboard in the right pane, link to #/project/<project_id>.
|
||||
- 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.
|
||||
|
||||
@@ -570,7 +570,7 @@ func (m *Manager) leadTools(l *live) []mcp.Tool {
|
||||
m.mu.Unlock()
|
||||
return "byre will ask for your handoff once this turn ends.", nil
|
||||
}),
|
||||
}, append(append(m.workflowTools(tool), m.scheduleTools(l, tool)...), m.noteTools(tool)...)...)
|
||||
}, append(append(m.workflowTools(tool), m.scheduleTools(tool)...), m.noteTools(tool)...)...)
|
||||
}
|
||||
|
||||
func (m *Manager) SetFocus(ctx context.Context, login string, f api.Focus, actor string) error {
|
||||
|
||||
+15
-46
@@ -20,20 +20,10 @@ func (m *Manager) SaveSchedule(ctx context.Context, projectID, scheduleID string
|
||||
return api.Schedule{}, err
|
||||
}
|
||||
sc.Prompt = strings.TrimSpace(deref(save.Prompt))
|
||||
sc.Model = strings.TrimSpace(deref(save.Model))
|
||||
sc.Workflow = strings.TrimSpace(deref(save.Workflow))
|
||||
switch {
|
||||
case sc.Workflow != "" && sc.Model != "":
|
||||
return api.Schedule{}, errModelWithWorkflow
|
||||
case sc.Workflow == "" && sc.Prompt == "":
|
||||
return api.Schedule{}, fmt.Errorf("%w: prompt is required without a workflow", ErrInvalid)
|
||||
case sc.Workflow == "" && sc.Model == "":
|
||||
return api.Schedule{}, fmt.Errorf("%w: model is required without a workflow", ErrInvalid)
|
||||
case sc.Workflow != "":
|
||||
_, err = m.store.GetWorkflow(ctx, sc.Workflow)
|
||||
if err != nil {
|
||||
return api.Schedule{}, err
|
||||
}
|
||||
sc.Workflow = strings.TrimSpace(save.Workflow)
|
||||
_, err = m.store.GetWorkflow(ctx, sc.Workflow)
|
||||
if err != nil {
|
||||
return api.Schedule{}, err
|
||||
}
|
||||
|
||||
if scheduleID != "" {
|
||||
@@ -118,19 +108,8 @@ func (m *Manager) startScheduled(ctx context.Context, sc api.Schedule) error {
|
||||
if user.GitName == "" || user.GitEmail == "" {
|
||||
return ErrNoGitIdentity
|
||||
}
|
||||
if sc.Workflow != "" {
|
||||
_, err = m.StartWorkflow(ctx, project, user, sc.Title, project.DefaultBranch, "byre", sc.Workflow, sc.Prompt, nil, "")
|
||||
return err
|
||||
}
|
||||
task, err := m.CreateTask(ctx, project, sc.Title, user.Login, project.DefaultBranch, "byre")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = m.create(ctx, task, user, "", sc.Prompt, sc.Model, "byre", "", "", nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("task %s created, but its agent did not start: %w", task.Id, err)
|
||||
}
|
||||
return nil
|
||||
_, err = m.StartWorkflow(ctx, project, user, sc.Title, project.DefaultBranch, "byre", sc.Workflow, sc.Prompt, nil, "")
|
||||
return err
|
||||
}
|
||||
|
||||
func scheduleText(sc api.Schedule) string {
|
||||
@@ -150,22 +129,17 @@ func scheduleText(sc api.Schedule) string {
|
||||
default:
|
||||
fmt.Fprintf(b, " at %02d:%02d", sc.Hour, sc.Minute)
|
||||
}
|
||||
fmt.Fprintf(b, ", next run %s", sc.NextRun.Local().Format(time.RFC3339))
|
||||
if sc.Workflow != "" {
|
||||
fmt.Fprintf(b, ", workflow %q", sc.Workflow)
|
||||
} else {
|
||||
fmt.Fprintf(b, ", model %s", sc.Model)
|
||||
}
|
||||
fmt.Fprintf(b, ", next run %s, workflow %q", sc.NextRun.Local().Format(time.RFC3339), sc.Workflow)
|
||||
if sc.Prompt != "" {
|
||||
fmt.Fprintf(b, "\n prompt: %s", clip(sc.Prompt, 500))
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func (m *Manager) scheduleTools(l *live, tool func(name, description, schema string, run func(ctx context.Context, user api.User, raw json.RawMessage) (string, error)) mcp.Tool) []mcp.Tool {
|
||||
func (m *Manager) scheduleTools(tool func(name, description, schema string, run func(ctx context.Context, user api.User, raw json.RawMessage) (string, error)) mcp.Tool) []mcp.Tool {
|
||||
return []mcp.Tool{
|
||||
tool("list_schedules",
|
||||
"List the schedules: each one's id, project, owner, title, timing, model or workflow, prompt, and next run in the server's local time. Give project_id for one project's.",
|
||||
"List the schedules: each one's id, project, owner, title, timing, workflow, prompt, and next run in the server's local time. Give project_id for one project's.",
|
||||
`{"type": "object", "properties": {"project_id": {"type": "string"}}}`,
|
||||
func(ctx context.Context, user api.User, raw json.RawMessage) (string, error) {
|
||||
args := struct {
|
||||
@@ -190,25 +164,24 @@ func (m *Manager) scheduleTools(l *live, tool func(name, description, schema str
|
||||
}),
|
||||
|
||||
tool("save_schedule",
|
||||
"Create a schedule, or with schedule_id replace one's settings (project_id is then ignored). On each run byre creates a task in the project from its default branch, as create_task does, "+
|
||||
"as the schedule's owner (you, for one you create), and you get its created signal. Times are the server's local time. "+
|
||||
"Create a schedule, or with schedule_id replace one's settings (project_id is then ignored). On each run byre starts the workflow in the project from its default branch, as create_task with workflow does, "+
|
||||
"as the schedule's owner (you, for one you create). Times are the server's local time. "+
|
||||
"every hour runs at minute past each hour (hour 0); day at hour:minute; week at hour:minute on each of weekdays; month at hour:minute on day_of_month, or the month's last day when shorter. "+
|
||||
"weekdays only for week, day_of_month only for month. Each run's agent sees nothing else, so the prompt must be a complete brief. "+
|
||||
"With workflow, each run starts that workflow, prompt is optional and is its brief, and model can't be given; the workflow is looked up by name at each run. "+
|
||||
"weekdays only for week, day_of_month only for month. prompt is optional and is added to every stage's first message as the run's brief. "+
|
||||
"The workflow is looked up by name at each run. "+
|
||||
"A run missed while byre was down happens once when it starts. The human sees and edits schedules on the project's dashboard. Only when the human asks.",
|
||||
`{"type": "object", "properties": {
|
||||
"project_id": {"type": "string"},
|
||||
"schedule_id": {"type": "string"},
|
||||
"title": {"type": "string", "description": "The title of each task it creates."},
|
||||
"title": {"type": "string", "description": "The title of each run."},
|
||||
"every": {"type": "string", "enum": ["hour", "day", "week", "month"]},
|
||||
"weekdays": {"type": "array", "items": {"type": "string", "enum": ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]}},
|
||||
"hour": {"type": "integer", "minimum": 0, "maximum": 23},
|
||||
"minute": {"type": "integer", "minimum": 0, "maximum": 59},
|
||||
"day_of_month": {"type": "integer", "minimum": 1, "maximum": 31},
|
||||
"prompt": {"type": "string"},
|
||||
"model": {"type": "string", "description": "Without workflow, the agent's model; defaults to yours."},
|
||||
"workflow": {"type": "string", "description": "The name of a workflow for each run to freeze a copy of and run."}
|
||||
}, "required": ["title", "every", "hour", "minute"]}`,
|
||||
}, "required": ["title", "every", "hour", "minute", "workflow"]}`,
|
||||
func(ctx context.Context, user api.User, raw json.RawMessage) (string, error) {
|
||||
args := struct {
|
||||
ProjectID string `json:"project_id"`
|
||||
@@ -223,10 +196,6 @@ func (m *Manager) scheduleTools(l *live, tool func(name, description, schema str
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if deref(save.Workflow) == "" {
|
||||
model := m.modelOr(deref(save.Model), l)
|
||||
save.Model = &model
|
||||
}
|
||||
sc, err := m.SaveSchedule(ctx, args.ProjectID, args.ScheduleID, save, user.Login, leadActor(user.Login))
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
Reference in New Issue
Block a user