langchain.agents.xml.base.create_xml_agent

langchain.agents.xml.base.create_xml_agent(llm: BaseLanguageModel, tools: Sequence[BaseTool], prompt: BasePromptTemplate) Runnable[source]

Create an agent that uses XML to format its logic.

Examples:

from langchain import hub
from langchain_community.chat_models import ChatAnthropic
from langchain.agents import AgentExecutor, create_xml_agent

prompt = hub.pull("hwchase17/xml-agent-convo")
model = ChatAnthropic()
tools = ...

agent = create_xml_agent(model, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)

agent_executor.invoke({"input": "hi"})

# Use with chat history
from langchain_core.messages import AIMessage, HumanMessage
agent_executor.invoke(
    {
        "input": "what's my name?",
        # Notice that chat_history is a string
        # since this prompt is aimed at LLMs, not chat models
        "chat_history": "Human: My name is Bob
AI: Hello Bob!”,

}

)

Args:

llm: LLM to use as the agent. tools: Tools this agent has access to. prompt: The prompt to use, must have input keys of

tools and agent_scratchpad.

Returns:

A runnable sequence representing an agent. It takes as input all the same input variables as the prompt passed in does. It returns as output either an AgentAction or AgentFinish.