← Technology, Science & Infrastructure ▣ Distilled locally

Build, Deploy, and Govern Your Agents with MongoDB Atlas Agent Engine

MongoDB Blog
November 16, 2026  ·  MongoDB Blog ↗
Build, Deploy, and Govern Your Agents with MongoDB Atlas Agent Engine

Big Model vs. Big Harness has been an ongoing debate in AI engineering. An agent harness is everything besides the LLM that makes an agent work, including the runtime, tools, context, and guardrails surrounding the model. As models improve, the parts of the harness that coax better reasoning out of the model, such as prompts and loops, will likely get absorbed into the model, while the control layers won't. Persistent memory, identity and least-privilege access, isolated execution, governance policies, and audit trails exist to persist, constrain, and record the model's work, so they have to live outside it.

MongoDB recently announced the Atlas Agent Engine, now in public preview, which provides this control layer as a managed service. Agent Engine gives your agents an identity, a managed runtime, long-term memory, auditability, and guardrails. It's also neutral across models, frameworks, and data sources: you can bring a LangGraph agent over with a handful of code changes, and it can keep accessing data where it already lives, without moving it to MongoDB.

In this tutorial, you'll see how to migrate a LangGraph agent to Atlas Agent Engine. Specifically, we will cover the following:

Migrating a LangGraph Agent to Atlas Agent Engine

In this tutorial, we'll walk through how we migrated a travel agent built with LangGraph to Agent Engine. This includes the changes we made to the agent's code and the configuration files we added to get it ready for Agent Engine. You'll make similar changes to migrate your own agents.

The migrated agent is available as a ready-to-deploy template in our Agent Engine examples repository on GitHub.

About the agent

The travel agent we built helps users find flights and accommodations and books them on their behalf once they approve. The flight data and Airbnb listings are stored in MongoDB, and the agent uses a combination of custom tools and tools from the MongoDB Atlas Managed MCP Server to query the data and make bookings:

MCP tools

Custom tools

Architecture

On Agent Engine, the system looks like this:

In Agent Engine, the agent gets its own runtime environment, called a workspace, within a project. Its code runs in two sandboxes: the agent sandbox runs the agent's graph, and the tool sandbox runs the agent's tools and LLM calls, including calls to the MongoDB Atlas Managed MCP Server. Agent Engine also comes with a memory service, lets you set governance policies and guardrails, and traces and monitors every tool and LLM call. The agent's memory, state, and application data all live in MongoDB Atlas.

The project and workspace structure also applies to how you organize your code: a project directory with one workspace directory per agent you want to deploy to the project. We will use the following terminology throughout the tutorial:

We migrated a single agent, so the template's project directory in the GitHub repo has one workspace directory (agents/trip-planner), which holds the agent's code and configuration files. To run more agents in the same project, add a workspace directory for each one under agents/. Here's the template's layout:

Step 1: Prerequisites

Whether you’re deploying our template or your own agent to Agent Engine, complete the following tasks before you begin:

If you’re deploying the template or an agent that accesses the MongoDB Atlas Managed MCP Server, you’ll also need to create an Atlas Managed MCP configuration with the Project Data Access Read Only role, and copy its client ID and secret.

Step 2: Migrate the agent code

To migrate the travel agent to Agent Engine, we first made a few changes to its code. You'll make similar changes if you’re migrating your own agent.

Step 2.1: Wrap the agent with the App class

To connect the agent to Agent Engine, we created an instance of the App class from agent_engine_sdk_langgraph, which is the LangGraph adapter for the Agent Engine SDK. This is used to register the agent’s tools and graph, and to route LLM and tool calls through Agent Engine so they can be traced and governed.

Step 2.2: Wrap the LLM with app.llm()

Next, we wrapped the LLM instance in app.llm() to route all LLM calls through Agent Engine’s audited execution path.

Step 2.3: Register and load tools with app

In LangGraph, you use the @tool decorator to automatically generate tool definitions for any tools that you write for your agents. In the Agent Engine SDK, you use the @app.tool() decorator, which generates the same definitions and also registers the tools with Agent Engine, so tool calls run through it and can be traced and governed. For our travel agent, we did this for the two custom tools, list_bookings and create_booking.

Then, instead of passing the list of tools to the LLM and the graph, we got them from app. app.get_tools() returns the tools for the graph, and app.get_tool_schemas() returns them for binding to the LLM:

Both methods also return the tools from any remote MCP servers configured in the agent.yaml (see Step 4). That's how the travel agent gets the tools from the MongoDB Atlas Managed MCP Server without any tool code.

Step 2.4: Replace the LangGraph checkpointer with the Agent Engine’s checkpointer

The original agent persisted its state and short-term memory in MongoDB using the MongoDBSaver checkpointer integration. To let Agent Engine manage this instead, we replaced the MongoDBSaver checkpointer with app.checkpointer().

Step 2.5: Mark the app’s entrypoint

We added the @app.entrypoint decorator to the function (build_agent()) that builds the agent’s graph. Agent Engine calls this function to build the graph that handles each request.

Step 2.6: Start the agent's runtime with app.run()

The last change was to call app.run(), which starts the runtime server that handles requests to the agent:

Step 3: Update the pyproject.toml

With the code changes done, we have the agent ready to run on Agent Engine. Agent Engine installs agents as Python packages using uv. It reads the package's name, dependencies, and build settings from pyproject.toml in the agent’s workspace directory.

Here’s the travel agent template’s pyproject.toml, truncated to show what Agent Engine requires:

In the above pyproject.toml snippet:

Step 4: Create an agent.yaml file

Next, we created an agent.yaml file in the agent's workspace directory that configures how Agent Engine discovers and runs the agent. It specifies the agent’s entry point, sandbox configurations, network policies, and so on. See our documentation for the full list of configuration options.

In our agent.yaml, we configured the following:

Step 5: Enable long-term memory

In Step 2.4, app.checkpointer() enabled state persistence and short-term memory for the agent. Next, we added long-term memory, so the agent remembers facts about users and their preferences, such as a budget or a nonstop-only rule for flights, across conversations. This took three steps:

Step 5.1: Enable memory in agent.yaml

Agent Engine comes with a memory service, so we only had to enable and configure it. To enable long-term memory for the agent, we set features.memory to true in agent.yaml:

Step 5.2: Configure memory extraction in project-config.yaml

Next, we created a project-config.yaml file in the project directory. It configures how Agent Engine extracts and stores long-term memories: which LLM to use for memory extraction, what memory types to extract, and which Voyage AI embedding model to use to embed memories for semantic retrieval. Here’s the travel agent’s project-config.yaml:

We chose Voyage AI's voyage-4-large model to generate the embeddings for semantic search, and gpt-5.4-mini to extract memories from conversations, and turned on three types of memories for the agent:

The api_key_secret is the name of the secret that contains the OpenAI API key (LLM_API_KEY). Memory also needs a Voyage API key stored in the VOYAGE_API_KEY secret. You'll set both secrets when you deploy the agent in Step 6.

To learn more about the Memory feature of Agent Engine, see our documentation.

Step 5.3: Add memory recall in the agent code

Finally, we added a memory retrieval step to the agent code, and passed the retrieved memories to the LLM as additional context.

The above code uses the build_context() method of app.memory, the app's memory client, to retrieve the current user's memories that are most relevant to their latest query. The max_tokens parameter caps how much memory text comes back.

In the agent node, we call recall() to fetch memories, then pass them to the LLM along with the conversation history (messages). Specifically, the retrieved memories fill the {memories} placeholder in the system prompt.

Step 6: Deploy the agent to Agent Engine

With the template ready, here's how to deploy it on Agent Engine. 🎉 We’ll do this using the agentengine CLI.

Step 6.1: Load the sample data into Atlas

First, load the sample flights and Airbnb datasets into your Atlas cluster. If you already loaded them while testing locally, skip this step.

Step 6.2: Register the agent on Agent Engine

Next, run the following command from the agent’s workspace directory and choose the organization and project for the agent when prompted. Choose the Atlas project that contains your cluster so Agent Engine can create a workspace for the agent in that project.

Step 6.3: Link your Atlas cluster to the agent

Then, run the command below to link your cluster to the agent. It asks you to choose the organization, project, and cluster for the agent, creates a database user and Voyage API key, saves the MONGODB_URI and VOYAGE_API_KEY as project-level secrets, and adds Agent Engine’s data plane IP addresses to the cluster’s access list:

Step 6.4: Set the remaining environment variables

Next, store the remaining environment variables the agent needs as secrets. In Agent Engine, you can set secrets at the project or workspace level. Project secrets are shared by all agents in the project, while workspace secrets are only available to the agent running in that workspace. For the travel agent, set the following secrets:

Project scope (default):

LLM_API_KEY: Your OpenAI API key

Workspace scope (Set with --workspace-scope):

ATLAS_PROJECT_ID: Your Atlas project ID

ATLAS_CLUSTER_NAME: Your Atlas cluster name

MONGODB_DATABASE: The database containing the sample data, travel_agent in this case

MDB_MCP_CLIENT_ID: Your MCP client ID

MDB_MCP_CLIENT_SECRET: Your MCP client secret

Run the following commands — each command prompts for a value.

Step 6.5: Upload the memory configuration

In Step 5.2, we configured how Agent Engine should create and store memories for the agent. Now, upload that memory configuration to your Agent Engine project using the command below. Memory configuration in Agent Engine is project-scoped, meaning one configuration applies to all agents in your project.

Step 6.6: Build and deploy

Finally, build the agent image and deploy it to Agent Engine using the following commands:

If the deployment is successful, you will see it show up with a “Succeeded” status in the Agent Engine UI:

Once the agent is deployed, you can interact with it in the Playground, monitor uptime, token usage, failures, etc., in the Monitoring tab, and investigate agent traces under Traces. To invoke the agent from an application or backend service, use the Invocation API.

Step 7: Add governance policies and guardrails

Governance is one of the main pillars of Agent Engine. Agent Engine gives admins the ability to enforce governance policies and content guardrails to ensure that agents deployed in their environments work within the bounds of desired behavior.

Policies control what the agents can do by limiting the models and tools they can use, the number of LLM calls and tokens used per execution, etc. Content guardrails control what goes into and comes out of the LLM. They match inputs and outputs against regular expressions and can block, modify, or send them for review.

Here’s an example of a policy that limits the travel agent we deployed to read-only tools: the four MongoDB MCP tools and the custom list_bookings tool. Policies match the tool names the agent sees, so the MCP tools are listed with their mongodb__ prefix (see Step 4):

This explicitly prevents the agent from creating bookings using the create_booking tool since it is not a part of the authorized tools list for the agent.

Here’s an example of a content guardrail on the LLM input designed to detect and block inputs that contain credit card numbers:

The guardrail blocks any input that contains a credit card number before it's sent to the LLM, so it never reaches the model.

Conclusion

In this tutorial, we walked through how we migrated a LangGraph agent to MongoDB Atlas Agent Engine with a handful of code changes. With Agent Engine, you can keep building agents with the frameworks you’re already familiar with, and let MongoDB handle running them in production.

Agent Engine turns your agent into a managed, scalable service, with built-in state and memory, tracing, observability, and governance. Next, try bringing one of your own agents to Agent Engine, and explore our documentation to see what else you can do with it.

Originally published by MongoDB Blog ↗ · rebuilt here from its own full-text RSS feed · all rights remain with the publisher, please read and support them there.