Friday Agent¶
- class oscopilot.agents.friday_agent.FridayAgent(planner, retriever, executor, Tool_Manager, config)[source]¶
Bases:
BaseAgentA FridayAgent orchestrates the execution of tasks by integrating planning, retrieving, and executing strategies.
This agent is designed to process tasks, manage errors, and refine strategies as necessary to ensure successful task completion. It supports dynamic task planning, information retrieval, execution strategy application, and employs a mechanism for self-refinement in case of execution failures.
- executing(tool_name, original_task)[source]¶
Executes a given sub-task as part of the task execution process, handling different types of tasks including code execution, API calls, and question-answering.
- Parameters:
tool_name (str) – The name of the tool associated with the sub-task.
original_task (object) – The original high-level task that has been decomposed into sub-tasks.
- Returns:
The state of execution for the sub-task, including the result, any errors encountered, and additional execution-related information.
- Return type:
The method dynamically adapts the execution strategy based on the type of sub-task, utilizing the executor component for code execution, API interaction, or question-answering as appropriate.
- judging(tool_name, state, code, description)[source]¶
Evaluates the execution of a tool based on its execution state and the provided code and description, determining whether the tool’s execution was successful or requires amendment.
- Parameters:
tool_name (str) – The name of the tool being judged.
state (ExecutionState) – The current execution state of the tool, including results and error information.
code (str) – The source code associated with the tool’s execution.
description (str) – A description of the tool’s intended functionality.
- Returns:
An object encapsulating the judgement on the tool’s execution, including whether it needs repair, a critique of the execution, and an optional error type and reasoning for the judgement.
- Return type:
This method assesses the correctness of the executed code and its alignment with the expected outcomes, guiding potential repair or amendment actions.
- planning(task)[source]¶
Decomposes a given high-level task into a list of sub-tasks by retrieving relevant tool names and descriptions, facilitating structured execution planning.
- Parameters:
task (object) – The high-level task to be planned and executed.
- Returns:
A list of sub-tasks generated by decomposing the high-level task, intended for sequential execution to achieve the task’s goal.
- Return type:
list
This method leverages the retriever component to fetch information relevant to the task, which is then used by the planner component to decompose the task into manageable sub-tasks.
- repairing(tool_name, code, description, state, critique, status)[source]¶
Attempts to repair the execution of a tool by amending its code based on the critique received and the current execution state, iterating until the code executes successfully or reaches the maximum iteration limit.
- Parameters:
tool_name (str) – The name of the tool being repaired.
code (str) – The current code of the tool that requires repairs.
description (str) – A description of the tool’s intended functionality.
state (ExecutionState) – The current execution state of the tool, including results and error information.
critique (str) – Feedback on the tool’s last execution attempt, identifying issues to be addressed.
status (str) – Three status types: ‘Amend’, ‘Complete’, and ‘Replan’.
- Returns:
An object encapsulating the result of the repair attempt, including whether the task has been completed successfully, the amended code, critique, execution score, and the execution result.
- Return type:
The method iterates, amending the tool’s code based on feedback until the code executes correctly or the maximum number of iterations is reached. It leverages the executor component for amending the code and re-evaluating its execution.
- replanning(tool_name, reasoning)[source]¶
Initiates the replanning process for a task based on new insights or failures encountered during execution, aiming to adjust the plan to better achieve the task goals.
- Parameters:
tool_name (str) – The name of the tool related to the task that requires replanning.
reasoning (str) – The rationale behind the need for replanning, often based on execution failures or updated task requirements.
- Returns:
An updated list of sub-tasks after the replanning process, intended for sequential execution to complete the task.
- Return type:
list
This method identifies alternative or additional tools and their descriptions based on the provided reasoning, updating the task plan accordingly.
- run(task)[source]¶
Executes the given task by planning, executing, and refining as needed until the task is completed or fails.
- Parameters:
query (object) – The high-level task to be executed.
No explicit return value, but the method controls the flow of task execution and may exit the process in case of irreparable failures.
- self_refining(tool_name, execution_state: ExecutionState)[source]¶
Analyzes and potentially refines the execution of a tool based on its current execution state. This can involve replanning or repairing the execution strategy based on the analysis of execution errors and outcomes.
- Parameters:
tool_name (str) – The name of the tool being executed.
execution_state (ExecutionState) – The current state of the tool’s execution, encapsulating all relevant execution information including errors, results, and codes.
- Returns:
isTaskCompleted (bool): Indicates whether the task associated with the tool has been successfully completed.
isReplan (bool): Indicates whether a replan is required due to execution state analysis.
- Return type:
tuple
The method decides on the next steps by analyzing the type of error (if any) and the execution results, aiming to either complete the task successfully or identify the need for further action, such as replanning.