langchain.js
    Preparing search index...
    • Type Parameters

      • A extends InteropZodObject | AnyAnnotationRoot = AnnotationRoot<
            {
                messages: BinaryOperatorAggregate<
                    BaseMessage<MessageStructure, MessageType>[],
                    Messages,
                >;
            },
        >
      • StructuredResponseFormat extends Record<string, any> = Record<string, any>
      • C extends InteropZodObject | AnyAnnotationRoot = AnyAnnotationRoot

      Returns CompiledStateGraph<
          ToAnnotationRoot<A>["State"],
          ToAnnotationRoot<A>["Update"],
          any,
          {
              messages: BinaryOperatorAggregate<
                  BaseMessage<MessageStructure, MessageType>[],
                  Messages,
              >;
          } & ToAnnotationRoot<A>["spec"],
          {
              messages: BinaryOperatorAggregate<
                  BaseMessage<MessageStructure, MessageType>[],
                  Messages,
              >;
              structuredResponse: {
                  Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<S>;
                  (): LastValue<StructuredResponseFormat>;
                  (
                      annotation: SingleReducer<
                          StructuredResponseFormat,
                          StructuredResponseFormat,
                      >,
                  ): BinaryOperatorAggregate<
                      StructuredResponseFormat,
                      StructuredResponseFormat,
                  >;
              };
          } & ToAnnotationRoot<A>["spec"],
      >

      createReactAgent has been moved to langchain package. Update your import to import { createAgent } from "langchain";

      Creates a StateGraph agent that relies on a chat model utilizing tool calling.

      import { ChatOpenAI } from "@langchain/openai";
      import { tool } from "@langchain/core/tools";
      import { z } from "zod";
      import { createReactAgent } from "@langchain/langgraph/prebuilt";

      const model = new ChatOpenAI({
      model: "gpt-4o",
      });

      const getWeather = tool((input) => {
      if (["sf", "san francisco"].includes(input.location.toLowerCase())) {
      return "It's 60 degrees and foggy.";
      } else {
      return "It's 90 degrees and sunny.";
      }
      }, {
      name: "get_weather",
      description: "Call to get the current weather.",
      schema: z.object({
      location: z.string().describe("Location to get the weather for."),
      })
      })

      const agent = createReactAgent({ llm: model, tools: [getWeather] });

      const inputs = {
      messages: [{ role: "user", content: "what is the weather in SF?" }],
      };

      const stream = await agent.stream(inputs, { streamMode: "values" });

      for await (const { messages } of stream) {
      console.log(messages);
      }
      // Returns the messages in the state at each step of execution