Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsAgent TypesConversationalOpenAI functionsOpenAI Multi Functions AgentReActReAct document storeSelf-ask with searchStructured tool chatXML AgentHow-toToolsToolkitsCallbacksModulesSecurityGuidesMoreModulesAgentsAgent TypesXML AgentOn this pageXML AgentSome language models (like Anthropic's Claude) are particularly good at reasoning/writing XML. This goes over how to use an agent that uses XML when prompting. Initialize the tools‚ÄãWe will initialize some fake tools for demo purposesfrom langchain.agents import tool@tooldef search(query: str) -> str:    """Search things about current events."""    return "32 degrees"tools = [search]from langchain.chat_models import ChatAnthropicmodel = ChatAnthropic(model="claude-2")Use LangChain Expression Language‚ÄãWe will first show how to create this agent using LangChain Expression Languagefrom langchain.tools.render import render_text_descriptionfrom langchain.agents.output_parsers import XMLAgentOutputParserfrom langchain.agents.format_scratchpad import format_xmlfrom langchain import hubprompt = hub.pull("hwchase17/xml-agent")prompt = prompt.partial(    tools=render_text_description(tools),    tool_names=", ".join([t.name for t in tools]),)llm_with_stop = model.bind(stop=["</tool_input>"])agent = {    "question": lambda x: x["question"],    "agent_scratchpad": lambda x: format_xml(x['intermediate_steps']),} | prompt | llm_with_stop | XMLAgentOutputParser()from langchain.agents import AgentExecutoragent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)agent_executor.invoke({"question": "whats the weather in New york?"})            > Entering new AgentExecutor chain...     <tool>search</tool>
Some language models (like Anthropic's Claude) are particularly good at reasoning/writing XML. This goes over how to use an agent that uses XML when prompting.
Some language models (like Anthropic's Claude) are particularly good at reasoning/writing XML. This goes over how to use an agent that uses XML when prompting. ->: Skip to main contentü¶úÔ∏èüîó LangChainDocsUse casesIntegrationsAPICommunityChat our docsLangSmithJS/TS DocsSearchCTRLKGet startedIntroductionInstallationQuickstartLangChain Expression LanguageInterfaceHow toCookbookLangChain Expression Language (LCEL)Why use LCEL?ModulesModel I/‚ÄãORetrievalChainsMemoryAgentsAgent TypesConversationalOpenAI functionsOpenAI Multi Functions AgentReActReAct document storeSelf-ask with searchStructured tool chatXML AgentHow-toToolsToolkitsCallbacksModulesSecurityGuidesMoreModulesAgentsAgent TypesXML AgentOn this pageXML AgentSome language models (like Anthropic's Claude) are particularly good at reasoning/writing XML. This goes over how to use an agent that uses XML when prompting. Initialize the tools‚ÄãWe will initialize some fake tools for demo purposesfrom langchain.agents import tool@tooldef search(query: str) -> str:    """Search things about current events."""    return "32 degrees"tools = [search]from langchain.chat_models import ChatAnthropicmodel = ChatAnthropic(model="claude-2")Use LangChain Expression Language‚ÄãWe will first show how to create this agent using LangChain Expression Languagefrom langchain.tools.render import render_text_descriptionfrom langchain.agents.output_parsers import XMLAgentOutputParserfrom langchain.agents.format_scratchpad import format_xmlfrom langchain import hubprompt = hub.pull("hwchase17/xml-agent")prompt = prompt.partial(    tools=render_text_description(tools),    tool_names=", ".join([t.name for t in tools]),)llm_with_stop = model.bind(stop=["</tool_input>"])agent = {    "question": lambda x: x["question"],    "agent_scratchpad": lambda x: format_xml(x['intermediate_steps']),} | prompt | llm_with_stop | XMLAgentOutputParser()from langchain.agents import AgentExecutoragent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)agent_executor.invoke({"question": "whats the weather in New york?"})            > Entering new AgentExecutor chain...     <tool>search</tool>