microsoft / TaskWeaver

A code-first agent framework for seamlessly planning and executing data analytics tasks.
https://microsoft.github.io/TaskWeaver/
MIT License
5.19k stars 661 forks source link

Unable to play the document_retriever plugins #204

Closed greatgatsby123 closed 6 months ago

greatgatsby123 commented 7 months ago

Describe the bug Whenever a plugin is enabled an requested to be used the Code Interpreter exits with an error claiming that the plugin is not defined.

To Reproduce Steps to reproduce the behavior:

  1. Enable any plugin (e.g. document retriever) and start the service
  2. Type the user query "What is TaskWeaver"
  3. Wait for the response
  4. See error

Expected behavior Call the plugin function

Screenshots If applicable, add screenshots to help explain your problem.

Environment Information (please complete the following information):

Additional context 2024-02-09 13:54:30,470 - INFO - Session 20240209-135430-05895969 is initialized 2024-02-09 13:54:30,520 - INFO - Planner initialized successfully 2024-02-09 13:54:30,558 - INFO - CodeInterpreter initialized successfully 2024-02-09 13:54:30,559 - INFO - CodeInterpreter initialized successfully. 2024-02-09 13:54:31,481 - INFO - Session 20240209-135431-0a12e451 is initialized 2024-02-09 13:54:31,531 - INFO - Planner initialized successfully 2024-02-09 13:54:31,570 - INFO - CodeInterpreter initialized successfully 2024-02-09 13:54:31,571 - INFO - CodeInterpreter initialized successfully. 2024-02-09 13:54:34,124 - INFO - Session 20240209-135434-a91abfbb is initialized 2024-02-09 13:54:34,160 - INFO - Planner initialized successfully 2024-02-09 13:54:34,198 - INFO - CodeInterpreter initialized successfully 2024-02-09 13:54:34,200 - INFO - CodeInterpreter initialized successfully. 2024-02-09 13:54:37,865 - INFO - Session 20240209-135437-31a131b9 is initialized 2024-02-09 13:54:37,916 - INFO - Planner initialized successfully 2024-02-09 13:54:37,962 - INFO - CodeInterpreter initialized successfully 2024-02-09 13:54:37,963 - INFO - CodeInterpreter initialized successfully. 2024-02-09 13:54:39,339 - INFO - Use back up engine: False 2024-02-09 13:54:51,805 - INFO - LLM output: {"response": [{"type": "init_plan", "content": "1. Retrieve documents related to TaskWeaver\n2. Summarize the information about TaskWeaver from the retrieved documents <sequentially depends on 1>"}, {"type": "plan", "content": "1. instruct CodeInterpreter to retrieve documents related to TaskWeaver"}, {"type": "current_plan_step", "content": "1. instruct CodeInterpreter to retrieve documents related to TaskWeaver"}, {"type": "send_to", "content": "CodeInterpreter"}, {"type": "message", "content": "Please retrieve documents related to TaskWeaver"}]} 2024-02-09 13:54:51,807 - INFO - Planner talk to CodeInterpreter: Please retrieve documents related to TaskWeaver 2024-02-09 13:54:51,808 - INFO - Use back up engine: False 2024-02-09 13:54:59,729 - INFO - LLM output: {"response": [{"type": "thought", "content": "ProgramApe will call the document_retriever plugin function to retrieve documents related to TaskWeaver."}, {"type": "python", "content": "# Calling the document_retriever plugin to retrieve documents related to TaskWeaver\nTaskWeaver_docs = document_retriever(query=\"what is TaskWeaver\")\nTaskWeaver_docs"}]} 2024-02-09 13:54:59,732 - INFO - Code to be verified: # Calling the document_retriever plugin to retrieve documents related to TaskWeaver TaskWeaver_docs = document_retriever(query="what is TaskWeaver") TaskWeaver_docs 2024-02-09 13:54:59,734 - INFO - Code to be executed: # Calling the document_retriever plugin to retrieve documents related to TaskWeaver TaskWeaver_docs = document_retriever(query="what is TaskWeaver") TaskWeaver_docs 2024-02-09 13:55:06,955 - INFO - CodeInterpreter talk to CodeInterpreter: The following python code has been executed:

# Calling the document_retriever plugin to retrieve documents related to TaskWeaver
TaskWeaver_docs = document_retriever(query="what is TaskWeaver")
TaskWeaver_docs

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 2 TaskWeaver_docs = document_retriever(query="what is TaskWeaver")

NameError: name 'document_retriever' is not defined

2024-02-09 13:55:06,955 - INFO - Use back up engine: True 2024-02-09 13:55:16,404 - INFO - LLM output: {"response": [{"type": "thought", "content": "ProgramApe acknowledges the execution error due to the plugin function 'document_retriever' not being defined. Since plugin functions can be directly called without importing, the error is likely due to an oversight in the execution environment rather than the code itself."}, {"type": "thought", "content": "ProgramApe will attempt to call the plugin function again without any changes, as the function should be directly callable in the user's environment."}, {"type": "python", "content": "# Calling the document_retriever plugin to retrieve documents related to TaskWeaver\nTaskWeaver_docs = document_retriever(query=\"what is TaskWeaver\")\nTaskWeaver_docs"}]} 2024-02-09 13:55:16,407 - INFO - Code to be verified: # Calling the document_retriever plugin to retrieve documents related to TaskWeaver TaskWeaver_docs = document_retriever(query="what is TaskWeaver") TaskWeaver_docs 2024-02-09 13:55:16,410 - INFO - Code to be executed: # Calling the document_retriever plugin to retrieve documents related to TaskWeaver TaskWeaver_docs = document_retriever(query="what is TaskWeaver") TaskWeaver_docs 2024-02-09 13:55:17,078 - INFO - CodeInterpreter talk to CodeInterpreter: The following python code has been executed:

# Calling the document_retriever plugin to retrieve documents related to TaskWeaver
TaskWeaver_docs = document_retriever(query="what is TaskWeaver")
TaskWeaver_docs

The execution of the generated python code above has failed

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

Cell In[2], line 2 TaskWeaver_docs = document_retriever(query="what is TaskWeaver")

NameError: name 'document_retriever' is not defined

2024-02-09 13:55:17,079 - INFO - Use back up engine: True 2024-02-09 13:55:19,755 - WARNING - Failed to parse attachment: thought- due to Task stopped by user 2024-02-09 13:55:31,054 - INFO - LLM output: {"response": [{"type": "thought", "content": "ProgramApe understands that the previous attempts to execute the code have failed due to a NameError, indicating that the 'document_retriever' function is not defined in the execution environment."}, {"type": "thought", "content": "Since ProgramApe is prohibited from importing plugin functions and the function should be directly callable, the issue seems to be on the execution side rather than the code itself."}, {"type": "text", "content": "The plugin function 'document_retriever' should be directly callable without import according to the instructions. However, since it's not recognized in your environment, this indicates a possible issue with the execution environment itself. Please ensure that the plugin functions are correctly accessible in your environment and try calling the function again."}]} 2024-02-09 13:55:31,064 - INFO - CodeInterpreter talk to Planner: The plugin function 'document_retriever' should be directly callable without import according to the instructions. However, since it's not recognized in your environment, this indicates a possible issue with the execution environment itself. Please ensure that the plugin functions are correctly accessible in your environment and try calling the function again. 2024-02-09 13:55:31,065 - INFO - Use back up engine: False 2024-02-09 13:55:38,880 - INFO - LLM output: {"response": [{"type": "init_plan", "content": "1. Retrieve documents related to TaskWeaver\n2. Summarize the information about TaskWeaver from the retrieved documents <sequentially depends on 1>"}, {"type": "plan", "content": "1. instruct CodeInterpreter to retrieve documents related to TaskWeaver using the document_retriever plugin"}, {"type": "current_plan_step", "content": "1. instruct CodeInterpreter to retrieve documents related to TaskWeaver using the document_retriever plugin"}, {"type": "send_to", "content": "CodeInterpreter"}, {"type": "message", "content": "Please use the document_retriever plugin to retrieve documents related to TaskWeaver"}]} 2024-02-09 13:55:38,882 - INFO - Planner talk to CodeInterpreter: Please use the document_retriever plugin to retrieve documents related to TaskWeaver 2024-02-09 13:55:38,882 - INFO - Use back up engine: False 2024-02-09 13:55:44,940 - INFO - LLM output: {"response": [{"type": "thought", "content": "ProgramApe will use the document_retriever plugin to retrieve documents related to TaskWeaver as per the user's request."}, {"type": "python", "content": "# Using the document_retriever plugin to retrieve documents related to TaskWeaver\nTaskWeaver_docs = document_retriever(query=\"what is TaskWeaver\")\nTaskWeaver_docs"}]} 2024-02-09 13:55:44,942 - INFO - Code to be verified: # Using the document_retriever plugin to retrieve documents related to TaskWeaver TaskWeaver_docs = document_retriever(query="what is TaskWeaver") TaskWeaver_docs 2024-02-09 13:55:44,944 - INFO - Code to be executed: # Using the document_retriever plugin to retrieve documents related to TaskWeaver TaskWeaver_docs = document_retriever(query="what is TaskWeaver") TaskWeaver_docs 2024-02-09 13:55:45,604 - INFO - CodeInterpreter talk to CodeInterpreter: The following python code has been executed:

# Using the document_retriever plugin to retrieve documents related to TaskWeaver
TaskWeaver_docs = document_retriever(query="what is TaskWeaver")
TaskWeaver_docs

The execution of the generated python code above has failed

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

Cell In[3], line 2 TaskWeaver_docs = document_retriever(query="what is TaskWeaver")

NameError: name 'document_retriever' is not defined

2024-02-09 13:55:45,604 - INFO - Use back up engine: True 2024-02-09 13:55:58,916 - INFO - LLM output: {"response": [{"type": "thought", "content": "ProgramApe acknowledges the repeated failure due to the NameError and understands that the plugin function 'document_retriever' is not being recognized in the execution environment."}, {"type": "thought", "content": "ProgramApe is instructed not to import plugins, as they should be directly callable. The issue seems to be on the execution side, and ProgramApe cannot resolve it by rewriting the code."}, {"type": "text", "content": "The 'document_retriever' plugin function is not being recognized in your execution environment, which is causing the NameError. As per the instructions, plugin functions should be directly callable without import, and ProgramApe cannot modify the execution environment or import the plugin. Please ensure that the plugin functions are correctly accessible in your environment. If the issue persists, it may be necessary to consult with the environment or system administrator to resolve the plugin accessibility issue."}]} 2024-02-09 13:55:58,924 - INFO - CodeInterpreter talk to Planner: The 'document_retriever' plugin function is not being recognized in your execution environment, which is causing the NameError. As per the instructions, plugin functions should be directly callable without import, and ProgramApe cannot modify the execution environment or import the plugin. Please ensure that the plugin functions are correctly accessible in your environment. If the issue persists, it may be necessary to consult with the environment or system administrator to resolve the plugin accessibility issue. 2024-02-09 13:55:58,925 - INFO - Use back up engine: False 2024-02-09 13:56:15,256 - INFO - LLM output: {"response": [{"type": "init_plan", "content": "1. Retrieve documents related to TaskWeaver\n2. Summarize the information about TaskWeaver from the retrieved documents <sequentially depends on 1>"}, {"type": "plan", "content": "1. instruct CodeInterpreter to retrieve documents related to TaskWeaver using the document_retriever plugin"}, {"type": "current_plan_step", "content": "1. instruct CodeInterpreter to retrieve documents related to TaskWeaver using the document_retriever plugin"}, {"type": "send_to", "content": "User"}, {"type": "message", "content": "I apologize for the inconvenience, but it seems there is an issue with accessing the document retrieval function in the current environment. I'm unable to provide information about TaskWeaver at this moment. Is there anything else I can assist you with?"}]} 2024-02-09 13:56:15,258 - INFO - Planner talk to User: I apologize for the inconvenience, but it seems there is an issue with accessing the document retrieval function in the current environment. I'm unable to provide information about TaskWeaver at this moment. Is there anything else I can assist you with?

liqul commented 7 months ago

@greatgatsby123 From the logs, I can see the LLM can see the plugin but the executor failed to load the plugin implementation which is typically due to dependency issues. Please take a look at this FAQ (https://microsoft.github.io/TaskWeaver/docs/plugin/how_to_develop_a_new_plugin#faq) and especially this question: “Q: Why TaskWeaver can see my plugin but cannot call it?”.

An immediate way of testing this plugin is adding the following code as explained in the FAQ:

if __name__ == "__main__":
    from taskweaver.plugin.context import temp_context

    with temp_context() as temp_ctx:
        retriever = DocumentRetriever(name="document_retriever", ctx=temp_ctx, config={"index_folder":
                                                                                           r"\absolution_path_to\project\sample_data\knowledge_base"})
        print(retriever(query="what is taskweaver?"))

If you can run it successfully, then there should be no problem when calling it as a plugin in the generated code.