LangGraph.js API Reference
    Preparing search index...
    • Creates and configures a Computer Use Agent.

      Type Parameters

      • StateModifier extends AnnotationRoot<any> = AnnotationRoot<
            {
                authenticatedId: BinaryOperatorAggregate<
                    undefined
                    | string,
                    undefined | string,
                >;
                instanceId: BinaryOperatorAggregate<
                    undefined
                    | string,
                    undefined | string,
                >;
                messages: BinaryOperatorAggregate<
                    BaseMessage<MessageStructure, MessageType>[],
                    Messages,
                >;
                streamUrl: BinaryOperatorAggregate<undefined | string, undefined | string>;
            },
        >

      Parameters

      • params: {
            authStateId?: string;
            environment?: "web" | "ubuntu" | "windows";
            nodeAfterAction?: (
                state: StateType<
                    {
                        authenticatedId: BinaryOperatorAggregate<
                            undefined
                            | string,
                            undefined | string,
                        >;
                        instanceId: BinaryOperatorAggregate<
                            undefined
                            | string,
                            undefined | string,
                        >;
                        messages: BinaryOperatorAggregate<
                            BaseMessage<MessageStructure, MessageType>[],
                            Messages,
                        >;
                        streamUrl: BinaryOperatorAggregate<
                            undefined
                            | string,
                            undefined | string,
                        >;
                    },
                > & StateModifier["State"],
                config: LangGraphRunnableConfig<
                    StateType<
                        {
                            authStateId: BinaryOperatorAggregate<
                                undefined
                                | string,
                                undefined | string,
                            >;
                            blockedDomains: BinaryOperatorAggregate<string[], string[]>;
                            environment: BinaryOperatorAggregate<CUAEnvironment, CUAEnvironment>;
                            prompt: BinaryOperatorAggregate<
                                undefined
                                | string
                                | SystemMessage<MessageStructure>,
                                undefined | string | SystemMessage<MessageStructure>,
                            >;
                            scrapybaraApiKey: BinaryOperatorAggregate<
                                undefined
                                | string,
                                undefined | string,
                            >;
                            timeoutHours: BinaryOperatorAggregate<number, number>;
                            zdrEnabled: BinaryOperatorAggregate<boolean, boolean>;
                        },
                    >,
                >,
            ) => Promise<
                UpdateType<
                    {
                        authenticatedId: BinaryOperatorAggregate<
                            undefined
                            | string,
                            undefined | string,
                        >;
                        instanceId: BinaryOperatorAggregate<
                            undefined
                            | string,
                            undefined | string,
                        >;
                        messages: BinaryOperatorAggregate<
                            BaseMessage<MessageStructure, MessageType>[],
                            Messages,
                        >;
                        streamUrl: BinaryOperatorAggregate<
                            undefined
                            | string,
                            undefined | string,
                        >;
                    },
                > & StateModifier["Update"],
            >;
            nodeBeforeAction?: (
                state: StateType<
                    {
                        authenticatedId: BinaryOperatorAggregate<
                            undefined
                            | string,
                            undefined | string,
                        >;
                        instanceId: BinaryOperatorAggregate<
                            undefined
                            | string,
                            undefined | string,
                        >;
                        messages: BinaryOperatorAggregate<
                            BaseMessage<MessageStructure, MessageType>[],
                            Messages,
                        >;
                        streamUrl: BinaryOperatorAggregate<
                            undefined
                            | string,
                            undefined | string,
                        >;
                    },
                > & StateModifier["State"],
                config: LangGraphRunnableConfig<
                    StateType<
                        {
                            authStateId: BinaryOperatorAggregate<
                                undefined
                                | string,
                                undefined | string,
                            >;
                            blockedDomains: BinaryOperatorAggregate<string[], string[]>;
                            environment: BinaryOperatorAggregate<CUAEnvironment, CUAEnvironment>;
                            prompt: BinaryOperatorAggregate<
                                undefined
                                | string
                                | SystemMessage<MessageStructure>,
                                undefined | string | SystemMessage<MessageStructure>,
                            >;
                            scrapybaraApiKey: BinaryOperatorAggregate<
                                undefined
                                | string,
                                undefined | string,
                            >;
                            timeoutHours: BinaryOperatorAggregate<number, number>;
                            zdrEnabled: BinaryOperatorAggregate<boolean, boolean>;
                        },
                    >,
                >,
            ) => Promise<
                UpdateType<
                    {
                        authenticatedId: BinaryOperatorAggregate<
                            undefined
                            | string,
                            undefined | string,
                        >;
                        instanceId: BinaryOperatorAggregate<
                            undefined
                            | string,
                            undefined | string,
                        >;
                        messages: BinaryOperatorAggregate<
                            BaseMessage<MessageStructure, MessageType>[],
                            Messages,
                        >;
                        streamUrl: BinaryOperatorAggregate<
                            undefined
                            | string,
                            undefined | string,
                        >;
                    },
                > & StateModifier["Update"],
            >;
            prompt?: string
            | SystemMessage<MessageStructure>;
            recursionLimit?: number;
            scrapybaraApiKey?: string;
            stateModifier?: StateModifier;
            timeoutHours?: number;
            uploadScreenshot?: (screenshot: string) => Promise<string>;
            zdrEnabled?: boolean;
        } = {}

        The parameters for the Computer Use Agent.

        • OptionalauthStateId?: string

          The ID of the authentication state. If defined, it will be used to authenticate with Scrapybara. Only applies if 'environment' is set to 'web'.

          undefined
          
        • Optionalenvironment?: "web" | "ubuntu" | "windows"

          The environment to use.

          "web"
          
        • OptionalnodeAfterAction?: (
              state: StateType<
                  {
                      authenticatedId: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                      instanceId: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                      messages: BinaryOperatorAggregate<
                          BaseMessage<MessageStructure, MessageType>[],
                          Messages,
                      >;
                      streamUrl: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                  },
              > & StateModifier["State"],
              config: LangGraphRunnableConfig<
                  StateType<
                      {
                          authStateId: BinaryOperatorAggregate<
                              undefined
                              | string,
                              undefined | string,
                          >;
                          blockedDomains: BinaryOperatorAggregate<string[], string[]>;
                          environment: BinaryOperatorAggregate<CUAEnvironment, CUAEnvironment>;
                          prompt: BinaryOperatorAggregate<
                              undefined
                              | string
                              | SystemMessage<MessageStructure>,
                              undefined | string | SystemMessage<MessageStructure>,
                          >;
                          scrapybaraApiKey: BinaryOperatorAggregate<
                              undefined
                              | string,
                              undefined | string,
                          >;
                          timeoutHours: BinaryOperatorAggregate<number, number>;
                          zdrEnabled: BinaryOperatorAggregate<boolean, boolean>;
                      },
                  >,
              >,
          ) => Promise<
              UpdateType<
                  {
                      authenticatedId: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                      instanceId: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                      messages: BinaryOperatorAggregate<
                          BaseMessage<MessageStructure, MessageType>[],
                          Messages,
                      >;
                      streamUrl: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                  },
              > & StateModifier["Update"],
          >

          A custom node to run after the computer action.

          undefined
          
        • OptionalnodeBeforeAction?: (
              state: StateType<
                  {
                      authenticatedId: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                      instanceId: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                      messages: BinaryOperatorAggregate<
                          BaseMessage<MessageStructure, MessageType>[],
                          Messages,
                      >;
                      streamUrl: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                  },
              > & StateModifier["State"],
              config: LangGraphRunnableConfig<
                  StateType<
                      {
                          authStateId: BinaryOperatorAggregate<
                              undefined
                              | string,
                              undefined | string,
                          >;
                          blockedDomains: BinaryOperatorAggregate<string[], string[]>;
                          environment: BinaryOperatorAggregate<CUAEnvironment, CUAEnvironment>;
                          prompt: BinaryOperatorAggregate<
                              undefined
                              | string
                              | SystemMessage<MessageStructure>,
                              undefined | string | SystemMessage<MessageStructure>,
                          >;
                          scrapybaraApiKey: BinaryOperatorAggregate<
                              undefined
                              | string,
                              undefined | string,
                          >;
                          timeoutHours: BinaryOperatorAggregate<number, number>;
                          zdrEnabled: BinaryOperatorAggregate<boolean, boolean>;
                      },
                  >,
              >,
          ) => Promise<
              UpdateType<
                  {
                      authenticatedId: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                      instanceId: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                      messages: BinaryOperatorAggregate<
                          BaseMessage<MessageStructure, MessageType>[],
                          Messages,
                      >;
                      streamUrl: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                  },
              > & StateModifier["Update"],
          >

          A custom node to run before the computer action.

          undefined
          
        • Optionalprompt?: string | SystemMessage<MessageStructure>

          The prompt to use for the model. This will be used as the system prompt for the model.

          undefined
          
        • OptionalrecursionLimit?: number

          The maximum number of recursive calls the agent can make.

          100
          
        • OptionalscrapybaraApiKey?: string

          The API key to use for Scrapybara. This can be provided in the configuration, or set as an environment variable (SCRAPYBARA_API_KEY).

          process.env.SCRAPYBARA_API_KEY
          
        • OptionalstateModifier?: StateModifier

          Optional state modifier for customizing the agent's state.

          undefined
          
        • OptionaltimeoutHours?: number

          The number of hours to keep the virtual machine running before it times out. Must be between 0.01 and 24.

          1
          
        • OptionaluploadScreenshot?: (screenshot: string) => Promise<string>

          A custom function to handle uploading screenshots to an external store, instead of saving them as base64 in state. Must accept a base64 string and return a URL.

          undefined
          
        • OptionalzdrEnabled?: boolean

          Whether or not Zero Data Retention is enabled in the user's OpenAI account. If true, the agent will not pass the 'previous_response_id' to the model, and will always pass it the full message history for each request. If false, the agent will pass the 'previous_response_id' to the model, and only the latest message in the history will be passed.

          false
          

      Returns CompiledStateGraph<
          { [key: string]: any },
          { [key: string]: any } | { [key: string]: any },

              | "__start__"
              | "callModel"
              | "createVMInstance"
              | "nodeBeforeAction"
              | "nodeAfterAction"
              | "takeComputerAction",
          any,
          any,
          {
              authStateId: BinaryOperatorAggregate<
                  undefined
                  | string,
                  undefined | string,
              >;
              blockedDomains: BinaryOperatorAggregate<string[], string[]>;
              environment: BinaryOperatorAggregate<CUAEnvironment, CUAEnvironment>;
              prompt: BinaryOperatorAggregate<
                  undefined
                  | string
                  | SystemMessage<MessageStructure>,
                  undefined | string | SystemMessage<MessageStructure>,
              >;
              scrapybaraApiKey: BinaryOperatorAggregate<
                  undefined
                  | string,
                  undefined | string,
              >;
              timeoutHours: BinaryOperatorAggregate<number, number>;
              zdrEnabled: BinaryOperatorAggregate<boolean, boolean>;
          },
          {
              callModel: {
                  messages: AIMessageChunk<MessageStructure> & {
                      additional_kwargs: {
                          tool_outputs?: {
                              action: {
                                  display_height: number;
                                  display_width: number;
                                  type: string;
                              };
                              call_id: string;
                          }[];
                      };
                  };
              };
              createVMInstance: | { instanceId?: undefined; streamUrl?: undefined }
              | { instanceId: string; streamUrl: string }
              | { instanceId: string; streamUrl?: undefined };
              nodeAfterAction: UpdateType<
                  {
                      authenticatedId: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                      instanceId: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                      messages: BinaryOperatorAggregate<
                          BaseMessage<MessageStructure, MessageType>[],
                          Messages,
                      >;
                      streamUrl: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                  },
              >;
              nodeBeforeAction: UpdateType<
                  {
                      authenticatedId: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                      instanceId: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                      messages: BinaryOperatorAggregate<
                          BaseMessage<MessageStructure, MessageType>[],
                          Messages,
                      >;
                      streamUrl: BinaryOperatorAggregate<
                          undefined
                          | string,
                          undefined | string,
                      >;
                  },
              >;
              takeComputerAction: {
                  authenticatedId: undefined
                  | string;
                  instanceId: string;
                  messages: ToolMessage<MessageStructure>[];
                  streamUrl: string;
              };
          },
          unknown,
          unknown,
      >

      The configured graph.