Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsAgent TypesHow-toAdd Memory to OpenAI Functions AgentRunning Agent as an IteratorReturning Structured OutputCombine agents and vector storesAsync APICreate ChatGPT cloneCustom functions with OpenAI Functions AgentCustom agentCustom agent with tool retrievalCustom LLM agentCustom LLM Agent (with a ChatModel)Custom MRKL agentCustom multi-action agentHandle parsing errorsAccess intermediate stepsCap the max number of iterationsTimeouts for agentsReplicating MRKLShared memory across agents and toolsStreaming final agent outputUse ToolKits with OpenAI FunctionsToolsToolkitsCallbacksModulesSecurityGuidesMoreModulesAgentsHow-toRunning Agent as an IteratorRunning Agent as an IteratorTo demonstrate the AgentExecutorIterator functionality, we will set up a problem where an Agent must:Retrieve three prime numbers from a ToolMultiply these together. In this simple problem we can demonstrate adding some logic to verify intermediate steps by checking whether their outputs are prime.import osimport dotenvimport pydanticfrom langchain.agents import AgentExecutor, initialize_agent, AgentTypefrom langchain.schema import AgentFinishfrom langchain.agents.tools import Toolfrom langchain.chains import LLMMathChainfrom langchain.chat_models import ChatOpenAI# Uncomment if you have a .env in root of repo contains OPENAI_API_KEY# dotenv.load_dotenv("../../../../../.env")# need to use GPT-4 here as GPT-3.5 does not understand, however hard you insist, that# it should use the calculator to perform the final calculationllm = ChatOpenAI(temperature=0, model="gpt-4")llm_math_chain = LLMMathChain.from_llm(llm=llm, verbose=True)Define tools which provide:The nth prime number (using a small
To demonstrate the AgentExecutorIterator functionality, we will set up a problem where an Agent must:
To demonstrate the AgentExecutorIterator functionality, we will set up a problem where an Agent must: ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsAgent TypesHow-toAdd Memory to OpenAI Functions AgentRunning Agent as an IteratorReturning Structured OutputCombine agents and vector storesAsync APICreate ChatGPT cloneCustom functions with OpenAI Functions AgentCustom agentCustom agent with tool retrievalCustom LLM agentCustom LLM Agent (with a ChatModel)Custom MRKL agentCustom multi-action agentHandle parsing errorsAccess intermediate stepsCap the max number of iterationsTimeouts for agentsReplicating MRKLShared memory across agents and toolsStreaming final agent outputUse ToolKits with OpenAI FunctionsToolsToolkitsCallbacksModulesSecurityGuidesMoreModulesAgentsHow-toRunning Agent as an IteratorRunning Agent as an IteratorTo demonstrate the AgentExecutorIterator functionality, we will set up a problem where an Agent must:Retrieve three prime numbers from a ToolMultiply these together. In this simple problem we can demonstrate adding some logic to verify intermediate steps by checking whether their outputs are prime.import osimport dotenvimport pydanticfrom langchain.agents import AgentExecutor, initialize_agent, AgentTypefrom langchain.schema import AgentFinishfrom langchain.agents.tools import Toolfrom langchain.chains import LLMMathChainfrom langchain.chat_models import ChatOpenAI# Uncomment if you have a .env in root of repo contains OPENAI_API_KEY# dotenv.load_dotenv("../../../../../.env")# need to use GPT-4 here as GPT-3.5 does not understand, however hard you insist, that# it should use the calculator to perform the final calculationllm = ChatOpenAI(temperature=0, model="gpt-4")llm_math_chain = LLMMathChain.from_llm(llm=llm, verbose=True)Define tools which provide:The nth prime number (using a small