Class: XAeonAgents::Agents::PlannerAgent

Inherits:
ComposableAgents::Agent
  • Object
show all
Includes:
XAeonAgents::AgentDefaults
Defined in:
lib/x_aeon_agents/agents/planner_agent.rb

Overview

Agent responsible for producing an implementation plan acceptable to the user.

Instance Method Summary collapse

Methods included from XAeonAgents::AgentDefaults

#new_agent, prepended, singleton_session_id

Instance Method Details

#input_artifacts_contractsHash{Symbol => Object}

Define input artifacts contracts

Returns:

  • (Hash{Symbol => Object})

    Set of input artifacts description, per artifact name



10
11
12
# File 'lib/x_aeon_agents/agents/planner_agent.rb', line 10

def input_artifacts_contracts
  { requirements: 'The initial requirements for which you need to devise an implementation plan' }
end

#output_artifacts_contractsHash{Symbol => Object}

Define output artifacts contracts

Returns:

  • (Hash{Symbol => Object})

    Set of output artifacts description, per artifact name



17
18
19
20
21
22
23
24
25
# File 'lib/x_aeon_agents/agents/planner_agent.rb', line 17

def output_artifacts_contracts
  {
    plan: {
      description: 'The full and detailed implementation plan in Markdown format, ' \
        "that should implement the requirements given by the artifact named `#{plan_generator_agent.artifact_ref(:requirements)}`",
      type: :markdown
    }
  }
end

#plan_generator_agentAgent

Get a Plan Generator agent.

Returns:

  • (Agent)

    The Plan Generator agent



84
85
86
# File 'lib/x_aeon_agents/agents/planner_agent.rb', line 84

def plan_generator_agent
  @plan_generator_agent ||= new_agent(PlanGeneratorAgent, **Config.agent_options['free_complex_planning'])
end

#run(requirements:) ⇒ Hash{Symbol => Object}

Execute the agent to generate some output artifacts based on some input artifacts.

Parameters:

  • requirements (String)

    The initial requirements.

Returns:

  • (Hash{Symbol => Object})

    Output artifacts content



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/x_aeon_agents/agents/planner_agent.rb', line 31

def run(requirements:)
  user_instructions = {
    ordered_list: [
      "Read the initial requirements from the artifact named `#{plan_generator_agent.artifact_ref(:requirements)}`",
      'Analyze the project files',
      "Create an artifact named `#{plan_generator_agent.artifact_ref(:plan)}` with a complete and detailed " \
        'step-by-step implementation plan in Markdown format'
    ]
  }
  loop do
    step_agent(plan_generator_agent, user_instructions:)
    @artifacts[:plan].strip!
    content, user_prompt = Helpers.review_content(
      reviews_dir: "#{@session_dir}/reviews",
      name: 'plan.md',
      description: 'Implementation plan',
      editable: true,
      promptable: true,
      content: @artifacts[:plan]
    )
    diffs =
      if @artifacts[:plan] == content
        nil
      else
        Diffy::Diff.new("#{@artifacts[:plan].strip}\n", "#{content.strip}\n", context: 3, include_diff_info: true).to_s
      end
    @artifacts[:plan] = content
    break if user_prompt.empty?

    user_instructions = <<~EO_INSTRUCTIONS
      #{user_prompt}

      Re-create the artifact named `#{plan_generator_agent.artifact_ref(:plan)}` with a revised implementation plan, taking the above user guidance into account.
    EO_INSTRUCTIONS
    user_instructions << <<~EO_INSTRUCTIONS if diffs

      The user performed the following modifications on your implementation plan.
      You have to take them into account while revising the plan.

      ```
      #{
        # Remove the 2 first lines (headers of temporary file names).
        diffs.to_s.split("\n")[2..].join("\n").strip
      }
      ```
    EO_INSTRUCTIONS
  end
  { plan: @artifacts[:plan] }
end