-
Notifications
You must be signed in to change notification settings - Fork 706
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Recepta Role for CoT in Planner [Ready] (#455)
Co-authored-by: Shilin HE <[email protected]>
- Loading branch information
Showing
12 changed files
with
731 additions
and
20 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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.