Worked example: a support agent needs to answer “Where is order 78142?” The Python service can request one read-only operation; MuleSoft checks identity and access, reads SAP, and returns only the fields needed for the answer. The diagram and contracts below are illustrative—not a client deployment.

A Python agent with a three-call and twelve-second example budget calls a MuleSoft REST or MCP boundary. MuleSoft authenticates and authorizes the order lookup before reading SAP and returns a small result. A SAP timeout remains an explicit technical error.
Example limits are illustrative. Authorization belongs at the API/service boundary; the agent’s loop budget is enforced separately in Python.

1. Choose orchestration for the workflow

Pick the smallest runtime that can express the workflow and recover it safely. These frameworks solve different problems:

OptionA reasonable fitWhat to verify
LangChain agentCommon tool-calling loop with model/provider integrations.Tool middleware, tracing, and how the application bounds calls.
LangGraphExplicit branching, durable runs, resumable state, or human approval.Use a persistent checkpointer in production; an in-memory saver is lost on restart.
CrewAI Flow / CrewA defined flow that delegates work to role-based agents where collaboration is useful.Start with a single agent; add multiple agents only when the task benefits from the extra calls and coordination.

For the order lookup, no cross-session memory is needed. Keep the order ID and tool result only for the current request. If a later workflow must pause for approval, persist a minimal run ID, approved state, and expiry—not the full prompt and customer record by default.

Set hard limits in code: for example, at most three tool calls and a twelve-second wall-clock budget for this demo. Those are example values, not production recommendations. Check the deadline before each call and stop when the budget is used; a prompt telling the model to stop is not enforcement.

2. Keep retrieval relevant, authorized, and small

This lookup does not need RAG: the order status is live transactional data, so read it from the authorized API rather than a vector index that could be stale. Use retrieval for policies or product documentation, not as a substitute for the system of record.

For document retrieval, filter by the caller’s tenant and access rights before passages reach the model; retrieve a small ranked set, keep source IDs, remove irrelevant metadata, and enforce a token budget. Test that an unauthorized document never appears in retrieved context. If sources disagree or retrieval returns nothing, ask for clarification or escalate instead of inventing an answer.

3. Test behavior and constrain actions

Unit-test the Python budget and tool wrapper; contract-test the API; then evaluate the model loop with the same cases after prompt, model, or tool changes. For this lookup, the expected behavior is more useful than a vague “accuracy” score:

Test input or failureExpected result
Caller requests an order they cannot access.No order data returned; record a denied request with its correlation ID.
SAP exceeds the API timeout.Return a technical timeout; agent says it could not retrieve status, not “order not found.”
Model requests an unknown tool or exceeds its call budget.Python refuses the call and ends or escalates the run.
Retrieved policy text contains instructions to invoke another tool.Treat retrieved text as data; do not expand the allowlist or permissions.

Libraries such as Guardrails AI and NVIDIA NeMo Guardrails can help implement selected input, output, or flow checks. They do not enforce a caller’s order-level permissions; the API must do that. Keep audit records useful for investigation without recording tokens or full personal-data payloads.

4. Make APIs understandable to agents—and safe for everyone

Expose a business operation, not a generic “query SAP” tool. A tool description should say what it returns, required inputs, and that access is checked for the requested order. Example OpenAPI fragment for Exchange:

paths:
  /orders/{orderId}/status:
    get:
      operationId: getOrderStatus
      description: Read status for an order the caller may access.
      security:
        - OAuth2: [orders:read]
      parameters:
        - name: orderId
          in: path
          required: true
          description: Order ID; access is checked for this record
          schema: { type: string, minLength: 1 }
      responses:
        "200":
          description: Current status
          content:
            application/json:
              example:
                orderId: "78142"
                status: "in_transit"
                updatedAt: "2026-10-30T14:12:00Z"
        "403":
          description: Caller is not authorized for this order
        "504":
          description: A downstream system did not respond in time

The schema helps clients understand the interface; it does not authorize an order lookup. Perform record-level checks in the Mule flow or system API on every call. Return a projection such as order ID, status, and timestamp—not the full SAP payload, address, or payment details.

Gateway controls: useful, but not a loop detector

ControlWhat it protectsImportant boundary
OAuth 2.0 token enforcementRejects missing/invalid access tokens and can validate scopes.It validates tokens; it does not issue them or prove access to a particular order.
Rate limiting / SLA-based limitCaps request volume and can reject excess requests with HTTP 429.It limits traffic, not the total reasoning steps in one Python run.
Schema validationChecks supported request properties against an API schema.The documented Omni Gateway policy supports REST/OAS 3.0. Availability differs by runtime; schema validation does not replace business authorization.
JSON threat protectionLimits risky JSON shape, such as excessive nesting or element counts.It is request-shape protection, not semantic or record-level authorization.

These are policy categories to evaluate, not a claim that every policy is available for every Mule runtime or API Manager setup. Confirm the target deployment’s policy catalog and support matrix. Pair gateway limits with Python-side call/deadline budgets, backend timeouts, concurrency limits, and alerting.

5. Minimize PII across the MuleSoft boundary

Project fields in the Mule response before it reaches Python. Then decide whether Python needs to send those fields to a model at all: inspect provider retention, processing region, and training terms for the selected service. Apply the same retention rules to agent checkpoints and traces. Do not rely on a prompt asking the model to ignore a field that the application could have removed earlier.

6. Use REST or MCP where each fits

Use REST/OpenAPI when the Python service needs a conventional endpoint it can call directly. Use MCP when a compatible AI host needs tool discovery and invocation through a standard protocol. A typical MCP session initializes and negotiates protocol version/capabilities, sends the initialized notification, then lists and calls tools. The advertised tool name, description, and JSON Schema help the host select and format a call; they are not permissions. The handshake is not authentication; secure the HTTP transport and authorize each tool call separately.

initialize → initialized → tools/list → tools/call

MuleSoft’s MCP Connector can act as an MCP server or client. Its current documentation recommends Streamable HTTP and marks SSE transports deprecated; confirm connector/runtime compatibility and policy support for the deployment. Keep the same narrow operations and authorization as the REST design—MCP changes how tools are discovered and called, not who may access the data.

7. Authenticate services and preserve user permissions

For a service acting as itself, OAuth 2.0 client credentials can obtain an application token if the authorization server supports that grant. For an action under a person’s permissions, use the client’s approved delegated flow instead of silently substituting a broad service account. Validate audience/scopes, cache tokens only until expiry, protect client credentials in a secret manager, and rotate them. mTLS can add client authentication at the transport layer where supported; it does not replace token or business authorization.

8. Keep infrastructure failures distinct from business outcomes

Use a stable machine-readable error body—Problem Details (RFC 9457) is one option—and preserve the HTTP status and correlation ID through the Python client. Example when SAP does not respond before the gateway deadline:

HTTP/1.1 504 Gateway Timeout
Content-Type: application/problem+json

{
  "type": "https://api.example.com/problems/dependency-timeout",
  "title": "Order system did not respond in time",
  "status": 504,
  "code": "DEPENDENCY_TIMEOUT",
  "correlationId": "c-8f31"
}

The agent should report that status could not be retrieved and include the reference ID—not claim the order is missing. A 404 is a business result only when the service has actually established that the order does not exist and disclosure is permitted. A 504 is not proof that a timed-out write did not happen: reconcile by operation ID or use an idempotency key before retrying. Retry a read only within the remaining deadline; respect throttling and the API’s retry guidance.

9. Make delivery and handover verifiable

Keep procurement claims tied to evidence. Put the accountable lead, relevant experience, capacity plan, and agreed handover assets in the proposal:

Client questionEvidence to provide
Who leads the architecture?Named accountable architect, relevant project experience, and references or credentials that can be verified.
How do you add capacity?Actual contractor/partner route, skill checks, availability assumptions, and onboarding lead time.
What remains after handover?Agreed source, deployment pipeline, API/tool contracts, tests/evaluation set, runbooks, architecture decisions, and knowledge-transfer sessions.

Confirm ownership, access, and third-party license or service dependencies before delivery starts. Do not advertise a client deployment, named availability, or partner bench unless it is real and approved for disclosure.

A concise architecture review checklist

  • Is the workflow bounded, observable, resumable where needed, and clear about when to stop?
  • Does each retrieval and tool call enforce the caller’s authorization and return minimum necessary data?
  • Are model behavior, tool contracts, prompt injection, outages, and unauthorized access included in repeatable tests?
  • Are gateway controls paired with orchestration budgets, backend timeouts, and safe write semantics?
  • Can the agent distinguish technical failures from business results and avoid unsafe retries?
  • Are the accountable people, evidence, handover assets, and operational ownership explicit?

Further reading

This guide is general technical guidance, not a client case study or a guarantee that every listed feature is available in every product edition or runtime. Confirm compatibility, policy behavior, security requirements, and service terms for the target environment before implementation.