forked from Archives/langchain
[agent][property type] Change allowed_tools to Set as Duplicate doesn’t make sense (#3840)
- ActionAgent has a property called, `allowed_tools`, which is declared as `List`. It stores all provided tools which is available to use during agent action. - This collection shouldn’t allow duplicates. The original datatype List doesn’t make sense. Each tool should be unique. Even when there are variants (assuming in the future), it would be named differently in load_tools. Test: - confirm the functionality in an example by initializing an agent with a list of 2 tools and confirm everything works. ```python3 def test_agent_chain_chat_bot(): from langchain.agents import load_tools from langchain.agents import initialize_agent from langchain.agents import AgentType from langchain.chat_models import ChatOpenAI from langchain.llms import OpenAI from langchain.utilities.duckduckgo_search import DuckDuckGoSearchAPIWrapper chat = ChatOpenAI(temperature=0) llm = OpenAI(temperature=0) tools = load_tools(["ddg-search", "llm-math"], llm=llm) agent = initialize_agent(tools, chat, agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True) agent.run("Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?") test_agent_chain_chat_bot() ``` Result: <img width="863" alt="Screenshot 2023-05-01 at 7 58 11 PM" src="https://user-images.githubusercontent.com/62768671/235572157-0937594c-ddfb-4760-acb2-aea4cacacd89.png">fix_agent_callbacks
parent
c5cc09d4e3
commit
ec21b7126c
@ -0,0 +1 @@
|
||||
"""All integration tests for agent."""
|
@ -0,0 +1,16 @@
|
||||
from langchain.agents.chat.base import ChatAgent
|
||||
from langchain.llms.openai import OpenAI
|
||||
from langchain.tools.ddg_search.tool import DuckDuckGoSearchRun
|
||||
|
||||
|
||||
class TestAgent:
|
||||
def test_agent_generation(self) -> None:
|
||||
web_search = DuckDuckGoSearchRun()
|
||||
tools = [web_search]
|
||||
agent = ChatAgent.from_llm_and_tools(
|
||||
ai_name="Tom",
|
||||
ai_role="Assistant",
|
||||
tools=tools,
|
||||
llm=OpenAI(maxTokens=10),
|
||||
)
|
||||
assert agent.allowed_tools == set([web_search.name])
|
Loading…
Reference in New Issue