Skip to content

Commit f30c6db

Browse files
Add --agent flag to resume command for task reassignment
Allow resuming a task with a different agent than originally assigned. The --agent flag accepts an agent name or ID, enabling users to: • Switch agents mid-conversation by resuming a task with a different agent • Leverage agent names through getAgentID helper function • Maintain task context while changing execution strategy This enables flexible agent switching for resumed tasks while maintaining backward compatibility with existing resume workflows. Co-authored-by: construct-agent <noreply@construct.sh>
1 parent 8d09f27 commit f30c6db

1 file changed

Lines changed: 24 additions & 11 deletions

File tree

frontend/cli/cmd/resume.go

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ import (
1919
type resumeOptions struct {
2020
last bool
2121
all bool
22-
limit int
22+
limit int
23+
agent string
2324
}
2425

2526
func NewResumeCmd() *cobra.Command {
@@ -54,33 +55,34 @@ choose from. Partial ID matching is supported.`,
5455
cmd.Flags().BoolVar(&options.last, "last", false, "Immediately resume the most recent session without showing the interactive picker")
5556
cmd.Flags().BoolVar(&options.all, "all", false, "Show all tasks in the picker, including non-interactive ones")
5657
cmd.Flags().IntVar(&options.limit, "limit", 10, "Maximum number of tasks to show in the picker")
58+
cmd.Flags().StringVar(&options.agent, "agent", "", "Resume the task with a specific agent")
5759

5860
return cmd
5961
}
6062

6163
func handleResumeCommand(ctx context.Context, apiClient *api.Client, options *resumeOptions, args []string) error {
6264
if len(args) > 0 {
6365
taskID := args[0]
64-
return resumeTaskByID(ctx, apiClient, taskID)
66+
return resumeTaskByID(ctx, apiClient, taskID, options.agent)
6567
}
6668

6769
if options.last {
68-
return resumeMostRecentTask(ctx, apiClient)
70+
return resumeMostRecentTask(ctx, apiClient, options.agent)
6971
}
7072

7173
return showTaskPicker(ctx, apiClient, options)
7274
}
7375

74-
func resumeTaskByID(ctx context.Context, apiClient *api.Client, taskID string) error {
76+
func resumeTaskByID(ctx context.Context, apiClient *api.Client, taskID string, agent string) error {
7577
task, err := resolveTaskID(ctx, apiClient, taskID)
7678
if err != nil {
7779
return fmt.Errorf("failed to resolve task ID %s: %w", taskID, err)
7880
}
7981

80-
return resumeTask(ctx, apiClient, task)
82+
return resumeTask(ctx, apiClient, task, agent)
8183
}
8284

83-
func resumeMostRecentTask(ctx context.Context, apiClient *api.Client) error {
85+
func resumeMostRecentTask(ctx context.Context, apiClient *api.Client, agent string) error {
8486
resp, err := apiClient.Task().ListTasks(ctx, &connect.Request[v1.ListTasksRequest]{
8587
Msg: &v1.ListTasksRequest{
8688
Filter: &v1.ListTasksRequest_Filter{},
@@ -98,15 +100,26 @@ func resumeMostRecentTask(ctx context.Context, apiClient *api.Client) error {
98100
}
99101

100102
mostRecentTask := resp.Msg.Tasks[0]
101-
return resumeTaskByID(ctx, apiClient, mostRecentTask.Metadata.Id)
103+
return resumeTaskByID(ctx, apiClient, mostRecentTask.Metadata.Id, agent)
102104
}
103105

104-
func resumeTask(ctx context.Context, apiClient *api.Client, task *v1.Task) error {
106+
func resumeTask(ctx context.Context, apiClient *api.Client, task *v1.Task, agent string) error {
107+
var agentID string
108+
if agent != "" {
109+
var err error
110+
agentID, err = getAgentID(ctx, apiClient, agent)
111+
if err != nil {
112+
return fmt.Errorf("failed to get agent %s: %w", agent, err)
113+
}
114+
} else {
115+
agentID = *task.Spec.AgentId
116+
}
117+
105118
agentResp, err := apiClient.Agent().GetAgent(ctx, &connect.Request[v1.GetAgentRequest]{
106-
Msg: &v1.GetAgentRequest{Id: PtrToString(task.Spec.AgentId)},
119+
Msg: &v1.GetAgentRequest{Id: agentID},
107120
})
108121
if err != nil {
109-
return fmt.Errorf("failed to get agent: %w", err)
122+
return fmt.Errorf("failed to get agent %s: %w", agentID, err)
110123
}
111124

112125
return startInteractiveSession(ctx, apiClient, task, agentResp.Msg.Agent)
@@ -169,7 +182,7 @@ func showTaskPicker(ctx context.Context, apiClient *api.Client, options *resumeO
169182
return fmt.Errorf("no task selected")
170183
}
171184

172-
return resumeTask(ctx, apiClient, selectedTask)
185+
return resumeTask(ctx, apiClient, selectedTask, options.agent)
173186
}
174187

175188
func resolveTaskID(ctx context.Context, apiClient *api.Client, taskID string) (*v1.Task, error) {

0 commit comments

Comments
 (0)