Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookPrompt + LLMRAGMultiple chainsQuerying a SQL DBAgentsCode writingAdding memoryAdding moderationUsing toolsLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreLangChain Expression LanguageCookbookAgentsAgentsYou can pass a Runnable into an agent.from langchain.agents import XMLAgent, tool, AgentExecutorfrom langchain.chat_models import ChatAnthropicmodel = ChatAnthropic(model="claude-2")@tooldef search(query: str) -> str:    """Search things about current events."""    return "32 degrees"tool_list = [search]# Get prompt to useprompt = XMLAgent.get_default_prompt()# Logic for going from intermediate steps to a string to pass into model# This is pretty tied to the promptdef convert_intermediate_steps(intermediate_steps):    log = ""    for action, observation in intermediate_steps:        log += (            f"<tool>{action.tool}</tool><tool_input>{action.tool_input}"            f"</tool_input><observation>{observation}</observation>"        )    return log# Logic for converting tools to string to go in promptdef convert_tools(tools):    return "\n".join([f"{tool.name}: {tool.description}" for tool in tools])Building an agent from a runnable usually involves a few things:Data processing for the intermediate steps. These need to represented in a way that the language model can recognize them. This should be pretty tightly coupled to the instructions in the promptThe prompt itselfThe model, complete with stop tokens if neededThe output parser - should be in sync with how the prompt specifies things to be formatted.agent = (    {        "question": lambda x: x["question"],        "intermediate_steps": lambda x: convert_intermediate_steps(x["intermediate_steps"])    }    |
You can pass a Runnable into an agent.
You can pass a Runnable into an agent. ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookPrompt + LLMRAGMultiple chainsQuerying a SQL DBAgentsCode writingAdding memoryAdding moderationUsing toolsLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsCallbacksModulesSecurityGuidesMoreLangChain Expression LanguageCookbookAgentsAgentsYou can pass a Runnable into an agent.from langchain.agents import XMLAgent, tool, AgentExecutorfrom langchain.chat_models import ChatAnthropicmodel = ChatAnthropic(model="claude-2")@tooldef search(query: str) -> str:    """Search things about current events."""    return "32 degrees"tool_list = [search]# Get prompt to useprompt = XMLAgent.get_default_prompt()# Logic for going from intermediate steps to a string to pass into model# This is pretty tied to the promptdef convert_intermediate_steps(intermediate_steps):    log = ""    for action, observation in intermediate_steps:        log += (            f"<tool>{action.tool}</tool><tool_input>{action.tool_input}"            f"</tool_input><observation>{observation}</observation>"        )    return log# Logic for converting tools to string to go in promptdef convert_tools(tools):    return "\n".join([f"{tool.name}: {tool.description}" for tool in tools])Building an agent from a runnable usually involves a few things:Data processing for the intermediate steps. These need to represented in a way that the language model can recognize them. This should be pretty tightly coupled to the instructions in the promptThe prompt itselfThe model, complete with stop tokens if neededThe output parser - should be in sync with how the prompt specifies things to be formatted.agent = (    {        "question": lambda x: x["question"],        "intermediate_steps": lambda x: convert_intermediate_steps(x["intermediate_steps"])    }    |