• Create an agent that uses tools.

    Parameters

    Returns AgentRunnableSequence<any, any>

    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 { ChatAnthropic } from "@langchain/anthropic";
    import { ChatPromptTemplate, MessagesPlaceholder } from "@langchain/core/prompts";
    import { AgentExecutor, createToolCallingAgent } from "langchain/agents";

    const prompt = ChatPromptTemplate.fromMessages(
    [
    ["system", "You are a helpful assistant"],
    ["placeholder", "{chat_history}"],
    ["human", "{input}"],
    ["placeholder", "{agent_scratchpad}"],
    ]
    );


    const llm = new ChatAnthropic({
    modelName: "claude-3-opus-20240229",
    temperature: 0,
    });

    // Define the tools the agent will have access to.
    const tools = [...];

    const agent = createToolCallingAgent({ llm, tools, prompt });

    const agentExecutor = new AgentExecutor({ agent, tools });

    const result = await agentExecutor.invoke({input: "what is LangChain?"});

    // Using with chat history
    import { AIMessage, HumanMessage } from "@langchain/core/messages";

    const result2 = await agentExecutor.invoke(
    {
    input: "what's my name?",
    chat_history: [
    new HumanMessage({content: "hi! my name is bob"}),
    new AIMessage({content: "Hello Bob! How can I assist you today?"}),
    ],
    }
    );
""