Deploy the application

Note the following limitations for the Reasoning Engine API:

  • The Reasoning Engine API supports deploying only Python code.
  • The Reasoning Engine API is supported in only the us-central1 region.

Before you begin

Before you run this tutorial, make sure you follow:

  1. Set up your environment.
  2. Develop an application.

Create a ReasoningEngine instance

To deploy the application on Vertex AI, use ReasoningEngine.create and pass in the object as a parameter. To introduce package dependencies for the application, use the following parameters:

  • requirements: A list of external PyPI package dependencies. Each line must be a single string. To learn more, see Requirements File Format.
  • extra_packages: A list of internal package dependencies. These package dependencies are local files or directories that correspond to the local Python packages required by the application.

The following code demonstrates how you can deploy an application:

remote_app = reasoning_engines.ReasoningEngine.create(
    reasoning_engines.LangchainAgent(
        model=model,
        tools=[get_exchange_rate],
        model_kwargs=model_kwargs,
    ),
    requirements=[
        "google-cloud-aiplatform[reasoningengine,langchain]",
    ],
    display_name="DISPLAY_NAME",  # Optional.
)
remote_app

Application deployment takes a few minutes to run. It builds containers and turns up HTTP servers on the backend. Deployment latency is dependent on the total time it takes to install the required packages.

Once deployed, remote_app corresponds to an instance of reasoning_engines.LangchainAgent that is running on Vertex AI and can be queried or deleted. It is separate from local instances of reasoning_engines.LangchainAgent.

Each deployed application has a unique identifier. Run the following command to get the resource_name identifier for your application:

remote_app.resource_name

resource_name has the following format: "projects/PROJECT_ID/locations/LOCATION/reasoningEngines/RESOURCE_ID".

Best Practices

  1. Pin your package versions (for reproducible builds). Common packages to keep track of include: google-cloud-aiplatform, cloudpickle, langchain, langchain-core, langchain-google-vertexai, and pydantic.
  2. Minimize the number of dependencies in your application. This reduces the number of breaking changes when updating your dependencies and makes it easier to update your application over time for newer features.

What's next