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
This class follows separation of concerns by:
-
Focusing on core planning logic and data generation
-
Returning structured data (ExecutionPlan) instead of formatted strings
-
Delegating presentation concerns to the ExecutionPlan class
Instance Attribute Summary collapse
-
#expected_answer ⇒ ExpectedAnswerFormat
readonly
The expected answer format.
-
#goal ⇒ String
readonly
The goal to be accomplished.
-
#llm_config ⇒ LlmConfig
readonly
The configuration for the LLM.
-
#tasks ⇒ Array<TaskDefinition>
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.
-
#execution_plan ⇒ ExecutionPlan
Returns an ExecutionPlan object representing the execution plan.
-
#initialize(goal, llm_config = LlmConfig.new) ⇒ TaskPlanner
constructor
Initializes a new TaskPlanner.
-
#plan ⇒ ExecutionPlan
Executes the entire planning process.
Constructor Details
#initialize(goal, llm_config = LlmConfig.new) ⇒ TaskPlanner
Initializes a new TaskPlanner
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/agentic/task_planner.rb', line 31 def initialize(goal, llm_config = LlmConfig.new) @goal = goal @tasks = [] @expected_answer = ExpectedAnswerFormat.new( format: "Undetermined", sections: [], length: "Undetermined" ) @llm_config = llm_config end |
Instance Attribute Details
#expected_answer ⇒ ExpectedAnswerFormat (readonly)
Returns The expected answer format.
23 24 25 |
# File 'lib/agentic/task_planner.rb', line 23 def expected_answer @expected_answer end |
#goal ⇒ String (readonly)
Returns The goal to be accomplished.
17 18 19 |
# File 'lib/agentic/task_planner.rb', line 17 def goal @goal end |
#llm_config ⇒ LlmConfig (readonly)
Returns The configuration for the LLM.
26 27 28 |
# File 'lib/agentic/task_planner.rb', line 26 def llm_config @llm_config end |
#tasks ⇒ Array<TaskDefinition> (readonly)
Returns The list of tasks to accomplish the goal.
20 21 22 |
# File 'lib/agentic/task_planner.rb', line 20 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
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 80 81 82 83 84 |
# File 'lib/agentic/task_planner.rb', line 44 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) if response.successful? @tasks = response.content["tasks"].map do |task_data| TaskDefinition.new( description: task_data["description"], agent: AgentSpecification.new( name: task_data["agent"]["name"], description: task_data["agent"]["description"], instructions: task_data["agent"]["instructions"] ) ) end else Agentic.logger.error("Failed to analyze goal: #{response.error&. || response.refusal}") @tasks = [] end end |
#determine_expected_answer ⇒ void
This method returns an undefined value.
Determines the expected answer format using LLM
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/agentic/task_planner.rb', line 88 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) if response.successful? @expected_answer = ExpectedAnswerFormat.new( format: response.content["format"], sections: response.content["sections"], length: response.content["length"] ) else Agentic.logger.error("Failed to determine expected answer format: #{response.error&. || response.refusal}") @expected_answer = ExpectedAnswerFormat.new( format: "Undetermined", sections: [], length: "Undetermined" ) end end |
#execution_plan ⇒ ExecutionPlan
Returns an ExecutionPlan object representing the execution plan
118 119 120 |
# File 'lib/agentic/task_planner.rb', line 118 def execution_plan ExecutionPlan.new(@tasks, @expected_answer) end |
#plan ⇒ ExecutionPlan
Executes the entire planning process
124 125 126 127 128 |
# File 'lib/agentic/task_planner.rb', line 124 def plan analyze_goal determine_expected_answer execution_plan end |