How to Configure Retries on LLMs and Remote Components#

python-icon Download Python Script

Python script/notebook for this guide.

Retry configuration how-to script

Prerequisites

This guide assumes familiarity with:

WayFlow remote components now share the same RetryPolicy object. You can use it to configure retry timing and per-attempt request timeouts consistently across LLMs, embedding models, ApiCallStep, RemoteTool, remote MCP transports such as StreamableHTTPTransport, OciAgent, and A2AAgent.

Create a Retry Policy#

Start by defining a RetryPolicy with the retry behavior you want to reuse.

from wayflowcore.retrypolicy import RetryPolicy

retry_policy = RetryPolicy(
    max_attempts=3,
    request_timeout=20.0,
    initial_retry_delay=1.0,
    max_retry_delay=8.0,
    backoff_factor=2.0,
    jitter="full_and_equal_for_throttle",
)

Apply the Policy to Remote Components#

You can then pass the same retry policy to any supported remote component.

from wayflowcore.models import OpenAICompatibleModel

llm = OpenAICompatibleModel(
    model_id="my-model",
    base_url="https://example.com",
    retry_policy=retry_policy,
)
from wayflowcore.steps import ApiCallStep
from wayflowcore.tools import RemoteTool

ORDER_API_BASE_URL = "https://example.com/orders"

api_step = ApiCallStep(
    name="fetch_order_step",
    url=ORDER_API_BASE_URL,
    method="POST",
    retry_policy=retry_policy,
)

remote_tool = RemoteTool(
    name="fetch_order",
    description="Fetch an order from a remote API.",
    url=ORDER_API_BASE_URL + "/{{ order_id }}",  # keep the base URL fixed and template only the path parameter
    method="GET",
    retry_policy=retry_policy,
    url_allow_list=[ORDER_API_BASE_URL],
)
from wayflowcore.a2a.a2aagent import A2AAgent, A2AConnectionConfig
from wayflowcore.mcp import StreamableHTTPTransport
from wayflowcore.models.ociclientconfig import OCIClientConfigWithInstancePrincipal
from wayflowcore.ociagent import OciAgent

a2a_agent = A2AAgent(
    agent_url="https://example.com/a2a",
    connection_config=A2AConnectionConfig(verify=False, retry_policy=retry_policy),
)

oci_agent = OciAgent(
    agent_endpoint_id="ocid1.agentendpoint.oc1..example",
    client_config=OCIClientConfigWithInstancePrincipal(service_endpoint="https://example.com"),
    retry_policy=retry_policy,
)

transport = StreamableHTTPTransport(
    url="https://example.com/mcp",
    retry_policy=retry_policy,
)

WayFlow applies request_timeout per attempt. Retries are limited to transient failures such as configured recoverable status codes, eligible 5xx responses, and connection errors. Authentication failures, validation failures, and TLS/certificate verification failures are not retried.

Agent Spec Exporting/Loading#

You can export a configuration that includes the retry policy to Agent Spec using the AgentSpecExporter.

from wayflowcore.agentspec import AgentSpecExporter

serialized_assistant = AgentSpecExporter().to_json(oci_agent)

Here is what the Agent Spec representation will look like ↓

Click here to see the assistant configuration.
{
  "component_type": "OciAgent",
  "id": "d3ec0b4c-ab23-4555-82e8-3dda8a831fb2",
  "name": "oci_agent_5008210d__auto",
  "description": "",
  "metadata": {
    "__metadata_info__": {}
  },
  "inputs": [],
  "outputs": [],
  "agent_endpoint_id": "ocid1.agentendpoint.oc1..example",
  "client_config": {
    "component_type": "OciClientConfigWithInstancePrincipal",
    "id": "45384ec0-c3c7-4d55-a37e-f8e28d8027e5",
    "name": "oci_client_config",
    "description": null,
    "metadata": {},
    "service_endpoint": "https://example.com",
    "auth_type": "INSTANCE_PRINCIPAL"
  },
  "retry_policy": {
    "max_attempts": 3,
    "request_timeout": 20.0,
    "initial_retry_delay": 1.0,
    "max_retry_delay": 8.0,
    "backoff_factor": 2.0,
    "jitter": "full_and_equal_for_throttle",
    "service_error_retry_on_any_5xx": true,
    "recoverable_statuses": {
      "409": [],
      "429": []
    }
  },
  "agentspec_version": "26.2.0"
}

You can then load the configuration back with the AgentSpecLoader.

from wayflowcore.agentspec import AgentSpecLoader

loaded_agent: OciAgent = AgentSpecLoader().load_json(serialized_assistant)

Next steps#

Now that you have learned how to configure retries on remote components, you may proceed to How to Use OCI Generative AI Agents or How to Connect to A2A Agents.

Full code#

Click on the card at the top of this page to download the full code for this guide or copy the code below.

  1# Copyright © 2026 Oracle and/or its affiliates.
  2#
  3# This software is under the Apache License 2.0
  4# %%[markdown]
  5# Code Example - How to Configure Retries on Remote Components
  6# ------------------------------------------------------------
  7
  8# How to use:
  9# Create a new Python virtual environment and install the latest WayFlow version.
 10# ```bash
 11# python -m venv venv-wayflowcore
 12# source venv-wayflowcore/bin/activate
 13# pip install --upgrade pip
 14# pip install "wayflowcore==26.1.2" 
 15# ```
 16
 17# You can now run the script
 18# 1. As a Python file:
 19# ```bash
 20# python howto_retry_configuration.py
 21# ```
 22# 2. As a Notebook (in VSCode):
 23# When viewing the file,
 24#  - press the keys Ctrl + Enter to run the selected cell
 25#  - or Shift + Enter to run the selected cell and move to the cell below# (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0) or Universal Permissive License
 26# (UPL) 1.0 (LICENSE-UPL or https://oss.oracle.com/licenses/upl), at your option.
 27
 28
 29
 30# %%[markdown]
 31## Create a retry policy
 32
 33# %%
 34from wayflowcore.retrypolicy import RetryPolicy
 35
 36retry_policy = RetryPolicy(
 37    max_attempts=3,
 38    request_timeout=20.0,
 39    initial_retry_delay=1.0,
 40    max_retry_delay=8.0,
 41    backoff_factor=2.0,
 42    jitter="full_and_equal_for_throttle",
 43)
 44
 45
 46# %%[markdown]
 47## Configure a remote LLM
 48
 49# %%
 50from wayflowcore.models import OpenAICompatibleModel
 51
 52llm = OpenAICompatibleModel(
 53    model_id="my-model",
 54    base_url="https://example.com",
 55    retry_policy=retry_policy,
 56)
 57
 58
 59# %%[markdown]
 60## Configure remote steps and tools
 61
 62# %%
 63from wayflowcore.steps import ApiCallStep
 64from wayflowcore.tools import RemoteTool
 65
 66ORDER_API_BASE_URL = "https://example.com/orders"
 67
 68api_step = ApiCallStep(
 69    name="fetch_order_step",
 70    url=ORDER_API_BASE_URL,
 71    method="POST",
 72    retry_policy=retry_policy,
 73)
 74
 75remote_tool = RemoteTool(
 76    name="fetch_order",
 77    description="Fetch an order from a remote API.",
 78    url=ORDER_API_BASE_URL + "/{{ order_id }}",  # keep the base URL fixed and template only the path parameter
 79    method="GET",
 80    retry_policy=retry_policy,
 81    url_allow_list=[ORDER_API_BASE_URL],
 82)
 83
 84
 85# %%[markdown]
 86## Configure remote agents and MCP transports
 87
 88# %%
 89from wayflowcore.a2a.a2aagent import A2AAgent, A2AConnectionConfig
 90from wayflowcore.mcp import StreamableHTTPTransport
 91from wayflowcore.models.ociclientconfig import OCIClientConfigWithInstancePrincipal
 92from wayflowcore.ociagent import OciAgent
 93
 94a2a_agent = A2AAgent(
 95    agent_url="https://example.com/a2a",
 96    connection_config=A2AConnectionConfig(verify=False, retry_policy=retry_policy),
 97)
 98
 99oci_agent = OciAgent(
100    agent_endpoint_id="ocid1.agentendpoint.oc1..example",
101    client_config=OCIClientConfigWithInstancePrincipal(service_endpoint="https://example.com"),
102    retry_policy=retry_policy,
103)
104
105transport = StreamableHTTPTransport(
106    url="https://example.com/mcp",
107    retry_policy=retry_policy,
108)
109
110
111# %%[markdown]
112## Export config to Agent Spec
113
114# %%
115from wayflowcore.agentspec import AgentSpecExporter
116
117serialized_assistant = AgentSpecExporter().to_json(oci_agent)
118
119
120# %%[markdown]
121## Load Agent Spec config
122
123# %%
124from wayflowcore.agentspec import AgentSpecLoader
125
126loaded_agent: OciAgent = AgentSpecLoader().load_json(serialized_assistant)