Class: Agentic::TaskPlanner
- Inherits:
-
Object
- Object
- Agentic::TaskPlanner
- Defined in:
- lib/agentic/task_planner.rb
Overview
Handles the task planning process for Agentic using LLM
Instance Attribute Summary collapse
-
#expected_answer ⇒ Hash
readonly
The expected answer format.
-
#goal ⇒ String
readonly
The goal to be accomplished.
-
#llm_config ⇒ LlmConfig
readonly
The configuration for the LLM.
-
#tasks ⇒ Array<Hash>
readonly
The list of tasks to accomplish the goal.
Instance Method Summary collapse
-
#analyze_goal ⇒ void
Analyzes the goal and breaks it down into tasks using LLM.
-
#determine_expected_answer ⇒ void
Determines the expected answer format using LLM.
-
#display_plan ⇒ String
Displays the execution plan.
-
#initialize(goal, llm_config = LlmConfig.new) ⇒ TaskPlanner
constructor
Initializes a new TaskPlanner.
-
#plan ⇒ String
Executes the entire planning process.
Constructor Details
#initialize(goal, llm_config = LlmConfig.new) ⇒ TaskPlanner
Initializes a new TaskPlanner
21 22 23 24 25 26 |
# File 'lib/agentic/task_planner.rb', line 21 def initialize(goal, llm_config = LlmConfig.new) @goal = goal @tasks = [] @expected_answer = {} @llm_config = llm_config end |
Instance Attribute Details
#expected_answer ⇒ Hash (readonly)
Returns The expected answer format.
13 14 15 |
# File 'lib/agentic/task_planner.rb', line 13 def expected_answer @expected_answer end |
#goal ⇒ String (readonly)
Returns The goal to be accomplished.
7 8 9 |
# File 'lib/agentic/task_planner.rb', line 7 def goal @goal end |
#llm_config ⇒ LlmConfig (readonly)
Returns The configuration for the LLM.
16 17 18 |
# File 'lib/agentic/task_planner.rb', line 16 def llm_config @llm_config end |
#tasks ⇒ Array<Hash> (readonly)
Returns The list of tasks to accomplish the goal.
10 11 12 |
# File 'lib/agentic/task_planner.rb', line 10 def tasks @tasks end |
Instance Method Details
#analyze_goal ⇒ void
This method returns an undefined value.
Analyzes the goal and breaks it down into tasks using LLM
30 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 |
# File 'lib/agentic/task_planner.rb', line 30 def analyze_goal = "You are an expert project planner. Your task is to break down complex goals into actionable tasks." = "Goal: #{@goal}\n\nBreak this goal down into a series of tasks. For each task:\n1. Specify the type of agent best suited to complete it.\n2. Include a brief description of the agent\n3. Include a set of instructions that the agent can follow to perform this task." schema = StructuredOutputs::Schema.new("tasks") do |s| s.array :tasks, items: { type: "object", properties: { description: {type: "string"}, agent: { type: "object", properties: { name: {type: "string"}, description: {type: "string"}, instructions: {type: "string"} }, required: %w[name description instructions] } }, required: %w[description agent] } end response = llm_request(, , schema) @tasks = response[:content]["tasks"] end |
#determine_expected_answer ⇒ void
This method returns an undefined value.
Determines the expected answer format using LLM
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/agentic/task_planner.rb', line 59 def determine_expected_answer = "You are an expert in report structuring and formatting. Your task is to determine the best format for a given report goal." = "Goal: #{@goal}\n\nDetermine the optimal format, sections, and length for a report addressing this goal." schema = StructuredOutputs::Schema.new("answer_format") do |s| s.string :format s.array :sections, items: {type: "string"} s.string :length end response = llm_request(, , schema) @expected_answer = response[:content] end |
#display_plan ⇒ String
Displays the execution plan
75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/agentic/task_planner.rb', line 75 def display_plan plan = "Execution Plan:\n\n" @tasks.each_with_index do |task, index| plan += "#{index + 1}. #{task["description"]} (Agent: #{task["agent"].inspect})\n" end plan += "\nExpected Answer:\n" plan += "Format: #{@expected_answer["format"]}\n" plan += "Sections: #{@expected_answer["sections"].join(", ")}\n" plan += "Length: #{@expected_answer["length"]}\n" plan end |
#plan ⇒ String
Executes the entire planning process
89 90 91 92 93 |
# File 'lib/agentic/task_planner.rb', line 89 def plan analyze_goal determine_expected_answer display_plan end |