Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsAgent TypesHow-toToolsDefining Custom ToolsHuman-in-the-loop Tool ValidationMulti-Input ToolsTool Input SchemaTools as OpenAI FunctionsToolkitsCallbacksModulesSecurityGuidesMoreModulesAgentsToolsDefining Custom ToolsOn this pageDefining Custom ToolsWhen constructing your own agent, you will need to provide it with a list of Tools that it can use. Besides the actual function that is called, the Tool consists of several components:name (str), is required and must be unique within a set of tools provided to an agentdescription (str), is optional but recommended, as it is used by an agent to determine tool usereturn_direct (bool), defaults to Falseargs_schema (Pydantic BaseModel), is optional but recommended, can be used to provide more information (e.g., few-shot examples) or validation for expected parameters.There are two main ways to define a tool, we will cover both in the example below.# Import things that are needed genericallyfrom langchain.chains import LLMMathChainfrom langchain.utilities import SerpAPIWrapperfrom langchain.agents import AgentType, initialize_agentfrom langchain.chat_models import ChatOpenAIfrom langchain.tools import BaseTool, StructuredTool, Tool, toolInitialize the LLM to use for the agent.llm = ChatOpenAI(temperature=0)Completely New Tools - String Input and Output‚ÄãThe simplest tools accept a single query string and return a string output. If your tool function requires multiple arguments, you might want to skip down to the StructuredTool section below.There are two ways to do this: either by using the Tool dataclass, or by subclassing the BaseTool class.Tool dataclass‚ÄãThe 'Tool' dataclass wraps functions that accept a single
When constructing your own agent, you will need to provide it with a list of Tools that it can use. Besides the actual function that is called, the Tool consists of several components:
When constructing your own agent, you will need to provide it with a list of Tools that it can use. Besides the actual function that is called, the Tool consists of several components: ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsAgent TypesHow-toToolsDefining Custom ToolsHuman-in-the-loop Tool ValidationMulti-Input ToolsTool Input SchemaTools as OpenAI FunctionsToolkitsCallbacksModulesSecurityGuidesMoreModulesAgentsToolsDefining Custom ToolsOn this pageDefining Custom ToolsWhen constructing your own agent, you will need to provide it with a list of Tools that it can use. Besides the actual function that is called, the Tool consists of several components:name (str), is required and must be unique within a set of tools provided to an agentdescription (str), is optional but recommended, as it is used by an agent to determine tool usereturn_direct (bool), defaults to Falseargs_schema (Pydantic BaseModel), is optional but recommended, can be used to provide more information (e.g., few-shot examples) or validation for expected parameters.There are two main ways to define a tool, we will cover both in the example below.# Import things that are needed genericallyfrom langchain.chains import LLMMathChainfrom langchain.utilities import SerpAPIWrapperfrom langchain.agents import AgentType, initialize_agentfrom langchain.chat_models import ChatOpenAIfrom langchain.tools import BaseTool, StructuredTool, Tool, toolInitialize the LLM to use for the agent.llm = ChatOpenAI(temperature=0)Completely New Tools - String Input and Output‚ÄãThe simplest tools accept a single query string and return a string output. If your tool function requires multiple arguments, you might want to skip down to the StructuredTool section below.There are two ways to do this: either by using the Tool dataclass, or by subclassing the BaseTool class.Tool dataclass‚ÄãThe 'Tool' dataclass wraps functions that accept a single