You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I added a very descriptive title to this question.
I searched the LangChain documentation with the integrated search.
I used the GitHub search to find a similar question and didn't find it.
Commit to Help
I commit to help with one of those options 👆
Example Code
Onserverlevel:
#Define toolssummary=SummaryTool(
...
)
www_search=BingSearchAgent(
...
)
sql_search=CosmosDBQueryTool(llm=llm)
# Create the Agentagent=create_openai_tools_agent(llm, [], CUSTOM_CHATBOT_PROMPT)
agent_executor=AgentExecutor(agent=agent, tools=[], callbacks=[logging_callback])
OnspecificHTTPrequestlevel:
```python@app.post("/agent/invoke", response_model=Output, tags=["agent"])asyncdefagent_invoke(item: AgentInput, user_roles: str=Header(...)) ->Any:
header_list= [item.strip() foriteminuser_roles.split(',')]
if"group1"inheader_list:
index_name="group1-index"elif"group2"inheader_list:
index_name= ["group1-index", "group2-index"]
else:
raiseHTTPException(status_code=400, detail="Invalid value in User-Roles header.")
doc_indexes=index_nameifisinstance(index_name, list) else [index_name]
doc_search=DocSearchAgent(
...
indexes=doc_indexes,
...
)
tools= [doc_search, www_search, summary, sql_search]
# Assign the tools to the Agent and AgentExecutoragent_executor.tools=toolsbrain_agent_executor=RunnableWithMessageHistory(
agent_executor,
get_session_history,
...
)
### Description
I am using FastAPI to serve content and I would like to have one instance of Agent and AgentExecutor objects for the whole server. The reason is if I do these instances for each HTTP request from scratch, it takes a lot of time.
I would like to select available Tools based on header user_roles of actual REST API request, so we could provide different tools for different group of people.
I have checked documentation, discussions and also LangChain chat, but had not found anything. The provided idea of code is "invented" by LangChain chat, but is not working on line
` agent_executor.tools = tools`
giving error:
openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid 'tools': empty array. Expected an array with minimum length 1, but got an empty array instead.", 'type': 'invalid_request_error', 'param': 'tools', 'code': 'empty_array'}}
**Is is possible to append/assign Tools [] dynamically to Agent / AgentExecutor after respective objects had been created ?**
As of now, it seems it's possible only in constructor when creating given objects which slows down HTTP responses significantly as objects have to be created with each HTTP request separately from scratch.
### System Info
System Information
------------------
> OS: Windows
> OS Version: 10.0.22631
> Python Version: 3.11.9 (tags/v3.11.9:de54cf5, Apr 2 2024, 10:12:12) [MSC v.1938 64 bit (AMD64)]
Package Information
-------------------
> langchain_core: 0.2.41
> langchain: 0.2.16
> langchain_community: 0.2.17
> langsmith: 0.1.135
> langchain_cli: 0.0.31
> langchain_cohere: 0.2.4
> langchain_experimental: 0.0.65
> langchain_mistralai: 0.1.13
> langchain_openai: 0.1.25
> langchain_text_splitters: 0.2.4
> langgraph: 0.2.37
> langserve: 0.2.3
Other Dependencies
------------------
> aiohttp: 3.10.5
> async-timeout: Installed. No version info available.
> cohere: 5.11.0
> dataclasses-json: 0.6.7
> fastapi: 0.115.0
> gitpython: 3.1.43
> gritql: 0.1.5
> httpx: 0.27.2
> httpx-sse: 0.4.0
> jsonpatch: 1.33
> langgraph-checkpoint: 2.0.1
> langgraph-sdk: 0.1.33
> langserve[all]: Installed. No version info available.
> numpy: 1.26.4
> openai: 1.51.2
> orjson: 3.10.7
> packaging: 24.1
> pandas: 2.2.2
> pydantic: 1.10.13
> pyproject-toml: 0.0.10
> PyYAML: 6.0.2
> requests: 2.32.3
> requests-toolbelt: 1.0.0
> SQLAlchemy: 2.0.35
> sse-starlette: 1.8.2
> tabulate: 0.9.0
> tenacity: 8.5.0
> tiktoken: 0.7.0
> tokenizers: 0.20.1
> tomlkit: 0.12.5
> typer[all]: Installed. No version info available.
> typing-extensions: 4.12.2
> uvicorn: 0.23.2
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Beta Was this translation helpful? Give feedback.
All reactions