PlanningModule¶
- class oscopilot.modules.planner.friday_planner.FridayPlanner(prompt)[source]¶
Bases:
BaseModuleA planning module responsible for decomposing complex tasks into manageable subtasks, replanning tasks based on new insights or failures, and managing the execution order of tasks.
The FridayPlanner uses a combination of tool descriptions, environmental state, and language learning models to dynamically create and adjust plans for task execution. It maintains a tool graph to manage task dependencies and execution order, ensuring that tasks are executed in a sequence that respects their interdependencies.
- add_new_tool(new_task_json, current_task)[source]¶
Incorporates a new tool into the existing tool graph based on its dependencies.
This method processes a JSON object representing a new task, including its name, description, type, and dependencies, and adds it to the tool graph. It also updates the tool nodes to reflect this new addition. Finally, it appends the last new task to the list of dependencies for the specified current task.
- Parameters:
new_task_json (dict) – A JSON object containing the new task’s details.
current_task (str) – The name of the current task to which the new task’s dependencies will be added.
- Side Effects:
Updates the tool graph and nodes to include the new tool and its dependencies. Modifies the dependencies of the current task to include the new tool.
- create_tool_graph(decompose_json)[source]¶
Constructs an tool graph based on dependencies specified in the given JSON.
This method takes a JSON object containing task information and dependencies, and constructs an tool graph. Each task is added as a node in the graph, with directed edges representing task dependencies. The method updates the class’s internal structures to reflect this graph, including tool nodes and their relationships, as well as the overall number of tools.
- Parameters:
decompose_json (dict) – A JSON object where each key is an tool name, and the value is a dictionary containing the tool’s name, description, type, and dependencies.
- Side Effects:
Modifies the internal state by updating tool_num, tool_node, and tool_graph to reflect the newly created tool graph.
- decompose_task(task, tool_description_pair)[source]¶
Decomposes a complex task into manageable subtasks and updates the tool graph.
This method takes a high-level task and an tool-description pair, and utilizes the environments’s current state to format and send a decomposition request to the language learning model. It then parses the response to construct and update the tool graph with the decomposed subtasks, followed by a topological sort to determine the execution order.
- Parameters:
task (str) – The complex task to be decomposed.
tool_description_pair (dict) – A dictionary mapping tool names to their descriptions.
- Side Effects:
Updates the tool graph with the decomposed subtasks and reorders tools based on dependencies through topological sorting.
- get_pre_tasks_info(current_task)[source]¶
Retrieves information about the prerequisite tasks for a given current task.
This method collects and formats details about all tasks that are prerequisites for the specified current task. It extracts descriptions and return values for each prerequisite task and compiles this information into a JSON string.
- Parameters:
current_task (str) – The name of the task for which prerequisite information is requested.
- Returns:
A JSON string representing a dictionary, where each key is a prerequisite task’s name, and the value is a dictionary with the task’s description and return value.
- get_tool_list(relevant_tool=None)[source]¶
Retrieves a list of all tools or a subset of relevant tools, including their names and descriptions.
This method fetches tool descriptions from the tool library. If a specific set of relevant tools is provided, it filters the list to include only those tools. The resulting list (or the full list if no relevant tools are specified) is then returned in JSON format.
- Parameters:
relevant_tool (list, optional) – A list of tool names to filter the returned tools by. If None, all tools are included. Defaults to None.
- Returns:
A JSON string representing a dictionary of tool names to their descriptions. The dictionary includes either all tools from the library or only those specified as relevant.
- replan_task(reasoning, current_task, relevant_tool_description_pair)[source]¶
Replans the current task by integrating new tools into the original tool graph.
Given the reasoning for replanning and the current task, this method generates a new tool plan incorporating any relevant tools. It formats a replanning request, sends it to the language learning model, and integrates the response (new tools) into the existing tool graph. The graph is then updated to reflect the new dependencies and re-sorted topologically.
- Parameters:
reasoning (str) – The reasoning or justification for replanning the task.
current_task (str) – The identifier of the current task being replanned.
relevant_tool_description_pair (dict) – A dictionary mapping relevant tool names to their descriptions for replanning.
- Side Effects:
Modifies the tool graph to include new tools and updates the execution order of tools within the graph.
- topological_sort()[source]¶
Generates a topological sort of the tool graph to determine the execution order.
This method applies a topological sorting algorithm to the current tool graph, considering the status of each tool. It aims to identify an order in which tools can be executed based on their dependencies, ensuring that all prerequisites are met before an tool is executed. The sorting algorithm accounts for tools that have not yet been executed to avoid cycles and ensure a valid execution order.
- Side Effects:
Populates sub_task_list with the sorted order of tools to be executed if a topological sort is possible. Otherwise, it indicates a cycle detection.
- update_tool(tool, return_val='', relevant_code=None, status=False, node_type='Code')[source]¶
Updates the specified tool’s node information within the tool graph.
This method allows updating an tool’s return value, relevant code, execution status, and node_type. It is particularly useful for modifying tools’ details after their execution or during the replanning phase.
- Parameters:
tool (str) – The tool identifier whose details are to be updated.
return_val (str, optional) – The return value of the tool. Default is an empty string.
relevant_code (str, optional) – Any relevant code associated with the tool. Default is None.
status (bool, optional) – The execution status of the tool. Default is False.
node_type (str, optional) – The node_type of the tool (e.g., ‘Code’). Default is ‘Code’.
- Side Effects:
Updates the information of the specified tool node within the tool graph.