October 3, 2025

How to Build an Industrial AI Agent Using Python and LangChain

Imagine starting a production shift and asking a simple question: "Can we produce 3 batches of Product A?" Instead of manually checking tank levels, walking to each machine to verify its status, and cross-referencing recipe information—a slow, error-prone process—an AI agent instantly gathers all the data, analyzes it, and gives you a clear go/no-go decision with detailed reasoning.

That's exactly what we're building in this tutorial.

What We're Building

This tutorial demonstrates how to create a Batch Plant Production Assistant AI Agent that can:

Access real-time equipment and material data from an OPC UA server.

Query product recipes and requirements from a TimescaleDB database.

Make intelligent production decisions based on material availability and equipment status.

Explain its reasoning in plain English.

The agent acts as a bridge between your industrial data systems and natural language queries, allowing operators to get instant, accurate answers without manual data gathering.

Why This Matters

Traditional industrial operations require operators to interface with multiple disconnected systems—SCADA displays, databases, paper records—to make a single decision. This approach is time-consuming, with minutes or hours spent gathering information. It's error-prone because manual data collection introduces mistakes, and it doesn't scale well since complex decisions require even more manual work.

AI agents change this paradigm entirely. By connecting to your existing data infrastructure and using large language models as the "brain," these agents can process natural language questions, orchestrate data retrieval from multiple sources, perform complex analysis and reasoning, and provide clear, actionable answers in seconds.

While we're demonstrating this with a simplified batch plant scenario, the principles apply to any industrial AI application. Whether you're working on predictive maintenance decisions, supply chain optimization, quality control analysis, or energy management, the foundational concepts you'll learn here translate directly to those more complex use cases.

The Technical Foundation

This isn't just another LLM chatbot. What makes this truly industrial is the real data integration through direct connections to OPC UA servers and industrial databases. The agent uses a tool-calling architecture, which means the AI doesn't just generate text—it actively retrieves and analyzes live data. It provides structured decision-making with clear yes/no outputs and supporting evidence, not vague suggestions. And it's built with frameworks and practices that scale to real deployments, making it production-ready from the start.

The tutorial uses Python for data access and application logic, the LangChain framework to simplify AI agent development, and Claude (Anthropic's LLM) as the reasoning engine. On the data side, we're working with OPC UA for real-time equipment data and TimescaleDB for historical and recipe data. These are representative of what you'd find in actual industrial facilities.

What You'll Learn

By following this tutorial, you'll understand how to convert Python functions into AI-callable tools, giving your agent the ability to actually interact with real systems rather than just talking about them. You'll learn the architecture of tool-calling AI agents and how they differ from simple chatbots. The tutorial covers how to structure prompts for consistent, reliable industrial decisions, which is critical when these systems are making real operational choices. You'll see how large language models can orchestrate complex data workflows, pulling information from multiple sources and synthesizing it into actionable insights. Perhaps most importantly, you'll understand the difference between basic LLM applications and production-ready industrial agents.

The Complete Walkthrough

The simulated batch plant we work with in this tutorial is actually pretty representative of what you'd find in a real facility. It includes three storage tanks that hold raw materials, a mixer that combines these materials according to recipes, a reactor where the actual chemical processing happens, and a filling machine that packages the finished product. All of this equipment exposes its real-time data through an OPC UA server, just like in modern industrial plants.

The full video tutorial walks through every step of building this AI agent from scratch. We start by setting up the simulated batch plant environment and connecting to it using an OPC UA browser, where you can see live tank levels and equipment states updating in real time. Then we create Python functions to access both the OPC UA server and the TimescaleDB database, verifying that we can reliably pull the data we need.

The heart of the tutorial is converting those functions into LangChain tools that the AI agent can call. This is where the magic happens—we're giving the language model actual capabilities to interact with industrial systems. We then build and configure the AI agent itself, which involves creating a carefully structured prompt that tells the agent its role, what tools it has available, and how it should make decisions. The prompt template is actually one of the most critical pieces because it ensures we get consistent, reliable behavior from the agent.

Finally, we test the agent with real queries and watch as it orchestrates the entire workflow. It queries the database to get the product recipe, calls the OPC UA server to check current material levels and machine states, performs the necessary calculations, and delivers a clear decision with detailed reasoning. You'll see the agent explain exactly why it reached its conclusion, showing its work like a helpful colleague rather than a black box.

Watch the Full Tutorial

The complete video tutorial provides a detailed, step-by-step walkthrough of building this industrial AI agent from scratch. You'll see actual code, live data, and the agent making real decisions based on simulated but realistic plant conditions.

All code is available on GitHub, so you can follow along, experiment, and adapt it to your own use cases. This is Part 1 of a five-part series on building Agentic AI for industrial systems, in Part you'll learn how to build and run your industrial AI agent fully local at edge edge.