getappmap / appmap-js

Client libraries for AppMap
48 stars 17 forks source link

@plan command is always followed by suggestion to @generate #1987

Open kgilpin opened 1 week ago

kgilpin commented 1 week ago

This is a natural flow that we recommend.

github-actions[bot] commented 1 week ago

Title

Ensure seamless transition from @plan to @generate command

Problem

The current issue is that when a user issues the @plan command, the system does not naturally suggest or facilitate a transition to the @generate command, which is the recommended workflow.

Analysis

The @plan command is used to generate a detailed plan for a given problem statement. Following this, users are expected to use the @generate command to generate code based on the plan. However, the smooth transition between these two commands is not currently implemented, and users must manually initiate the @generate command after receiving the plan. Ensuring a seamless transition can improve user experience by automating this workflow.

The main components involved in handling commands are PlanAgent and GenerateAgent, and the AgentSelectionService. The PlanAgent should suggest the @generate command upon completion, or the AgentSelectionService could facilitate this transition based on the user's flow.

Proposed Changes

  1. packages/navie/src/agents/plan-agent.ts:

    • After the PlanAgent completes the processing of the @plan command, add logic to suggest or automatically transition to the @generate command. This can be achieved by appending a prompt or invoking the appropriate agent.
  2. packages/navie/src/services/agent-selection-service.ts:

    • Modify the selectAgent method to facilitate the transition from @plan to @generate. Ensure that when an @plan command is processed, there is a follow-up suggestion or auto-invocation of the @generate command.

Here are the detailed steps for each proposed change:

  1. Update PlanAgent to suggest or initiate the @generate command:
// After the context service search is completed
await this.contextService.searchContext(options, tokensAvailable);

// Add the following logic to suggest or initiate `@generate`
this.history.addEvent(
  new PromptInteractionEvent(
    'system',
    'Suggestion',
    "Now that the plan is ready, you can proceed with the `@generate` command to implement the changes suggested in the plan."
  )
);
  1. Modify AgentSelectionService to handle transition logic:
selectAgent(
  question: string,
  classification: ContextV2.ContextLabel[],
  userOptions: UserOptions
): AgentModeResult {
  let modifiedQuestion = question;

  const contextService = new ContextService(
    this.history,
    this.vectorTermsService,
    this.lookupContextService,
    this.applyContextService
  );

  const planAgent = () => new PlanAgent(this.history, contextService);
  const generateAgent = () => new GenerateAgent(this.history, contextService, this.fileChangeExtractorService);

  const buildAgent: { [key in AgentMode]: () => Agent } = {
    [AgentMode.Plan]: planAgent,
    [AgentMode.Generate]: generateAgent,
    // other agents...
  };

  // Add logic to handle transition after `@plan` command
  const agentResult = buildAgent[detectedMode]();
  if (detectedMode === AgentMode.Plan) {
    this.history.addEvent(
      new PromptInteractionEvent(
        'system',
        'Transition',
        "Plan completed. Automatically transitioning to `@generate`."
      )
    );
    return buildAgent[AgentMode.Generate]();
  }

  return agentResult;
}