Skip to content

Commit 7535fde

Browse files
authored
Merge pull request #202 from hoomano/kroussel/update_doc_workflow_creation
Kroussel/update doc workflow creation
2 parents 77fad00 + e2793c1 commit 7535fde

File tree

4 files changed

+64
-85
lines changed

4 files changed

+64
-85
lines changed

backend/app/routes/task.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,14 @@
214214
}
215215
}
216216
}
217+
},
218+
"review_chat_enabled":{
219+
"type": "boolean",
220+
"default": false
221+
},
222+
"user_validation_required":{
223+
"type": "boolean",
224+
"default": true
217225
}
218226
}
219227
}

backend/app/routes/task.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def put(self):
153153
definition_for_system=step["definition_for_system"],
154154
task_fk=task.task_pk,
155155
rank=step_index + 1,
156-
review_chat_enabled=step.get("review_chat_enabled", False)
156+
review_chat_enabled=step.get("review_chat_enabled", False),
157+
user_validation_required=step.get("user_validation_required", True),
157158
)
158159
db.session.add(db_step)
159160
db.session.flush()

docs/guides/workflows/new_workflow.md

Lines changed: 48 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,64 @@
11
# Create a new workflow
22

33
## Technical definition
4-
A workflow is a sequence of steps that the agent must execute one by one. Each step execution then requires a user validation before the agent can proceed to the next step.
5-
Compared to the tasks, the workflows are more complex and constrainted, allowing the user to keep more control over the agent's actions.
4+
A workflow is a sequence of steps that the agent must execute one by one. A step is code: anything can be done in this code including complex actions as API calls.
5+
6+
The result of each step execution is always available to the user that can consult it. On the steps requiring user validation, user can edit the step result and sometimes open a chat to give an instruction to relaunch the step.
7+
Compared to the instruct tasks, the workflows are more complex and constrainted, allowing the user to keep more control over the agent's actions.
68

79
## How to create a new workflow?
810

9-
STEP 1: Create the steps' code
10-
In `backend>app>models>workflows` create a new folder named by your workflow. In this folder, create one file per step in your workflow.
11-
In each of those files, implement the crresponding step code.
11+
### STEP 1: Create the steps' code
12+
In `mojodex_core>workflows` create a new folder named by your workflow. In this folder, create one file per step in your workflow.
13+
In each of those files, implement the corresponding step code.
1214
A workflow step is a class that implements the `WorkflowStep` class.
1315

14-
An implementation of `WorkflowStep` looks like this:
16+
An implementation of `WorkflowStep` overrides the method `_execute()`. It looks like this:
17+
1518
```python
16-
from models.workflows.step import WorkflowStep
19+
from mojodex_core.entities.workflow_step import WorkflowStep
1720

1821
class MyWorkflowStep(WorkflowStep):
1922

20-
@property
21-
def definition_for_system(self):
22-
return "This is a definition of the step" # Definition of the step as used in prompts
23-
24-
@property
25-
def input_keys(self):
26-
return ['input_key1', 'input_key2'] # List of keys that must be present in the input parameter
27-
28-
@property
29-
def output_keys(self):
30-
return ['output_key1', 'output_key2'] # List of keys that will be present in the output parameter
31-
3223

33-
def _execute(self, parameter: dict, learned_instructions: dict, initial_parameter: dict, history: List[dict], workflow_conversation: str):
24+
def _execute(self, parameter: dict, learned_instructions: dict, initial_parameter: dict, past_validated_steps_results: List[dict], user_id: str, user_task_execution_pk: int, task_name_for_system: str, session_id:str):
3425
try:
35-
# parameter contains every input keys
36-
return [{'output_key1': <output>, 'output_key2': <output>}] # output contains every output key
26+
return [{'output_key1': <output>, 'output_key2': <output>}]
3727
except Exception as e:
3828
raise Exception(f"execute :: {e}")
3929
```
4030

41-
STEP 2: Add your steps to the steps library
42-
In `backend>app>models>workflows>steps_library.py`, add your steps to the `STEPS` dictionary. The key must be the name of the step and the value must be the class of the step. This is used to dynamically load the steps from their name in the database.
31+
The result of the step execution must be a list of dictionaries. The next step of the workflow will be executed as many time as there are dictionaries in the list, each time with the corresponding dictionary as parameter.
4332

44-
STEP 3: Create the workflow
45-
To create a new workflow, you can use the dedicated route PUT `/workflow`
33+
### STEP 2: Add your steps to the steps library
34+
In `mojodex_core>workflows>steps_library.py`, add your steps to the `STEPS` dictionary. The key must be the name of the step as later defined in DB and the value must be the class of the step. This is used to dynamically load the steps from their name in the database.
35+
36+
### STEP 3: Create the workflow
37+
To create a new workflow, you can use the dedicated route PUT `/task`.
4638

4739
Replace `<BACKOFFICE_SECRET>` with your actual token and name, steps, icon and description with the actual workflow name, steps, icon and description.
4840
> Careful: steps names must match the ones in the steps library.
49-
> Careful: steps must be in the right order.
5041
5142
Then, run the following command in your terminal:
5243

5344
```shell
54-
curl --location --request PUT 'http://localhost:5001/workflow' \
45+
curl --location --request PUT 'http://localhost:5001/task' \
5546
--header 'Authorization: <BACKOFFICE_SECRET>' \
5647
--header 'Content-Type: application/json' \
5748
--data-raw '{"datetime": "2024-02-14T17:49:26.545180",
49+
"task_type": "workflow",
50+
"predefined_actions": [],
5851
"name_for_system": "<WORKFLOW_NAME_FOR_SYSTEM>",
5952
"icon": "<EMOJI>",
6053
"definition_for_system": "<WORKFLOW_DEFINITION_FOR_SYSTEM>",
61-
"platforms": ["webapp", "mobile"], # List of platforms where the workflow is available
54+
"output_type": "document",
55+
"platforms": ["webapp"], # List of platforms where the workflow is available. Workflows are not yet implemented on mobile app.
6256
"steps": [{
6357
"name_for_system": "<STEP_NAME_FOR_SYSTEM>",
58+
"definition_for_system": "<STEP_DEFINITION_FOR_SYSTEM>",
59+
"rank": 1,
60+
"review_chat_enabled": false, # Whether the chat is enabled at the end of the step or not.
61+
"user_validation_required": true, # Whether the user validation is required or not at the end of this step
6462
"step_displayed_data":[
6563
{
6664
"language_code": "<2-LETTERS LANGUAGE-CODE>",
@@ -71,80 +69,46 @@ curl --location --request PUT 'http://localhost:5001/workflow' \
7169
]},
7270
...
7371
],
74-
"workflow_displayed_data": [
72+
"task_displayed_data": [
7573
{
7674
"language_code":"<2-LETTERS LANGUAGE-CODE>",
7775
"name_for_user": <WORKFLOW_NAME_FOR_USER>",
7876
"definition_for_user": <WORKFLOW_DEFINITION_FOR_USER>",
79-
"json_inputs_spec": [
80-
{"input_name_for_system": "<INPUT_NAME_FOR_SYSTEM>", "type": "text_area", "input_name_for_user":"<INPUT_NAME_FOR_USER>"},
77+
"json_input": [
78+
{"input_name": "<INPUT_NAME>",
79+
"description_for_user": "<DESCRIPTION_FOR_USER>",
80+
"description_for_system": "<DESCRIPTION_FOR_SYSTEM>",
81+
"type": "text_area"},
8182
...
8283
]
8384
},
8485
...
85-
]
86+
],
87+
"result_chat_enabled": false # Whether the chat is enabled at the end of the workflow on the produced text or not.
8688
}'
8789
```
8890

89-
STEP 4: Define workflow checkpoints
90-
By default, every step is defined as a checkpoint. This means that at the end of each step_execution_run, if the user does not validate the result, the user will give an instruction and this same step_execution_run will be executed again.
91-
92-
Example on Qualify Lead workflow:
93-
Step 1 is "Write the query you will use with SERP API to search Google"
94-
95-
- Step 1 - Run 1 - Execution 1:
96-
parameter: {"company": "Hoomano"}
97-
learned instructions: None
98-
step result: "query: 'Hoomano industry'"
99-
<USER DOES NOT VALIDATE>
100-
user instruction: "This query is not specific enough, please add more keywords"
101-
102-
- Step 1 - Run 1 - Execution 2:
103-
parameter: {"company": "Hoomano"}
104-
learned instructions: "Make specific queries"
105-
step result: "query: 'Hoomano company industry trends AI"
106-
<USER VALIDATES>
107-
108-
On the contrary, if a step is not defined as a checkpoint, the user will give an instruction but the last checkpoint step last run will be executed again.
109-
Let's keep Qualify Lead workflow example running:
110-
Step 2 is "Check the SERP API results and select the 3 most relevant one"
111-
112-
- Step 2 - Run 1 - Execution 1:
113-
parameter: {"query": "Hoomano company industry trends AI"}
114-
learned instructions: None
115-
step result: "result 1, result 2, ..."
116-
<USER DOES NOT VALIDATE>
117-
user instruction: "This is not relevant, please try again, look for any blog post the company wrote"
118-
119-
- Step 1 - Run 1 - Execution 3:
120-
parameter: {"company": "Hoomano"}
121-
learned instructions: "Make specific queries, look for any blog post the company wrote"
122-
step result: "query: 'Hoomano company AI blog posts"
123-
<USER VALIDATES>
124-
125-
- Step 2 - Run 2 - Execution 1:
126-
parameter: {"query": "Hoomano company AI blog posts"}
127-
learned instructions: "Make specific queries, look for any blog post the company wrote"
128-
step result: "result 1, result 2, ..."
129-
<USER VALIDATES>
130-
131-
STEP 5: Associate workflow to a user through a product.
132-
Replace `<BACKOFFICE_SECRET>` with your actual token and `<user_id>` and `<workflow_pk>` with the actual user id and workflow primary key.
91+
> **Note regarding "result_chat_enabled" parameter**:
92+
Be careful that once on result page:
93+
> - Assistant will no longer be able to re-launch past steps code - therefore relaunch api requests or other…
94+
> - Text has been generated by a whole chain of steps. It could be too long for context-windows on a basic LLM chat call.
95+
96+
> As a consequence, depending on the workflow, it may be relevant to disable the chat on result to avoid user confusion (preventing them to ask to re-launch a query for example)
97+
98+
99+
### STEP 4: Associate workflow to a user through a product.
100+
Replace `<BACKOFFICE_SECRET>` with your actual token and `<user_id>` and `<task_pk>` with the actual user id and workflow primary key.
133101
Then, run the following command in your terminal:
134102

135103

136104
Default user `demo@example.com` is associated with default product `demo` with pk 1. Let's add the task to this product.
137105
```
138-
curl --location --request PUT 'http://localhost:5001/product_workflow_association' \
106+
curl --location --request PUT 'http://localhost:5001/product_task_association' \
139107
--header 'Authorization: backoffice_secret' \
140108
--header 'Content-Type: application/json' \
141109
--data-raw '{
142110
"datetime": "'"$(date -u +"%Y-%m-%dT%H:%M:%S.%3NZ")"'",
143111
"product_pk": 1,
144-
"workflow_pk": <workflow_pk retrieved from previous command>
112+
"task_pk": <task_pk retrieved from previous command>
145113
}'
146-
```
147-
148-
149-
150-
114+
```

docs/openAPI/backend_api.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3618,6 +3618,12 @@ paths:
36183618
type: string
36193619
definition_for_system:
36203620
type: string
3621+
review_chat_enabled:
3622+
type: boolean
3623+
default: false
3624+
user_validation_required:
3625+
type: boolean
3626+
default: true
36213627
step_displayed_data:
36223628
type: array
36233629
items:

0 commit comments

Comments
 (0)