Params required to create the agent. Includes an LLM, tools, and prompt.
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.
import { AgentExecutor, createXmlAgent } from "langchain/agents";
import { pull } from "langchain/hub";
import type { PromptTemplate } from "@langchain/core/prompts";
import { ChatAnthropic } from "@langchain/anthropic";
// Define the tools the agent will have access to.
const tools = [...];
// Get the prompt to use - you can modify this!
const prompt = await pull<PromptTemplate>("hwchase17/xml-agent-convo");
const llm = new ChatAnthropic({
temperature: 0,
});
const agent = await createXmlAgent({
llm,
tools,
prompt,
});
const agentExecutor = new AgentExecutor({
agent,
tools,
});
const result = await agentExecutor.invoke({
input: "what is LangChain?",
});
// With chat history
const result2 = await agentExecutor.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: Hi! My name is Cob\nAI: Hello Cob! Nice to meet you",
});
Generated using TypeDoc
Create an agent that uses XML to format its logic.