langchain
langchain copied to clipboard
How to create a vectorstoreinfo using a custom tool.
System Info
aiohttp==3.8.4 aiosignal==1.3.1 altair==4.2.2 anyio @ file:///C:/ci_311/anyio_1676425491996/work/dist argilla==1.6.0 argon2-cffi @ file:///opt/conda/conda-bld/argon2-cffi_1645000214183/work argon2-cffi-bindings @ file:///C:/ci_311/argon2-cffi-bindings_1676424443321/work asttokens @ file:///opt/conda/conda-bld/asttokens_1646925590279/work async-timeout==4.0.2 attrs @ file:///C:/ci_311/attrs_1676422272484/work Babel @ file:///C:/ci_311/babel_1676427169844/work backcall @ file:///home/ktietz/src/ci/backcall_1611930011877/work backoff==2.2.1 beautifulsoup4 @ file:///C:/b/abs_0agyz1wsr4/croot/beautifulsoup4-split_1681493048687/work bleach @ file:///opt/conda/conda-bld/bleach_1641577558959/work blinker==1.6.2 brotlipy==0.7.0 cachetools==5.3.0 certifi @ file:///C:/b/abs_4a0polqwty/croot/certifi_1683875377622/work/certifi cffi @ file:///C:/ci_311/cffi_1676423759166/work chardet==5.1.0 charset-normalizer @ file:///tmp/build/80754af9/charset-normalizer_1630003229654/work chromadb==0.3.21 click==8.1.3 clickhouse-connect==0.5.22 colorama @ file:///C:/ci_311/colorama_1676422310965/work comm @ file:///C:/ci_311/comm_1678376562840/work commonmark==0.9.1 cryptography @ file:///C:/ci_311/cryptography_1679419210767/work Cython==0.29.34 dataclasses-json==0.5.7 debugpy @ file:///C:/ci_311/debugpy_1676426137692/work decorator @ file:///opt/conda/conda-bld/decorator_1643638310831/work defusedxml @ file:///tmp/build/80754af9/defusedxml_1615228127516/work Deprecated==1.2.13 duckdb==0.7.1 entrypoints @ file:///C:/ci_311/entrypoints_1676423328987/work et-xmlfile==1.1.0 executing @ file:///opt/conda/conda-bld/executing_1646925071911/work fastapi==0.95.1 fastjsonschema @ file:///C:/ci_311/python-fastjsonschema_1679500568724/work filelock==3.12.0 frozenlist==1.3.3 fsspec==2023.4.0 ftfy==6.1.1 gitdb==4.0.10 GitPython==3.1.31 google-api-core==2.11.0 google-api-python-client==2.86.0 google-auth==2.18.0 google-auth-httplib2==0.1.0 googleapis-common-protos==1.59.0 greenlet==2.0.2 h11==0.14.0 hnswlib @ file:///D:/bld/hnswlib_1675802891722/work httpcore==0.16.3 httplib2==0.22.0 httptools==0.5.0 httpx==0.23.3 huggingface-hub==0.14.1 idna @ file:///C:/ci_311/idna_1676424932545/work importlib-metadata==6.6.0 ipykernel @ file:///C:/ci_311/ipykernel_1678734799670/work ipython @ file:///C:/b/abs_d1yx5tjhli/croot/ipython_1680701887259/work ipython-genutils @ file:///tmp/build/80754af9/ipython_genutils_1606773439826/work ipywidgets @ file:///C:/b/abs_5awapknmz_/croot/ipywidgets_1679394824767/work jedi @ file:///C:/ci_311/jedi_1679427407646/work Jinja2 @ file:///C:/ci_311/jinja2_1676424968965/work joblib==1.2.0 json5 @ file:///tmp/build/80754af9/json5_1624432770122/work jsonschema @ file:///C:/b/abs_d40z05b6r1/croot/jsonschema_1678983446576/work jupyter @ file:///C:/ci_311/jupyter_1678249952587/work jupyter-console @ file:///C:/b/abs_82xaa6i2y4/croot/jupyter_console_1680000189372/work jupyter-server @ file:///C:/ci_311/jupyter_server_1678228762759/work jupyter_client @ file:///C:/b/abs_059idvdagk/croot/jupyter_client_1680171872444/work jupyter_core @ file:///C:/b/abs_9d0ttho3bs/croot/jupyter_core_1679906581955/work jupyterlab @ file:///C:/ci_311/jupyterlab_1677719392688/work jupyterlab-pygments @ file:///tmp/build/80754af9/jupyterlab_pygments_1601490720602/work jupyterlab-widgets @ file:///C:/b/abs_38ad427jkz/croot/jupyterlab_widgets_1679055289211/work jupyterlab_server @ file:///C:/b/abs_e0qqsihjvl/croot/jupyterlab_server_1680792526136/work langchain==0.0.157 lxml @ file:///C:/b/abs_c2bg6ck92l/croot/lxml_1679646459966/work lz4==4.3.2 Markdown==3.4.3 MarkupSafe @ file:///C:/ci_311/markupsafe_1676424152318/work marshmallow==3.19.0 marshmallow-enum==1.5.1 matplotlib-inline @ file:///C:/ci_311/matplotlib-inline_1676425798036/work mistune @ file:///C:/ci_311/mistune_1676425149302/work monotonic==1.6 mpmath==1.3.0 msg-parser==1.2.0 multidict==6.0.4 mypy-extensions==1.0.0 nbclassic @ file:///C:/b/abs_c8_rs7b3zw/croot/nbclassic_1681756186106/work nbclient @ file:///C:/ci_311/nbclient_1676425195918/work nbconvert @ file:///C:/ci_311/nbconvert_1676425836196/work nbformat @ file:///C:/ci_311/nbformat_1676424215945/work nest-asyncio @ file:///C:/ci_311/nest-asyncio_1676423519896/work networkx==3.1 nltk==3.8.1 notebook @ file:///C:/b/abs_49d8mc_lpe/croot/notebook_1681756182078/work notebook_shim @ file:///C:/ci_311/notebook-shim_1678144850856/work numexpr==2.8.4 numpy==1.23.5 olefile==0.46 openai==0.27.6 openapi-schema-pydantic==1.2.4 openpyxl==3.1.2 packaging @ file:///C:/b/abs_ed_kb9w6g4/croot/packaging_1678965418855/work pandas==1.5.3 pandocfilters @ file:///opt/conda/conda-bld/pandocfilters_1643405455980/work parso @ file:///opt/conda/conda-bld/parso_1641458642106/work pdfminer.six==20221105 pickleshare @ file:///tmp/build/80754af9/pickleshare_1606932040724/work Pillow==9.5.0 platformdirs @ file:///C:/ci_311/platformdirs_1676422658103/work ply==3.11 posthog==3.0.1 prometheus-client @ file:///C:/ci_311/prometheus_client_1679591942558/work prompt-toolkit @ file:///C:/ci_311/prompt-toolkit_1676425940920/work protobuf==3.20.3 psutil @ file:///C:/ci_311_rebuilds/psutil_1679005906571/work pure-eval @ file:///opt/conda/conda-bld/pure_eval_1646925070566/work pyarrow==11.0.0 pyasn1==0.5.0 pyasn1-modules==0.3.0 pycparser @ file:///tmp/build/80754af9/pycparser_1636541352034/work pydantic==1.10.7 pydeck==0.8.1b0 Pygments @ file:///opt/conda/conda-bld/pygments_1644249106324/work Pympler==1.0.1 pyOpenSSL @ file:///C:/b/abs_de215ipd18/croot/pyopenssl_1678965319166/work pypandoc==1.11 pyparsing==3.0.9 PyQt5==5.15.7 PyQt5-sip @ file:///C:/ci_311/pyqt-split_1676428895938/work/pyqt_sip pyrsistent @ file:///C:/ci_311/pyrsistent_1676422695500/work PySocks @ file:///C:/ci_311/pysocks_1676425991111/work python-dateutil @ file:///tmp/build/80754af9/python-dateutil_1626374649649/work python-docx==0.8.11 python-dotenv==1.0.0 python-magic==0.4.27 python-pptx==0.6.21 pytz @ file:///C:/ci_311/pytz_1676427070848/work pytz-deprecation-shim==0.1.0.post0 pywin32==305.1 pywinpty @ file:///C:/ci_311/pywinpty_1677707791185/work/target/wheels/pywinpty-2.0.10-cp311-none-win_amd64.whl PyYAML==6.0 pyzmq @ file:///C:/b/abs_8b16zbmf46/croot/pyzmq_1682697651374/work qtconsole @ file:///C:/b/abs_eb4u9jg07y/croot/qtconsole_1681402843494/work QtPy @ file:///C:/ci_311/qtpy_1676432558504/work regex==2023.3.23 requests @ file:///C:/b/abs_41owkd5ymz/croot/requests_1682607524657/work rfc3986==1.5.0 rich==13.0.1 rsa==4.9 scikit-learn==1.2.2 scipy==1.10.1 Send2Trash @ file:///tmp/build/80754af9/send2trash_1632406701022/work sentence-transformers==2.2.2 sentencepiece==0.1.99 sip @ file:///C:/ci_311/sip_1676427825172/work six @ file:///tmp/build/80754af9/six_1644875935023/work smmap==5.0.0 sniffio @ file:///C:/ci_311/sniffio_1676425339093/work soupsieve @ file:///C:/b/abs_a989exj3q6/croot/soupsieve_1680518492466/work SQLAlchemy==2.0.12 stack-data @ file:///opt/conda/conda-bld/stack_data_1646927590127/work starlette==0.26.1 streamlit==1.22.0 sympy==1.11.1 tenacity==8.2.2 terminado @ file:///C:/ci_311/terminado_1678228513830/work threadpoolctl==3.1.0 tiktoken==0.3.3 tinycss2 @ file:///C:/ci_311/tinycss2_1676425376744/work tokenizers==0.13.3 toml @ file:///tmp/build/80754af9/toml_1616166611790/work tomli @ file:///C:/ci_311/tomli_1676422027483/work toolz==0.12.0 torch==2.0.0 torchvision==0.15.1 tornado @ file:///C:/ci_311/tornado_1676423689414/work tqdm==4.65.0 traitlets @ file:///C:/ci_311/traitlets_1676423290727/work transformers==4.28.1 typing-inspect==0.8.0 typing_extensions @ file:///C:/b/abs_a1bb332wcs/croot/typing_extensions_1681939523095/work tzdata==2023.3 tzlocal==4.3 unstructured==0.6.2 uritemplate==4.1.1 urllib3 @ file:///C:/b/abs_3ce53vrdcr/croot/urllib3_1680254693505/work uvicorn==0.22.0 validators==0.20.0 watchdog==3.0.0 watchfiles==0.19.0 wcwidth @ file:///Users/ktietz/demo/mc3/conda-bld/wcwidth_1629357192024/work webencodings==0.5.1 websocket-client @ file:///C:/ci_311/websocket-client_1676426063281/work websockets==11.0.2 widgetsnbextension @ file:///C:/b/abs_882k4_4kdf/croot/widgetsnbextension_1679313880295/work wikipedia==1.4.0 win-inet-pton @ file:///C:/ci_311/win_inet_pton_1676425458225/work wrapt==1.14.1 XlsxWriter==3.1.0 yarl==1.9.2 zipp==3.15.0 zstandard==0.21.0
Who can help?
@vowelparrot
I have created a toolkit from chroma documents. I have also created a custom tool.
I want to create a vectorstoreinfo from my custom tool so I can use this tool in vectorstoreagent.
Information
- [ ] The official example notebooks/scripts
- [ ] My own modified scripts
Related Components
- [X] LLMs/Chat Models
- [ ] Embedding Models
- [ ] Prompts / Prompt Templates / Prompt Selectors
- [ ] Output Parsers
- [ ] Document Loaders
- [X] Vector Stores / Retrievers
- [ ] Memory
- [X] Agents / Agent Executors
- [X] Tools / Toolkits
- [ ] Chains
- [ ] Callbacks/Tracing
- [ ] Async
Reproduction
from langchain.agents.agent_toolkits import (
create_vectorstore_agent,
VectorStoreToolkit,
VectorStoreInfo,
)
vectorstore_info = VectorStoreInfo(
name=" tax queries",
description="tax related documents",
vectorstore=db_store
)
toolkit = VectorStoreToolkit(vectorstore_info=vectorstore_info)
agent_executor = create_vectorstore_agent(
llm=llm,
toolkit=toolkit,
verbose=True
)
Expected behavior
I have created a custom tool
def evaluate expression:
ans = "expression"
return ans
tool = Tool(
name = "Expression Evaluator",
func=evaluate_expression,
description= "useful for when you need output expression.
)
Please, inform How can I create a vectorstoreinfo using this tool and add in a toolkit so I can use this tool in vectorstoreagent.
@vowelparrot Can you please inform any way or workaround. Your assistance is much appreciated.
Thanks for the question! Could you share more about your desired behavior? So you want to make a VectorStoreAgent but then give it additional custom tools?
The easiest way to do this would probably be something like:
from langchain.tools import Tool
from langchain.agents import initialize_agent, AgentType
from langchain.agents.agent_toolkits import (
create_vectorstore_agent,
VectorStoreToolkit,
VectorStoreInfo,
)
vectorstore_info = VectorStoreInfo(
name=" tax queries",
description="tax related documents",
vectorstore=db_store
)
toolkit = VectorStoreToolkit(vectorstore_info=vectorstore_info)
def my_custom_tool(expression: str) -> str:
'''what the tool does.''''
....
tools = toolkit.get_tools() + [Tool.from_function(my_custom_tool, name="My Tool Name", description="my tool description")]
agent_executor = initialize_agent(
tools,
llm,
# agent = AgentType.ZERO_SHOT_REACT_DESCRIPTION # You may want to test different agents here
Hi, @Hizafa-Nadeem! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
From what I understand, you were seeking guidance on how to create a VectorStoreInfo
using a custom tool and add it to a toolkit so that it can be used in a VectorStoreAgent
. @vowelparrot responded with a code example and suggested using the VectorStoreToolkit
to add the custom tool to the toolkit. They also asked for more information about the desired behavior.
Before we close this issue, we wanted to check if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.
Thank you for your contribution to the LangChain repository!