-
Notifications
You must be signed in to change notification settings - Fork 766
Add Recepta Role for CoT in Planner [Ready] #455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a0bd759
optimize reasoning process for planner
liqul 5e6971b
add news
liqul 34bdc93
add recepta and example
liqul c556729
refine prompts
liqul 41f7ce6
remove inst
liqul f22e72e
Merge branch 'main' into liqun/opt_planner_reasoning
liqul 20b23d7
add stop reason
liqul 5417e3d
Merge branch 'liqun/opt_planner_reasoning' of https://github.com/micr…
liqul e7514a3
update blog
liqul 641011c
add news
liqul c0951a6
revise sentence
liqul 437dcc0
Merge branch 'main' into liqun/opt_planner_reasoning
ShilinHe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
project/examples/planner_examples/example-planner-recepta.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| enabled: True | ||
| rounds: | ||
| - user_query: echo 'Generate Employee Report' | ||
| state: created | ||
| post_list: | ||
| - message: |- | ||
| please follow the instructions below to complete the task: | ||
|
|
||
| # Task Instructions | ||
| ## Step 1: Extract Employee Data | ||
| Extract the following information from the employee summary: | ||
| - `Employee ID` | ||
| - `Department` | ||
| - `Project Code` | ||
| - `Role` | ||
| - `Manager` | ||
| - `Location` | ||
|
|
||
| ### Employee Summary | ||
| On April 10, 2025, a review was conducted for an employee with ID `E12345`. The employee is part of the `Development` department and is currently assigned to project code `"X987"`. The role held is `"Software Engineer"` under the supervision of manager `"J. Doe."` The primary work location is `"Remote."` | ||
|
|
||
| ## Step 2: Validate the Role | ||
| - Confirm if the role is recognized among the following: Software Engineer, Data Analyst, Project Manager, DevOps Specialist, QA Tester. | ||
| - Check if the role is one of the recognized roles. | ||
|
|
||
| ## Step 3: Construct SQL Query | ||
| Prepare and print the SQL query using the extracted details: | ||
| ```sql | ||
| SELECT EmployeeID, Department, ProjectCode, Role, Manager, Location | ||
| FROM EmployeeRecords | ||
| WHERE EmployeeID = '{EmployeeID}' | ||
| AND Department = '{Department}' | ||
| AND ProjectCode = '{ProjectCode}' | ||
| AND Role = '{Role}' | ||
| AND Manager = '{Manager}' | ||
| AND Location = '{Location}' | ||
| ORDER BY EmployeeID; | ||
| ``` | ||
| send_from: User | ||
| send_to: Planner | ||
| attachment_list: | ||
| - message: |- | ||
| Thought: I can read and comprehend the employee summary to extract the required information. | ||
| Result: the `Employee ID` is `E12345`, the `Department` is `Development`, the `Project Code` is `X987`, the `Role` is `Software Engineer`, the `Manager` is `J. Doe`, and the `Location` is `Remote`. | ||
| send_from: Planner | ||
| send_to: Recepta | ||
| attachment_list: | ||
| - type: plan_reasoning | ||
| content: |- | ||
| The first step is to extract the following information from the employee summary: `Employee ID`, `Department`, `Project Code`, `Role`, `Manager`, `Location`. | ||
| - type: init_plan | ||
| content: |- | ||
| 1. extract the following information from the employee summary: `Employee ID`, `Department`, `Project Code`, `Role`, `Manager`, `Location` | ||
| 2. validate the role <interactively depends on 1> | ||
| 3. construct and print the SQL query using the extracted details <interactively depends on 1> | ||
| 4. check the execution result and report the result to the user <interactively depends on 1 and 3> | ||
| - type: plan | ||
| content: |- | ||
| 1. extract information from the employee summary | ||
| 2. validate the role | ||
| 3. construct SQL query using the extracted details | ||
| 4. report the result to the user | ||
| - type: current_plan_step | ||
| content: 1. extract information from the employee summary | ||
| - type: stop | ||
| content: InProcess | ||
| - message: Got it! Please go ahead. | ||
| send_from: Recepta | ||
| send_to: Planner | ||
| attachment_list: | ||
| - message: |- | ||
| Thought: I can verify if the role is one of the recognized roles with my pattern matching capability. | ||
| Thought: The recognized roles are `Software Engineer, Data Analyst, Project Manager, DevOps Specialist, QA Tester`. | ||
| Result: The role is `Software Engineer`, which is recognized. | ||
| send_from: Planner | ||
| send_to: Recepta | ||
| attachment_list: | ||
| - type: plan_reasoning | ||
| content: |- | ||
| I have extracted the information from the employee summary. The next step is to verify if the role is one of the recognized roles. | ||
| - type: init_plan | ||
| content: |- | ||
| 1. extract the following information from the employee summary: `Employee ID`, `Department`, `Project Code`, `Role`, `Manager`, `Location` | ||
| 2. validate the role <interactively depends on 1> | ||
| 3. construct and print the SQL query using the extracted details <interactively depends on 1> | ||
| 4. check the execution result and report the result to the user <interactively depends on 1 and 3> | ||
| - type: plan | ||
| content: |- | ||
| 1. extract information from the employee summary | ||
| 2. validate the role | ||
| 3. construct SQL query using the extracted details | ||
| 4. report the result to the user | ||
| - type: current_plan_step | ||
| content: 2. validate the role | ||
| - type: stop | ||
| content: InProcess | ||
| - message: Got it! Please go ahead. | ||
| send_from: Recepta | ||
| send_to: Planner | ||
| attachment_list: | ||
| - message: |- | ||
| The role is `Software Engineer`, which is recognized. | ||
|
|
||
| Here is the SQL query using the extracted details: | ||
| ```sql | ||
| SELECT EmployeeID, Department, ProjectCode, Role, Manager, Location | ||
| FROM EmployeeRecords | ||
| WHERE EmployeeID = 'E12345' | ||
| AND Department = 'Development' | ||
| AND ProjectCode = 'X987' | ||
| AND Role = 'Software Engineer' | ||
| AND Manager = 'J. Doe' | ||
| AND Location = 'Remote' | ||
| ORDER BY EmployeeID; | ||
| ``` | ||
| send_from: Planner | ||
| send_to: User | ||
| attachment_list: | ||
| - type: plan_reasoning | ||
| content: |- | ||
| I can prepare and print the SQL query using the extracted details to the User. | ||
| - type: init_plan | ||
| content: |- | ||
| 1. extract the following information from the employee summary: `Employee ID`, `Department`, `Project Code`, `Role`, `Manager`, `Location` | ||
| 2. validate the role <interactively depends on 1> | ||
| 3. construct and print the SQL query using the extracted details <interactively depends on 1> | ||
| 4. check the execution result and report the result to the user <interactively depends on 1 and 3> | ||
| - type: plan | ||
| content: |- | ||
| 1. extract information from the employee summary | ||
| 2. validate the role | ||
| 3. construct SQL query using the extracted details | ||
| 4. report the result to the user | ||
| - type: current_plan_step | ||
| content: 3. construct and print the SQL query using the extracted details and report the result to the user | ||
| - type: stop | ||
| content: Completed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| from injector import inject | ||
|
|
||
| from taskweaver.logging import TelemetryLogger | ||
| from taskweaver.memory import Memory, Post | ||
| from taskweaver.module.event_emitter import SessionEventEmitter | ||
| from taskweaver.module.tracing import Tracing | ||
| from taskweaver.role import Role | ||
| from taskweaver.role.role import RoleConfig, RoleEntry | ||
|
|
||
|
|
||
| class ReceptaConfig(RoleConfig): | ||
| def _configure(self): | ||
| self.decorator = self._get_str("decorator", "") | ||
|
|
||
|
|
||
| class Recepta(Role): | ||
| @inject | ||
| def __init__( | ||
| self, | ||
| config: ReceptaConfig, | ||
| logger: TelemetryLogger, | ||
| tracing: Tracing, | ||
| event_emitter: SessionEventEmitter, | ||
| role_entry: RoleEntry, | ||
| ): | ||
| super().__init__(config, logger, tracing, event_emitter, role_entry) | ||
|
|
||
| def reply(self, memory: Memory, **kwargs: ...) -> Post: | ||
| rounds = memory.get_role_rounds( | ||
| role=self.alias, | ||
| include_failure_rounds=False, | ||
| ) | ||
|
|
||
| # obtain the query from the last round | ||
| last_post = rounds[-1].post_list[-1] | ||
|
|
||
| post_proxy = self.event_emitter.create_post_proxy(self.alias) | ||
|
|
||
| post_proxy.update_send_to(last_post.send_from) | ||
| post_proxy.update_message( | ||
| "Got it. Now, please go ahead!", | ||
| ) | ||
|
|
||
| return post_proxy.end() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| alias: Recepta | ||
| module: taskweaver.ext_role.recepta.recepta.Recepta | ||
| intro : |- | ||
| - Recepta is responsible for helping the Planner to record the reasoning process. | ||
| - When the Planner is reasoning and do not involve any Workers, it must send a message to Recepta to record the reasoning process. | ||
| - When Planner needs to reason in the middle of the task and is not ready to talk to the User, it can send a message to `Recepta` to record the reasoning process and result. The message should be formatted as "Thought 1: reasoning...\nThought 2: reasoning...\n...Result: result...". | ||
| - The reasoning result should be insights or conclusion derived for the task step, NOT a plan or a set of instructions for further action. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.