跳至主要内容

体验

动机

智能体开发者可以添加示例来指导规划和代码生成。 此外,我们还提供了另一种将用户经验保存到长期记忆中的方式。 实际应用中,如果用户要求TaskWeaver解决一个复杂问题, TaskWeaver可能一开始会出错。但经过多次尝试或用户提供更多指示后, 智能体最终能解决问题。然而,下次用户提出类似问题 甚至完全相同的问题时,智能体仍难以第一时间给出正确方案, 因为它没有记住这些经验。因此,我们提出了一种称为"经验记忆"的机制。 其核心思想是:用户可以通过命令让TaskWeaver保存聊天记录, 从中提取经验提示并存入经验池。 之后当智能体遇到类似请求时,就会从记忆中检索这些经验 来指导其规划和代码生成。 每条经验提示都记录了"遇到此类请求时应做或不应做"的事项。 后续收到相似请求时,我们会将检索到的经验添加到提示中。

Save User Experience

快速开始

在本快速入门教程中,我们将向您展示如何启用经验功能并将聊天记录保存到经验池中。

  1. 要启用经验功能,您需要在配置文件中将planner.use_experiencecode_generator.use_experience参数设置为true。 这样,Planner和CodeInterpreter都可以利用经验来指导规划和代码生成。

  2. 启动与TaskWeaver的新对话。您会发现在项目目录中创建了experience目录。 请注意,由于我们尚未保存任何聊天记录,目前该目录为空。

  3. 如果您认为当前聊天记录值得保存,可以在控制台聊天界面输入命令/save进行保存。 您将在experience目录下发现一个名为raw_exp_{session_id}.yaml的新文件被创建。

  4. 重启TaskWeaver并开始新对话。在初始化阶段,TaskWeaver会读取raw_exp_{session_id}.yaml文件 并生成一个名为exp_{session_id}.yaml的新摘要文件。 这个过程可能需要一些时间,因为TaskWeaver需要调用LLM模型从聊天记录中提取经验技巧。

  5. 下次当用户向TaskWeaver发送类似查询时,系统将检索相关经验并将其加载到系统提示中(供Planner和CodeInterpreter使用)。通过这种方式,这些经验可用于指导未来的对话。

info

项目目录中会创建experience文件夹。 您可以通过在配置文件中设置session.experience_dir参数 来更改experience文件夹的位置。

示例演练

  1. 启动与TaskWeaver的新对话。向TaskWeaver发送请求"计算./project/sample_data/data_demo.csv的平均值"。
  2. 你会发现TaskWeaver犯了一个错误,计算了非数值列的平均值。 经过多次尝试,TaskWeaver修复了这个问题。
=========================================================
_____ _ _ __
|_ _|_ _ ___| | _ | | / /__ ____ __ _____ _____
| |/ _` / __| |/ /| | /| / / _ \/ __ `/ | / / _ \/ ___/
| | (_| \__ \ < | |/ |/ / __/ /_/ /| |/ / __/ /
|_|\__,_|___/_|\_\|__/|__/\___/\__,_/ |___/\___/_/
=========================================================
TaskWeaver ▶ I am TaskWeaver, an AI assistant. To get started, could you please enter your request?
Human ▶ calculate the mean value of d:/demo_data.csv
╭───< Planner >
├─► [init_plan]
│ 1. load the data file
│ 2. calculate the mean value of the loaded data <sequentially depends on 1>
│ 3. report the result to the user <interactively depends on 2>
├─► [plan]
│ 1. instruct CodeInterpreter to load the data file and calculate the mean value of the loaded data
│ 2. report the result to the user
├─► [current_plan_step] 1. instruct CodeInterpreter to load the data file and calculate the mean value of the loaded data
├──● Please load the data file d:/demo_data.csv and calculate the mean value of the loaded data
╰──● sending message to CodeInterpreter
╭───< CodeInterpreter >
├─► [thought] ProgramApe will generate a code snippet to load the data file d:/demo_data.csv and calculate the mean value of the loaded data using pandas.
├─► [python]
│ import pandas as pd

│ data_file_path = "d:/demo_data.csv"
│ data_df = pd.read_csv(data_file_path)
│ mean_value = data_df.mean()
│ mean_value
├─► [verification] NONE
├─► [code_error] No code verification is performed.
├─► [execution_status] FAILURE
├─► [execution_result]
│ The execution of the generated python code above has failed

│ During execution, the following messages were logged:
│ Traceback (most recent call last):

│ Cell In[1], line 5
│ mean_value = data_df.mean()

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\frame.py:11335 in mean
│ result = super().mean(axis, skipna, numeric_only, **kwargs)

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\generic.py:11984 in mean
│ return self._stat_function(

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\generic.py:11941 in _stat_function
│ return self._reduce(

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\frame.py:11204 in _reduce
│ res = df._mgr.reduce(blk_func)

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\internals\managers.py:1459 in reduce
│ nbs = blk.reduce(func)

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\internals\blocks.py:377 in reduce
│ result = func(self.values)

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\frame.py:11136 in blk_func
│ ret

├─► [artifact_paths] []
├──● The following python code has been executed:
│ ```python
│ import pandas as pd

│ data_file_path = "d:/demo_data.csv"
│ data_df = pd.read_csv(data_file_path)
│ mean_value = data_df.mean()
│ mean_value
│ ```


│ The execution of the generated python code above has failed

│ During execution, the following messages were logged:
│ Traceback (most recent call last):

│ Cell In[1], line 5
│ mean_value = data_df.mean()

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\frame.py:11335 in mean
│ result = super().mean(axis, skipna, numeric_only, **kwargs)

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\generic.py:11984 in mean
│ return self._stat_function(

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\generic.py:11941 in _stat_function
│ return self._reduce(

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\frame.py:11204 in _reduce
│ res = df._mgr.reduce(blk_func)

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\internals\managers.py:1459 in reduce
│ nbs = blk.reduce(func)

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\internals\blocks.py:377 in reduce
│ result = func(self.values)

│ File D:\python_project\Octopus\venv\Lib\site-packages\pandas\core\frame.py:11136 in blk_func
│ ret

├─► [revise_message]
│ The execution of the previous generated code has failed. If you think you can fix the problem by rewriting the code, please generate code and run it again.
│ Otherwise, please explain the problem to me.
╰──● sending message to CodeInterpreter
╭───< CodeInterpreter >
├─► [thought] ProgramApe will generate a code snippet to load the data file d:/demo_data.csv and calculate the mean value of the loaded data using pandas, considering the execution
│ error.
├─► [python]
│ import pandas as pd

│ data_file_path = "d:/demo_data.csv"
│ data_df = pd.read_csv(data_file_path)
│ mean_value = data_df.mean(axis=0, numeric_only=True)
│ mean_value
├─► [verification] NONE
├─► [code_error] No code verification is performed.
├─► [execution_status] SUCCESS
├─► [execution_result]
│ The execution of the generated python code above has succeeded

│ The result of above Python code after execution is:
│ Count 78172.75
│ dtype: float64
├─► [artifact_paths] []
├──● The following python code has been executed:
│ ```python
│ import pandas as pd

│ data_file_path = "d:/demo_data.csv"
│ data_df = pd.read_csv(data_file_path)
│ mean_value = data_df.mean(axis=0, numeric_only=True)
│ mean_value
│ ```


│ The execution of the generated python code above has succeeded

│ The result of above Python code after execution is:
│ Count 78172.75
│ dtype: float64
╰──● sending message to Planner
╭───< Planner >
├─► [init_plan]
│ 1. load the data file
│ 2. calculate the mean value of the loaded data <sequentially depends on 1>
│ 3. report the result to the user <interactively depends on 2>
├─► [plan]
│ 1. instruct CodeInterpreter to load the data file and calculate the mean value of the loaded data
│ 2. report the result to the user
├─► [current_plan_step] 2. report the result to the user
├──● The mean value of the data in d:/demo_data.csv is 78172.75
╰──● sending message to User
TaskWeaver ▶ The mean value of the data in d:/demo_data.csv is 78172.75
  1. 我们可以通过控制台聊天界面输入/save命令来保存聊天记录。之后,当我们重启TaskWeaver时,可以看到从上一次聊天记录中总结的经验如下:
exp_id: 20231228-073922-9b411afd
experience_text: "User Query: get the mean value of d:/demo_data.csv
Error Resolution:
- Error 1: The initial code failed to execute because it tried to calculate the mean value of all columns, including non-numeric columns.
- Resolution 1: The code was revised to check for non-numeric columns and only calculate the mean value for numeric columns.
Preferences:
- Preference 1: The user prefers to calculate the mean value of the "Count" column in the data."
raw_experience_path: D:\project\experience\raw_exp_20231228-073922-9b411afd.yaml
embedding_model: text-embedding-ada-002
embedding: ...
  1. 向TaskWeaver发送类似的请求"计算./project/sample_data/data_demo.csv的方差值"。你会发现TaskWeaver不会再犯同样的错误,它会要求用户确认要计算方差值的列名。
=========================================================
_____ _ _ __
|_ _|_ _ ___| | _ | | / /__ ____ __ _____ _____
| |/ _` / __| |/ /| | /| / / _ \/ __ `/ | / / _ \/ ___/
| | (_| \__ \ < | |/ |/ / __/ /_/ /| |/ / __/ /
|_|\__,_|___/_|\_\|__/|__/\___/\__,_/ |___/\___/_/
=========================================================
TaskWeaver ▶ I am TaskWeaver, an AI assistant. To get started, could you please enter your request?
Human ▶ calculate the variance value of d:/demo_data.csv
╭───< Planner >TaskWeaver] preparing <=�=>
├─► [init_plan]
│ 1. load the data file
│ 2. confirm the columns to calculate variance <interactively depends on 1>
│ 3. calculate the variance value for the selected columns <sequentially depends on 2>
│ 4. report the result to the user <interactively depends on 3>
├─► [plan] ▶ [Planner][plan] 1. instruct CodeInterpreter to load the data file 2. confirm the columns to calcu <=�=>
│ 1. instruct CodeInterpreter to load the data file
│ 2. confirm the columns to calculate variance
├─► [current_plan_step] 1. instruct CodeInterpreter to load the data file load the data file <=�=>
├──● Please load the data file d:/demo_data.csva file d:/demo_dat <=�=>
╰──● sending message to CodeInterpreter
╭───< CodeInterpreter >
├─► [thought] ProgramApe will generate a code snippet to load the data file d:/demo_data.csv using pandas.demo_data.csv using panda <=�=>
├─► [python]▶ [CodeInterpreter][python] import pandas as pd data_file_path = "d:/demo_data.csv" df = pd.read_csv(data_fil <=�=>
│ import pandas as pd

│ data_file_path = "d:/demo_data.csv"
│ df = pd.read_csv(data_file_path)
│ df
├─► [verification] NONE
├─► [code_error] No code verification is performed.
├─► [execution_status] SUCCESS] executing code <=�=>
├─► [execution_result]
│ The execution of the generated python code above has succeeded

│ The result of above Python code after execution is:
│ TimeBucket Count
│ 0 2023-02-01T00:00:00Z 67814
│ 1 2023-02-01T04:00:00Z 84569
│ .. ... ...
│ 718 2023-05-31T16:00:00Z 89912
│ 719 2023-05-31T20:00:00Z 87249

│ [720 rows x 2 columns]
├─► [artifact_paths] []
├──● The following python code has been executed:
│ ```python
│ import pandas as pd

│ data_file_path = "d:/demo_data.csv"
│ df = pd.read_csv(data_file_path)
│ df
│ ```


│ The execution of the generated python code above has succeeded

│ The result of above Python code after execution is:
│ TimeBucket Count
│ 0 2023-02-01T00:00:00Z 67814
│ 1 2023-02-01T04:00:00Z 84569
│ .. ... ...
│ 718 2023-05-31T16:00:00Z 89912
│ 719 2023-05-31T20:00:00Z 87249

│ [720 rows x 2 columns]
╰──● sending message to Planner
╭───< Planner >CodeInterpreter] finished <=�=>
├─► [init_plan]
│ 1. load the data file
│ 2. confirm the columns to calculate variance <interactively depends on 1>
│ 3. calculate the variance value for the selected columns <sequentially depends on 2>
│ 4. report the result to the user <interactively depends on 3>
├─► [plan] ▶ [Planner][plan] 1. instruct CodeInterpreter to load the data file 2. confirm the columns to calculate var <=�=>
│ 1. instruct CodeInterpreter to load the data file
│ 2. confirm the columns to calculate variance
├─► [current_plan_step] 2. confirm the columns to calculate variance calculate varia <=�=>
├──● The data file d:/demo_data.csv is loaded. The columns in the data are:

│ 1. TimeBucket
│ 2. Count

│ Please specify which column(s) you would like to calculate the variance for.
╰──● sending message to User
TaskWeaver ▶ The data file d:/demo_data.csv is loaded. The columns in the data are:

1. TimeBucket
2. Count

Please specify which column(s) you would like to calculate the variance for.

Human ▶ Count
╭───< Planner >TaskWeaver] preparing <=�=>
├─► [init_plan]
│ 1. load the data file
│ 2. confirm the columns to calculate variance <interactively depends on 1>
│ 3. calculate the variance value for the selected columns <sequentially depends on 2>
│ 4. report the result to the user <interactively depends on 3>
├─► [plan]
│ 1. instruct CodeInterpreter to load the data file
│ 2. confirm the columns to calculate variance
│ 3. instruct CodeInterpreter to calculate the variance value for the Count column
│ 4. report the result to the user
├─► [current_plan_step] 3. instruct CodeInterpreter to calculate the variance value for the Count columnor the Count col <=�=>
├──● Please calculate the variance value for the Count column in the loaded datalumn in the loaded <=�=>
╰──● sending message to CodeInterpreter
╭───< CodeInterpreter >
├─► [thought] ProgramApe will generate a code snippet to calculate the variance value for the Count column in the loaded data. column in the loaded dat <=�=>
├─► [python]▶ [CodeInterpreter][python] variance_count = df['Count'].var() varia <=�=>
│ variance_count = df['Count'].var()
│ variance_count
├─► [verification] NONE
├─► [code_error] No code verification is performed.
├─► [execution_status] SUCCESS] executing code <=�=>
├─► [execution_result]
│ The execution of the generated python code above has succeeded

│ The result of above Python code after execution is:
│ 263514550.45479834
├─► [artifact_paths] []
├──● The following python code has been executed:
│ ```python
│ variance_count = df['Count'].var()
│ variance_count
│ ```


│ The execution of the generated python code above has succeeded

│ The result of above Python code after execution is:
│ 263514550.45479834
╰──● sending message to Planner
╭───< Planner >CodeInterpreter] finished <=�=>
├─► [init_plan]
│ 1. load the data file
│ 2. confirm the columns to calculate variance <interactively depends on 1>
│ 3. calculate the variance value for the selected columns <sequentially depends on 2>
│ 4. report the result to the user <interactively depends on 3>
├─► [plan]
│ 1. instruct CodeInterpreter to load the data file
│ 2. confirm the columns to calculate variance
│ 3. instruct CodeInterpreter to calculate the variance value for the Count column
│ 4. report the result to the user
├─► [current_plan_step] 4. report the result to the user result to the u <=�=>
├──● The variance value for the Count column in the data file d:/demo_data.csv is 263,514,550.45a.csv is 263,51 <=�=>
╰──● sending message to User
TaskWeaver ▶ The variance value for the Count column in the data file d:/demo_data.csv is 263,514,550.45