Replies: 1 comment 8 replies
-
To set a default tool for your agent executor in LangChain, you can initialize and configure the tool, then integrate it into your
from langchain_community.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
# Initialize the API wrapper
api_wrapper = WikipediaAPIWrapper(top_k_results=1, doc_content_chars_max=100)
# Initialize the tool with the API wrapper
tool = WikipediaQueryRun(api_wrapper=api_wrapper)
# Optionally, customize the tool's name, description, and JSON schema
from langchain_core.pydantic_v1 import BaseModel, Field
class WikiInputs(BaseModel):
"""Inputs to the wikipedia tool."""
query: str = Field(description="query to look up in Wikipedia, should be 3 or less words")
tool = WikipediaQueryRun(
name="wiki-tool",
description="look up things in wikipedia",
args_schema=WikiInputs,
api_wrapper=api_wrapper,
return_direct=True,
)
# Set this tool as the default tool for your agent executor
default_tool = tool
from langchain.agents.agent import AgentExecutor
from langchain.agents.base import BaseSingleActionAgent
# Assuming you have an agent instance
agent = BaseSingleActionAgent()
# Create the AgentExecutor with the default tool
agent_executor = AgentExecutor.from_agent_and_tools(
agent=agent,
tools=[default_tool]
)
# Now, the agent executor will use the default tool if it doesn't know which tool to use This setup ensures that the |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Checked other resources
Commit to Help
Example Code
Description
Hi @dosu, please help me!
I have an agent with 10 available tools, and I need it to execute a specific default tool if it doesn't know which tool to use.
How can I do this?
System Info
Since it is a conceptual question, I did not include any source code.
Beta Was this translation helpful? Give feedback.
All reactions