Mintplex-Labs / anything-llm

The all-in-one Desktop & Docker AI application with built-in RAG, AI agents, and more.
https://anythingllm.com
MIT License
26.12k stars 2.61k forks source link

[BUG]: Agent chat information contaminates other threads #1349

Closed Propheticus closed 5 months ago

Propheticus commented 5 months ago

How are you running AnythingLLM?

Docker (local)

What happened?

The Agent query and response history from the 'default' thread spill over into newly created threads.

Steps:

Default thread: image

New thread: image

logs of first message in new thread look normal:

[2024-05-10 23:01:08.203] [INFO] Received POST request to /v1/chat/completions with body: {
  "model": "lmstudio-community/Meta-Llama-3-8B-Instruct-BPE-fix-GGUF/Meta-Llama-3-8B-Instruct-Q8_0.gguf",
  "stream": true,
  "messages": [
    {
      "role": "system",
      "content": "You are a smart, precise and helpful AI assistant. Use the provided context to answer the user's questions. Do not make up answers that are not in the context.\n"
    },
    {
      "role": "user",
      "content": "This is text in a new thread"
    }
  ],
  "temperature": 0.7
}

The first agent call does not

[2024-05-10 23:01:27.985] [INFO] Received POST request to /v1/chat/completions with body: {
  "model": "lmstudio-community/Meta-Llama-3-8B-Instruct-BPE-fix-GGUF/Meta-Llama-3-8B-Instruct-Q8_0.gguf",
  "temperature": 0,
  "messages": [
    {
      "content": "You are a program which picks the most optimal function and parameters to call.\n      DO NOT HAVE TO PICK A FUNCTION IF IT WILL NOT HELP ANSWER OR FULFILL THE USER'S QUERY.\n      When a function is selection, respond in JSON with no additional text.\n      When there is no relevant function to call - return with a regular chat text response.\n      Your task is to pick a **single** function that we will use to call, if any seem useful or relevant for the user query.\n\n      All JSON responses should have two keys.\n      'name': this is the name of the function name to call. eg: 'web-scraper', 'rag-memory', etc..\n      'arguments': this is an object with the function properties to invoke the function.\n      DO NOT INCLUDE ANY OTHER KEYS IN JSON RESPONSES.\n\n      Here are the available tools you can use an examples of a query and response so you can understand how each one works.\n      -----------\nFunction name: rag-memory\nFunction Description: Search against local documents for context that is relevant to the query or store a snippet of text into memory for retrieval later. Storing information should only be done when the user specifically requests for information to be remembered or saved to long-term memory. You should use this tool before search the internet for information. Do not use this tool unless you are explicity told to 'remember' or 'store' information.\nFunction parameters in JSON format:\n{\n    \"action\": {\n        \"type\": \"string\",\n        \"enum\": [\n            \"search\",\n            \"store\"\n        ],\n        \"description\": \"The action we want to take to search for existing similar context or storage of new context.\"\n    },\n    \"content\": {\n        \"type\": \"string\",\n        \"description\": \"The plain text to search our local documents with or to store in our vector database.\"\n    }\n}\nQuery: \"What is AnythingLLM?\"\nJSON: {\"action\":\"search\",\"content\":\"What is AnythingLLM?\"}\nQuery: \"What do you know about Plato's motives?\"\nJSON: {\"action\":\"search\",\"content\":\"What are the facts about Plato's motives?\"}\nQuery: \"Remember that you are a robot\"\nJSON: {\"action\":\"store\",\"content\":\"I am a robot, the user told me that i am.\"}\nQuery: \"Save that to memory please.\"\nJSON: {\"action\":\"store\",\"content\":\"<insert summary of conversation until now>\"}\n-----------\n-----------\nFunction name: document-summarizer\nFunction Description: Can get the list of files available to search with descriptions and can select a single file to open and summarize.\nFunction parameters in JSON format:\n{\n    \"action\": {\n        \"type\": \"string\",\n        \"enum\": [\n            \"list\",\n            \"summarize\"\n        ],\n        \"description\": \"The action to take. 'list' will return all files available with their filename and descriptions. 'summarize' will open and summarize the file by the a document name.\"\n    },\n    \"document_filename\": {\n        \"type\": \"string\",\n        \"x-nullable\": true,\n        \"description\": \"The file name of the document you want to get the full content of.\"\n    }\n}\nQuery: \"Summarize example.txt\"\nJSON: {\"action\":\"summarize\",\"document_filename\":\"example.txt\"}\nQuery: \"What files can you see?\"\nJSON: {\"action\":\"list\",\"document_filename\":null}\nQuery: \"Tell me about readme.md\"\nJSON: {\"action\":\"summarize\",\"document_filename\":\"readme.md\"}\n-----------\n-----------\nFunction name: web-scraping\nFunction Description: Scrapes the content of a webpage or online resource from a provided URL.\nFunction parameters in JSON format:\n{\n    \"url\": {\n        \"type\": \"string\",\n        \"format\": \"uri\",\n        \"description\": \"A complete web address URL including protocol. Assumes https if not provided.\"\n    }\n}\nQuery: \"What is useanything.com about?\"\nJSON: {\"uri\":\"https://useanything.com\"}\nQuery: \"Scrape https://example.com\"\nJSON: {\"uri\":\"https://example.com\"}\n-----------\n-----------\nFunction name: web-browsing\nFunction Description: Searches for a given query using a search engine to get better results for the user query.\nFunction parameters in JSON format:\n{\n    \"query\": {\n        \"type\": \"string\",\n        \"description\": \"A search query.\"\n    }\n}\nQuery: \"Who won the world series today?\"\nJSON: {\"query\":\"Winner of today's world series\"}\nQuery: \"What is AnythingLLM?\"\nJSON: {\"query\":\"AnythingLLM\"}\nQuery: \"Current AAPL stock price\"\nJSON: {\"query\":\"AAPL stock price today\"}\n-----------\n\n\n      Now pick a function if there is an appropriate one to use given the last user message and the given conversation so far.",
      "role": "system"
    },
    {
      "content": "@agent can you browse the web to tell me when the Eurovision final is broadcasted? ",
      "role": "user"
    },
    {
      "content": "Based on the web browsing results, it appears that the Eurovision Song Contest 2024 final is scheduled to take place on Saturday, May 11th, at 8pm. This information is confirmed by multiple sources, including BBC One and BBC iPlayer.\n\nHere are some of the relevant results:\n\n* The official Eurovision website mentions that the Grand Final will take place in Malmö, Sweden, but does not provide a specific date.\n* Radio Times reports that the Eurovision Song Contest final will air on BBC One and BBC iPlayer on Saturday 11th May at 8pm.\n* Wikipedia lists the dates for the Eurovision Song Contest 2023 as two semi-finals on May 9th and 11th, followed by a final on May 13th. However, it's unclear if these dates will be repeated in 2024.\n\nI hope this information is helpful! Let me know if you have any further questions.",
      "role": "assistant"
    },
    {
      "content": "@agent this is agent text in a new thread",
      "role": "user"
    }
  ]
}

Are there known steps to reproduce?

No response

ShadowArcanist commented 5 months ago

I just tested this on MacOS Desktop:

First I asked about Date in Austin Texas image

Then I created a new thread and asked for climate info but I didn't mentioned the location image

Model used is - ollama:llama3:8b-instruct-q8_0 I ran the Desktop app on the debug mode and this is what I got on terminal


[AgentHandler] Start ba98fc9b-88cd-44fb-8d4e-d65260ec4223::ollama:llama3:8b-instruct-q8_0
[TELEMETRY SENT] {
  event: 'agent_chat_started',
  distinctId: 'eb81c08d-5e69-4d74-ad8c-01028ee8a5eb',
  properties: { runtime: 'desktop' }
}
[AgentHandler] Attached websocket plugin to Agent cluster
[AgentHandler] Attached chat-history plugin to Agent cluster
[AgentHandler] Attaching user and default agent to Agent cluster.
[AgentHandler] Attached rag-memory plugin to Agent cluster
[AgentHandler] Attached document-summarizer plugin to Agent cluster
[AgentHandler] Attached web-scraping plugin to Agent cluster
[AgentHandler] Attached web-browsing plugin to Agent cluster
[AgentLLM - llama3:8b-instruct-q8_0] Valid tool call found - running web-browsing.
[AgentHandler] [debug]: @agent is attempting to call `web-browsing` tool
[AgentLLM - llama3:8b-instruct-q8_0] Function tool with exact arguments has already been called this stack.
[AgentLLM - llama3:8b-instruct-q8_0] Will assume chat completion without tool call inputs.
[TELEMETRY SENT] {
  event: 'agent_chat_sent',
  distinctId: 'eb81c08d-5e69-4d74-ad8c-01028ee8a5eb',
  properties: { runtime: 'desktop' }
}
[TELEMETRY SENT] {
  event: 'workspace_thread_created',
  distinctId: 'eb81c08d-5e69-4d74-ad8c-01028ee8a5eb',
  properties: {
    multiUserMode: false,
    LLMSelection: 'groq',
    Embedder: 'ollama',
    VectorDbSelection: 'lancedb',
    runtime: 'desktop'
  }
}
[Event Logged] - workspace_thread_created
[AgentHandler] End ba98fc9b-88cd-44fb-8d4e-d65260ec4223::ollama:llama3:8b-instruct-q8_0
[TELEMETRY SENT] {
  event: 'sent_chat',
  distinctId: 'eb81c08d-5e69-4d74-ad8c-01028ee8a5eb',
  properties: {
    multiUserMode: false,
    LLMSelection: 'groq',
    Embedder: 'ollama',
    VectorDbSelection: 'lancedb',
    runtime: 'desktop'
  }
}
[Event Logged] - sent_chat
[AgentHandler] Start a7b2104a-6c90-4bb4-9a8d-19e57e178899::ollama:llama3:8b-instruct-q8_0
[TELEMETRY SENT] {
  event: 'agent_chat_started',
  distinctId: 'eb81c08d-5e69-4d74-ad8c-01028ee8a5eb',
  properties: { runtime: 'desktop' }
}
[AgentHandler] Attached websocket plugin to Agent cluster
[AgentHandler] Attached chat-history plugin to Agent cluster
[AgentHandler] Attaching user and default agent to Agent cluster.
[AgentHandler] Attached rag-memory plugin to Agent cluster
[AgentHandler] Attached document-summarizer plugin to Agent cluster
[AgentHandler] Attached web-scraping plugin to Agent cluster
[AgentHandler] Attached web-browsing plugin to Agent cluster
[AgentLLM - llama3:8b-instruct-q8_0] Valid tool call found - running web-browsing.
[AgentHandler] [debug]: @agent is attempting to call `web-browsing` tool
[AgentLLM - llama3:8b-instruct-q8_0] Function tool with exact arguments has already been called this stack.
[AgentLLM - llama3:8b-instruct-q8_0] Will assume chat completion without tool call inputs.
[TELEMETRY SENT] {
  event: 'agent_chat_sent',
  distinctId: 'eb81c08d-5e69-4d74-ad8c-01028ee8a5eb',
  properties: { runtime: 'desktop' }
}
[AgentHandler] End a7b2104a-6c90-4bb4-9a8d-19e57e178899::ollama:llama3:8b-instruct-q8_0 ```
timothycarambat commented 5 months ago

Think this might be desktop only. Cannot replicate on docker version but i bet this is because the state does not refresh on desktop since we prevent reloads when navigating between threads for UX. Let me look there

timothycarambat commented 5 months ago

Confirmed, it is just desktop. In fact, if you go to the new thread and send the chat, it even appears in the first thread as a historical message.

Propheticus commented 5 months ago

Confirmed, it is just desktop. In fact, if you go to the new thread and send the chat, it even appears in the first thread as a historical message.

I'm running docker. And I did not see that behaviour of addition to the first thread. image

Propheticus commented 5 months ago

I'll check on Edge to see if it's browser specific. I'm using Firefox. Edit: yup, also happens in Edge.

timothycarambat commented 5 months ago

@Propheticus are you saying this same bug occurs in docker as well? I just tested that and could not replicate

Propheticus commented 5 months ago

@timothycarambat I am saying I found this bug while using Docker, yes.

Propheticus commented 5 months ago

That was quick.

timothycarambat commented 5 months ago

it was a simple typo I overlooked :)

Will be in next desktop release but should be live in docker once build is complete. Thanks for pointing this out, it actually lead to an overall improvement in the desktop client as well that was not even related.

Propheticus commented 5 months ago

Cool. Glad it helped. Please also see my commenting on Discord and Bug reporting here as trying to help perfect a very nice tool. Thanks for making this and sharing it with the community!

Propheticus commented 5 months ago

it was a simple typo I overlooked :)

Will be in next desktop release but should be live in docker once build is complete. Thanks for pointing this out, it actually lead to an overall improvement in the desktop client as well that was not even related.

Confirmed resolved in latest pull of Docker image.