Skip to main content

Pro-Code AI Agents

1 Overview

Description

This best practice page focuses on building production-ready AI agents using code-based approaches within the SAP ecosystem. For security and governance of AI agents, see the dedicated Agentic AI Security and Governance best practice page. For connecting agents to enterprise tools and data sources via the Model Context Protocol, see the Model Context Protocol (MCP) best practice page.

AI agents are software systems that go beyond simple prompt-response interactions. They can plan, reason, and act iteratively to complete multi-step tasks by calling external tools, APIs, and data sources. Unlike traditional LLM usage ("single prompt" to "single response"), agents operate in a loop: they reason about what to do next, take an action, observe the result, and decide whether to continue or deliver a final answer.

Within the SAP ecosystem, code-based agents represent the most flexible approach to building agentic workflows. They offer full autonomy for advanced intelligence, custom API integrations, and specialized algorithms, in contrast to content-based agents (low-code/no-code declarative approach) or Joule Scenarios (SAP's built-in conversational AI).

This best practice page covers two complementary approaches:

  1. The ReAct Pattern (from scratch): Understanding how agents work at a fundamental level, the Thought Action Observation loop that underpins all agentic frameworks. This foundation is essential for debugging, optimizing, and reasoning about agent behavior.
  2. LangGraph: The recommended production framework for building structured, enterprise-grade agentic workflows within SAP. LangGraph models agent logic as a graph of nodes and edges with shared state, offering the granular control and reliability required for business-critical processes. The content is structured in 3 subsections:
    1. Basic ReAct Agent: replaces the manual loop with a structured state graph
    2. Multi-Agent Routing with Conditional Edges: LLM-based classifier at the entry point of the graph. The key takeaway is scoped tool access: by restricting which tools each agent can call, you reduce cost (fewer tokens describing irrelevant tools), improve reliability (the model is less likely to pick the wrong tool), and enforce domain boundaries
    3. Enterprise Procurement Workflow: replaces the toy tools of the first ReAct Agent with six enterprise-grade tools backed by mock data simulating SAP systems.