How to add AI agents to SAP S/4HANA
Short answer
Build AI agents on S/4HANA by giving a model a small set of tools backed by released OData APIs (or BAPIs and CDS views on-prem), running under a dedicated technical user with narrow authorizations. Start with read-only agents for MRP exceptions and PO follow-up, then add write tools that create drafts or requests which a person approves.
Most S/4HANA teams already have the data an agent needs: MRP results, open purchase orders, inbound deliveries, quality notifications, production orders. What they lack is somebody to read all of it every morning. Planners spend the first hours of a shift in MD04, ME2N, CO02 and QM10 clicking through exceptions that a careful worker could triage in minutes. An AI agent is that worker: it reads the exceptions, looks up the context, and proposes an action.
SAP's own Joule and the embedded AI scenarios cover a growing list of cases, and they are worth using when the scenario you need is shipped for your release and licence. They do not cover the odd, plant-specific routines that make up most of a planner's week, and they do not let you pick the model or keep prompts inside your own network. A custom agent layer fills that gap, and it can sit alongside Joule rather than replace it.
The key design decision is where the agent's authority ends. In SAP, a posting is a legal and financial event. A good agent design therefore treats every write as a proposal: it prepares a purchase requisition, a change request or a notification draft, and a named user releases it using normal SAP authorizations and workflow.
What teams use it for
MRP exception triage
The agent reads MRP exception messages (reschedule in, reschedule out, cancel) for a planner group, checks supplier confirmations and open demand, and returns a ranked list with a recommended action and the reason for it.
Purchase order expediting
For POs past confirmation date, the agent pulls the schedule lines and confirmation data, drafts a supplier chaser, and flags the ones that will stop a production order.
Production order shortage review
Before a shift, the agent checks component availability on released production orders and lists the shortages with the likely cause: late PO, stock in quality inspection, or a reservation taken by another order.
Quality notification drafting
When an inspection lot is rejected, the agent assembles the defect data, usage decision, batch and vendor, and drafts a quality notification for the quality engineer to review.
Invoice and goods receipt mismatch research
For invoices blocked on price or quantity variance, the agent compares the PO, goods receipt and invoice lines and writes a short explanation for the AP clerk, who decides.
Master data hygiene
The agent scans material masters for missing MRP type, lot size or planned delivery time and raises a change request to the data steward instead of editing directly.
SAP S/4HANA integration surface
- Released OData services from the SAP Business Accelerator Hub (api.sap.com): purchase orders, sales orders, product, business partner, material stock, production order and inspection lot services. Exact service names and versions (V2 or V4) differ by release, so check your own catalog.
- On-prem: services are activated in the SAP Gateway through /IWFND/MAINT_SERVICE, and custom ones can be built with ABAP RAP or CDS. In S/4HANA Cloud the equivalent is a communication arrangement tied to a communication scenario and a communication user.
- BAPIs and function modules over RFC (for example the purchase requisition and production order BAPIs) remain the practical write path for many on-prem systems, called through a middleware or a small ABAP wrapper.
- Released ABAP CDS views (the I_ and C_ interface views) are the cleanest read surface for analytics-style questions, exposed as OData with annotations.
- Events: business events from the SAP Event Mesh or Advanced Event Mesh, or classic IDocs (WE02 for monitoring) and workflow events, can wake the agent when something changes instead of polling.
How it works
- 1
List the decisions you want the agent to make
Pick two or three routines a planner or buyer repeats daily, with a clear definition of a good answer. MRP exceptions for one planner group is a good first scope.
- 2
Create a technical user with narrow roles
Use a dedicated communication user or service user. Give it display authorizations only (for example M_BEST_* and M_MTDI_ORG style objects limited to the plants in scope) and nothing in the write area for phase one.
- 3
Expose a small tool layer
Wrap each OData call as a tool with typed inputs: get_open_pos(vendor, date_range), get_mrp_exceptions(plant, planner_group), get_stock(material, plant). Keep the number of tools under about fifteen so the model picks correctly.
- 4
Run the model against the tools
Use an open-weight model served with vLLM or Ollama inside your network, or a cloud model if policy allows. The agent loop calls tools, reads results, and produces a structured recommendation, never a free text posting.
- 5
Add write tools as drafts
Introduce tools that create purchase requisitions, change requests or quality notifications in a draft or workflow state. A person releases them. Log every call with the user, prompt and payload.
- 6
Evaluate on historical data
Replay last month's exceptions and compare the agent's advice with what planners actually did. Fix tool descriptions and prompts before expanding scope.
Example flows
Morning MRP review for a planner group
Trigger: Scheduled at 06:00 for each planner group.
- Agent calls get_mrp_exceptions for the plant and planner group.
- For each exception it fetches the PO schedule lines, supplier confirmation and the dependent production orders.
- It scores impact by the earliest affected customer delivery date.
- It posts a ranked list into the planner's inbox with the evidence for each item.
Result: The planner starts the day on the five items that matter instead of two hundred messages.
Late PO chaser with approval
Trigger: A scheduled event finds a PO line more than two days past its confirmed date.
- Agent reads the PO, vendor contact and affected production order.
- It drafts a supplier email in the buyer's usual tone and attaches the PO lines.
- The buyer reviews, edits and sends it.
- The agent records the chase date against the PO as a note for the next review.
Result: Chasing is consistent and fast, and the buyer stays in control of what is sent.
Keeping data on-prem
Run the whole stack inside your network: the tool layer next to the SAP Gateway or on the same segment as your integration platform, the model on your own GPUs, and the log store in your SIEM. Nothing needs to leave the site, which matters for defense, aerospace and export-controlled programs where material and drawing data cannot go to a public API. For on-prem S/4HANA the Gateway hub and the backend are usually separate, so decide which one the agent reaches and keep that hop on an internal firewall rule only. If you also use SAP BTP, the agent can run there with a private link, but a self-hosted model keeps prompts out of any third-party service.
Security checklist
- Use a dedicated technical user per agent with the smallest authorization set that works, and review it through the usual PFCG role process.
- Keep phase one read-only. Add writes only as drafts or workflow items that a human releases.
- Log every tool call with the user it acted for, the parameters and the response size, and store logs outside the agent runtime.
- Filter output by the requesting user's own plant and company code scope so the agent cannot show what that user could not see in SAP.
- Treat text from vendors, emails and notes as untrusted and never let it change which tools the agent may call.
Ways to get it done
SAP Joule and embedded AI scenarios
Effort: Configuration and licensing work, little code.
Good when your scenario is shipped for your release and you are on the matching licence and cloud subscription.
Build in-house on BTP or your own stack
Effort: Typically a few months for a first useful agent, then ongoing evaluation.
Good when you have ABAP and integration engineers and want full control of tools and models.
Work with a partner such as Netray
Effort: Usually weeks for a read-only pilot, then incremental write tools.
Good when you want a private, on-prem agent layer over your existing SAP APIs without staffing it yourself.
Pitfalls
- !Exposing too many tools. A model with sixty near-identical tools picks the wrong one. Group by task.
- !Using a dialog user with broad roles because it was quick. Agents then inherit far too much authority.
- !Ignoring SAP's licence terms for API and indirect usage. Confirm with your SAP account team how agent calls are counted.
- !Letting the agent call BAPIs that commit directly. Wrap writes so a human release step is mandatory.
- !Skipping evaluation. Agents drift when master data or process changes, so keep a small replay set.
Frequently asked questions
Can an AI agent post transactions in S/4HANA?
Technically yes, through BAPIs or write-enabled OData services, but it is rarely wise at the start. A safer pattern is to have the agent create drafts, requisitions or requests, and a person with the right authorization releases them. Keep a full audit trail either way.
Do we need SAP BTP to build agents?
No. BTP helps with managed connectivity and events, but an agent can call released OData services or RFC-enabled BAPIs from any approved network location. Many on-prem customers run the tool layer and model entirely outside BTP.
Is this different from SAP Joule?
Joule is SAP's own assistant and covers shipped scenarios. A custom agent covers your plant-specific routines and lets you choose the model and hosting. They can coexist, and some teams use Joule for generic tasks and custom agents for local ones.
Which model should the agent use?
Choose by data policy first. If prompts cannot leave your network, use an open-weight model on your own GPUs. If cloud is acceptable, a hosted frontier model may reason better. Test both on replayed historical cases before deciding.
How do we stop the agent from seeing restricted data?
Run it under a technical user whose authorizations are limited to the plants and company codes in scope, and filter by the requesting user's own scope in the tool layer. Never rely on the prompt to hide data.
Want AI agents working on your SAP S/4HANA?
A free 30 minute assessment: we map the integration path for your version and setup, and where it should run.
Get a free assessment