Repository: run-llama/llama_index
Pull request: BUG-8206-remove-kwargs-from-ReActAgent-from-tools
# Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes [#8206](https://github.com/run-llama/llama_index/issues/8206) 

## Type of Change

Please delete options that are not relevant.

- [x] Bug fix (non-breaking change which fixes an issue)

# How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

- [x] I stared at the code and made sure it makes sense

Replicated bug using script below:

```
import os

import drum

from llama_index import SimpleDirectoryReader
from llama_index.chat_engine.types import ChatMode
from llama_index.indices.loading import load_index_from_storage
from llama_index.indices.vector_store import VectorStoreIndex
from llama_index.node_parser import SimpleNodeParser
from llama_index.prompts import Prompt
from llama_index.storage import StorageContext
from llama_index.storage.docstore import SimpleDocumentStore

reader = SimpleDirectoryReader("./docs/examples/data/paul_graham")
documents = reader.load_data()
nodes = SimpleNodeParser.from_defaults().get_nodes_from_documents(documents)
docstore = SimpleDocumentStore()
docstore.add_documents(nodes)

sc = StorageContext.from_defaults(docstore=docstore)

try:
    key = drum.RuntimeParameters.get("OPENAI_API_KEY")["apiToken"]
except:
    key = os.environ["OPENAI_API_KEY"]

index = VectorStoreIndex(nodes, storage_context=sc)

template_str = """We have provided context information below. If you don't know the answer, just say you don't know. Don't make up an answer. Do not mention you are an AI language model. 
Always say to refer to the respective department for extra information. Don't mention anything about the provided context in your response. \n"
"---------------------\n"
"{context_str}"
"\n---------------------\n"
"Do not give me an answer if it is not mentioned in the context as a fact. Given this information, please answer the question: {query_str}\n"""

qa_template = Prompt(template_str)
model = index.as_chat_engine(
    chat_mode=ChatMode.REACT,
    similarity_top_k=2, text_qa_template=qa_template)
```

After the change is made, the error of unknown params goes away.


Problem statement:
[Bug]: index.as_chat_engine
### Bug Description

VectoreStoreIndex.as_chat_engine method not taking Streaming, k_similarity, or qa_template parameters anymore.

Not sure if this was a recent update, but none of those initializer parameters are working anymore.

### Version

0.8.46

### Steps to Reproduce

Create a VectoreStoreIndex. Call as_chat_engine method on the index.

```python
sc = StorageContext.from_defaults(persist_dir=PERSIST_DIR)

    try:
        key = drum.RuntimeParameters.get("OPENAI_API_KEY")["apiToken"]
    except:
        key = os.environ["OPENAI_API_KEY"]
    
    try:
        index = load_index_from_storage(storage_context=sc, index_id='vector_index')
    
        template_str = """We have provided context information below. If you don't know the answer, just say you don't know. Don't make up an answer. Do not mention you are an AI language model. 
        Always say to refer to the respective department for extra information. Don't mention anything about the provided context in your response. \n"
        "---------------------\n"
        "{context_str}"
        "\n---------------------\n"
        "Do not give me an answer if it is not mentioned in the context as a fact. Given this information, please answer the question: {query_str}\n"""
    
        qa_template = Prompt(template_str)
        model = index.as_chat_engine(streaming=False
                                                  ,similarity_top_k=2
                                                  , text_qa_template=qa_template)
```


### Relevant Logs/Tracbacks

```shell
Error: __init__() got an unexpected keyword argument 'streaming'
```

Hints from issue discussion:
@XariZaru just remove the streaming kwarg, you don't need to pass this to chat engines since they have `chat()` and `stream_chat()` endpoints
> @XariZaru just remove the streaming kwarg, you don't need to pass this to chat engines since they have `chat()` and `stream_chat()` endpoints

When I remove the streaming kwarg, it complains about the next kwarg.

Error has occurred loading model from vector store index
__init__() got an unexpected keyword argument 'similarity_top_k'
@XariZaru  Do you have the full traceback? 
> @XariZaru Do you have the full traceback?

Error has occurred loading model from vector store index
Traceback (most recent call last):
  File "/tmp/ipykernel_24/2984667311.py", line 31, in load_model
    model = index.as_chat_engine(similarity_top_k=2
  File "/etc/system/kernel/.venv/lib64/python3.9/site-packages/llama_index/indices/base.py", line 393, in as_chat_engine
    return ReActAgent.from_tools(
  File "/etc/system/kernel/.venv/lib64/python3.9/site-packages/llama_index/agent/react/base.py", line 95, in from_tools
    return cls(
TypeError: __init__() got an unexpected keyword argument 'similarity_top_k'
Ah, the `ReActAgent.from_tools` just needs to be updated to accept `**kwargs`
> Ah, the `ReActAgent.from_tools` just needs to be updated to accept `**kwargs`

Okay cool. I'll just wait for the change to be made and redownload llama_index right?

Commit message: remove **kwargs from cls(..) of ReActAgent.from_tools; add doc string with NOTE on kwargs propagation

Patch to review:
diff --git a/llama_index/agent/react/base.py b/llama_index/agent/react/base.py
index b44b93e18c..92a99ed66b 100644
--- a/llama_index/agent/react/base.py
+++ b/llama_index/agent/react/base.py
@@ -86,6 +86,16 @@ def from_tools(
         verbose: bool = False,
         **kwargs: Any,
     ) -> "ReActAgent":
+        """Convenience constructor method from set of of BaseTools (Optional).
+
+        NOTE: kwargs should have been exhausted by this point. In other words
+        the various upstream components such as BaseSynthesizer (response synthesizer)
+        or BaseRetriver should have picked up off their respective kwargs in their
+        constructions.
+
+        Returns:
+            ReActAgent
+        """
         llm = llm or OpenAI(model=DEFAULT_MODEL_NAME)
         if callback_manager is not None:
             llm.callback_manager = callback_manager
@@ -102,7 +112,6 @@ def from_tools(
             output_parser=output_parser,
             callback_manager=callback_manager,
             verbose=verbose,
-            **kwargs,
         )
 
     @property


Code review comments:
diff_hunk: @@ -86,6 +86,16 @@ def from_tools(
         verbose: bool = False,
         **kwargs: Any,
     ) -> "ReActAgent":
+        """Convenience constructor method from set of of BaseTools (Optional).
+
+        NOTE: kwargs should have been exhausted by this point. In other words
+        the various upstream components such as BaseSynthesizer (response synthesizer)
+        or BaseRetriver should have picked up off their respective kwargs in their
path: llama_index/agent/react/base.py
text: @user1:
ubernit: BaseRetriever

@author:
Good catch!