Agents, by definition, act upon their environment. Yet the quality of their actions depend entirely on how accurately and swiftly they perceive the state of their world. Imagine trying to make your way through a crowded room, guided only by a photo taken five minutes earlier. You reach for a chair that’s been moved, step into someone’s path who wasn’t there before, and navigate a space that no longer matches reality. This is how AI agents behave when they’re forced to act without access to live, consistent state.

The conceptual solution to this problem, as laid out in our original post, is simple: give agents a digital twin. This twin allows agents to observe, reason, and act based on the current truth of your organization. And thanks to Materialize, building it is now straightforward. Materialize connects directly to your operational systems, maintains always-fresh views into every aspect of your business, and surfaces them in a form agents can understand and use.

This guide is a technical companion to that idea, showing you how to move from concept to implementation using Materialize and Strands Agents. By the end, you’ll have a practical blueprint for making your most important business concepts available to agents that need them.

Defining the Digital Twin

A digital twin for AI agents isn’t just another copy of your data. It’s a structured always-current representation of the core entities that define your business like customers, inventory, shipments. And the live properties that shape their meaning, like availability, status, or tier. Think of it as a continuously updating map of your operational world. A semantic model that stays in sync with reality.

Each view corresponds to a concrete entity along with its properties. What this approach avoids is forcing agents to guess how these entities are defined or stitched together. The model context protocol, or MCP, provides a standardized way to surface these views as tools so agents can reliably observe their current state.

And as your library of views grows, so too does your system’s semantic richness. Agents gain a broader and more coherent understanding of your business, one well-modeled object at a time.

Building the Live Bridge

Consider a same-day delivery service working to launch a new feature: an agent that can shop for ingredients based on a customer’s recipe. The goal is to eliminate friction from meal planning by letting an agent do the work. But implementing it means stitching together a complex set of systems. ERP for inventory, CRM for customer data, marketing for promotions. The challenge is surfacing the live state of all these systems in one cohesive, agent-readable model.

The team starts with the most foundational questions, what is actually in stock right now.

They start by connecting their ERP system, where inventory is managed, directly to Materialize. Materialize mirrors every change as it occurs in real time, allowing the team to build a live view of the product entity.

sql
CREATE VIEW products AS
SELECT p.product_id,
       p.name,
       BOOL_OR(p.active AND il.quantity_on_hand > 0) AS in_stock,
       SUM(il.quantity_on_hand - il.quantity_reserved) AS available_to_sell,
       COUNT(DISTINCT il.warehouse_location) AS num_fulfillment_sites,
       CASE
         WHEN SUM(il.quantity_on_hand - il.quantity_reserved) > 100 THEN 'High'
         WHEN SUM(il.quantity_on_hand - il.quantity_reserved) > 0 THEN 'Medium'
         ELSE 'Low'
       END AS stock_level
FROM product_catalog p
JOIN inventory_levels il ON p.product_id = il.product_id
GROUP BY p.product_id, p.name;

CREATE INDEX products_primary ON products(product_id);

They start by creating a view in Materialize, products, that agents can reference. products is a comprehensive inventory summary that joins all of our products from our product_catalog with our inventory_levels table. We expose the product name, id, availability, number of fulfillment centers, and stock level to the agents. This curated view gives agents access to the exact information they need, saving agents token cost and leaving out confidential information from our ERP system.

The index tells Materialize to keep the results of the view always fresh and available.

sql
COMMENT ON VIEW products IS 'Definitive, operationally trusted representation of a product and its current availability across the fulfillment network. Serves as the single source of truth for determining product availability, stock levels, and fulfillment capabilities in real time. Central to inventory management, fulfillment routing, and product-level operational decisions.';
COMMENT ON COLUMN products.product_id IS 'Globally unique identifier for the product. Serves as the primary key for referencing product-related operations, inventory levels, and catalog information across the business.';
COMMENT ON COLUMN products.name IS 'Canonical name of the product used in customer-facing systems and internal operations. Provides human-readable context and is essential for search, navigation, and user interfaces.';
COMMENT ON COLUMN products.primary_warehouse IS 'Warehouse location marked as the primary fulfillment site for this product. Selected based on highest priority location flag, this value drives preferred routing decisions and serves as a fallback for stock aggregation and replenishment.';
COMMENT ON COLUMN products.in_stock IS 'Boolean flag indicating whether the product is currently available at any fulfillment site with non-zero salable inventory. Used in determining product availability for purchase, surfacing in-stock indicators, and powering real-time stock checks.';
COMMENT ON COLUMN products.available_to_sell IS 'Total quantity of unreserved, sellable inventory across all fulfillment locations. Computed as the sum of quantity on hand minus quantity reserved. Drives availability logic for order placement, backorder prevention, and stock-level decisioning.';
COMMENT ON COLUMN products.num_fulfillment_sites IS 'Count of distinct warehouse locations currently stocking this product. Reflects the breadth of fulfillment coverage and is a proxy for fulfillment flexibility and resiliency.';
COMMENT ON COLUMN products.stock_level IS 'Qualitative stock level classification derived from available-to-sell quantity. Used for merchandising, alerts, and operational reporting. High indicates ample inventory, Medium signals moderate availability, and Low warns of impending stockout or zero availability.';

With the live, in memory, view of products and their inventory information, the team defines comments for their MCP server for the products view itself and its properties. These comments define in natural language what the view and properties for the agents.

bash
uv pip install mcp-materialize
uv run mcp-materialize --mz-dsn "$DSN" --transport http

Just like that, the team has enabled agents to look up the current state of any product based on its product id. Agents leverage the natural language descriptions provided to understand the semantics of the entity. This means agents can autonomously determine when and how to look up products and interpret properties like stock levels to make live decisions.

From here, the team can reach for a framework like Strands Agents, to quickly build an AI Agent that assists with shopping carts. It takes a customers recipe and observes the current state of each product through the products view to ensure all the ingredients for a recipe are available.

python
materialize = MCPServer(lambda: streamablehttp("http://mcp-materialize:8001/mcp"))
with materialize:
        tools = materialize.list_tools_sync()
	purchase_agent = Agent(
    		system_prompt="Select and reserve ingredients for a customer’s recipe using live availability. If an ingredient isn't available find an alternative and and check with the customer",
    		tools=tools
	)

	response = purchase_agent("I want to make lasagna")

Expanding Capabilities

With inventory live, the team turns to customer context. They connect their CRM and build a unified customer view that merges identity, preferences, and trust signals into a single, live model.

Now the agent can do more than check what’s in stock, it can personalize its choices. If the customer is allergic to dairy, it swaps ricotta for a cashew-based alternative. If they’re gold-tier, it prioritizes ingredients available for same-day delivery from their preferred warehouse. The agent isn’t just filling a cart, it’s tailoring the experience to the individual, using fresh data at every step.

sql
CREATE VIEW customers AS
WITH merged AS (
    SELECT
        COALESCE(c.customer_id, b.customer_id, s.customer_id) AS customer_id,
        COALESCE(c.name, 'Unknown') AS name,
        COALESCE(c.email, s.email) AS email,
        b.phone,
        b.address,
        GREATEST(c.updated_at, b.updated_at, s.updated_at) AS last_updated,
        COALESCE(st.crm_trust, 0) * 1.5 +
        COALESCE(st.billing_trust, 0) * 1.2 +
        COALESCE(st.support_trust, 0) +
        (CASE WHEN c.email IS NOT NULL THEN 5 ELSE 0 END) +
        (CASE WHEN b.phone IS NOT NULL THEN 3 ELSE 0 END) +
        (CASE WHEN b.address IS NOT NULL THEN 2 ELSE 0 END) AS score,
        ARRAY(SELECT DISTINCT a.allergen FROM customer_allergies a WHERE a.customer_id = COALESCE(c.customer_id, b.customer_id, s.customer_id)) AS allergens
    FROM crm_customers c
    FULL OUTER JOIN billing_customers b USING (customer_id)
    FULL OUTER JOIN support_customers s USING (customer_id)
    LEFT JOIN source_trust st ON st.customer_id = COALESCE(c.customer_id, b.customer_id, s.customer_id)
)
SELECT DISTINCT ON (customer_id)
    customer_id,
    name,
    email,
    phone,
    address,
    last_updated,
    score,
    allergens
FROM merged
ORDER BY customer_id, score DESC, last_updated DESC;

CREATE INDEX customers_primary ON customers(customer_id);

COMMENT ON VIEW customers IS 'Provides a unified and current profile of each customer, combining identity, contact details, and behavioral signals from multiple operational systems. Includes trust-based scoring and allergy information to support precise, context-aware decisions.';

COMMENT ON COLUMN customers.customer_id IS 'The unified identifier for a customer, resolved across CRM, billing, and support systems.';
COMMENT ON COLUMN customers.name IS 'Customer name prioritized from CRM and used for personalization and support.';
COMMENT ON COLUMN customers.email IS 'Customer email derived with fallback to support systems, used for notifications and validation.';
COMMENT ON COLUMN customers.phone IS 'Customer phone number as stored in billing systems, used for contact and verification.';
COMMENT ON COLUMN customers.address IS 'Most up-to-date known address for the customer, used for shipping and delivery logic.';
COMMENT ON COLUMN customers.last_updated IS 'Timestamp of most recent activity across all customer-related systems.';
COMMENT ON COLUMN customers.score IS 'Composite trust score based on source confidence and field completeness, used to prioritize high-quality records.';
COMMENT ON COLUMN customers.allergens IS 'List of known customer allergens based on medical or preference records, used for product filtering.'

What started as a basic cart builder is now a fulfillment strategist, personalization engine, and promotion optimizer. Because with each new view your agents grow more capable. They gain the context to personalize decisions, coordinate operations, and respond to change. All because of the data it can see.

Materialize is the platform for building these agent-ready digital twins. Just write SQL. Under the hood, our breakthrough in incremental view maintenance keeps everything fresh and at scale. You can run Materialize as a managed service or deploy it privately in your own cloud.

If you’re working to make your operational data ready for AI, we’d love to help. Book a 30-minute introductory call with us here.

Get Started with Materialize