How I learned the OpenAI Agents SDK by breaking down a Stripe workflow from the OpenAI cookbook (part 3)

tl;dr: I set loggers to DEBUG, reran the triage agent workflow, and dug through the raw JSON logs. Seeing each request and response in detail revealed how agents and handoffs really work. Seriously fun!
View the series
  1. See how I learned the Stripe API to follow Dan's agent workflow
  2. Come explore tools and handoffs in OpenAI Agents SDK with me
  3. Join me as I dive into SDK logs to trace its OpenAI API calls
  4. Learn how I removed AI agents from the Stripe workflow

With the Traces dashboard ↗, we can visualize workflows in a neat interface. It's great for seeing the flow between LLM calls, function calls, and handoffs, and for inspecting their inputs and outputs.

Visualization of AI agents, API responses, and function tool handoffs in OpenAI Traces UI

But to really understand what happens when we run

await Runner.run(triage_agent, input=...)

I prefer to look directly at the JSON data of the requests and responses that the OpenAI Agents SDK sends to the Responses API.

This way, I can mentally map the code written (agents, function tools, handoffs) to the JSON payload of the requests sent to the Responses API. The benefit? I don't have to dig into the specifics of Python classes and decorators like FunctionTool, @function_tool, Agent, Handoff, or the logic inside the Runner.run loop.

To do this, I set the logging level of the loggers openai.agents and openai._base_client to DEBUG:

import logging

logging.basicConfig()
logging.getLogger("openai.agents").setLevel(logging.DEBUG)
logging.getLogger("openai._base_client").setLevel(logging.DEBUG)

Then I ran the worklow again:

import asyncio

triage_agent = Agent(
    name="Triage Agent Log level DEBUG",
    instructions=(
        "Please do the following:\n"
        "1. Find the order ID from the payment intent's metadata.\n"
        "2. Retrieve detailed information about the order (e.g., shipping status).\n"
        "3. If the order has shipped, escalate this dispute to the investigator agent.\n"
        "4. If the order has not shipped, accept the dispute.\n"
    ),
    model="gpt-4o",
    tools=[retrieve_payment_intent, get_order],
    handoffs=[accept_dispute_agent, investigator_agent]
)

payment = stripe.PaymentIntent.create(
  amount=2000,
  currency="usd",
  payment_method = "pm_card_createDisputeProductNotReceived",
  confirm=True,
  metadata={"order_id": "1234"},
  off_session=True,
  automatic_payment_methods={"enabled": True},
)

asyncio.run(process_dispute(payment.id, triage_agent))
Get my latest AI automation experiments — free

No spam. Unsubscribe anytime.

Here are some of the logs. I kept the POST requests to the Responses API, the function call outputs, and pretty-printed the JSON objects for readability:

Turn 1 (Triage Agent Log level DEBUG)

DEBUG:openai.agents:Running agent Triage Agent Log level DEBUG (turn 1)
...
DEBUG:openai._base_client:Sending HTTP Request: POST https://api.openai.com/v1/responses
{
  "include": [],
  "input": [
    {
      "content": "{\"dispute_id\": \"dp_1RngVxQuMzbiv2kflcD3SYfK\", \"amount\": 2000, \"due_by\": 1754006399, \"payment_intent\": \"pi_3RngVxQuMzbiv2kf1qfcy34X\", \"reason\": \"product_not_received\", \"status\": \"needs_response\", \"card_brand\": \"visa\"}",
      "role": "user"
    }
  ],
  "instructions": "Please do the following:\n1. Find the order ID from the payment intent's metadata.\n2. Retrieve detailed information about the order (e.g., shipping status).\n3. If the order has shipped, escalate this dispute to the investigator agent.\n4. If the order has not shipped, accept the dispute.\n",
  "model": "gpt-4o",
  "stream": false,
  "tools": [
    {
      "name": "retrieve_payment_intent",
      "parameters": {
        "properties": {
          "payment_intent_id": {
            "title": "Payment Intent Id",
            "type": "string"
          }
        },
        "required": [
          "payment_intent_id"
        ],
        "title": "retrieve_payment_intent_args",
        "type": "object",
        "additionalProperties": false
      },
      "strict": true,
      "type": "function",
      "description": "Retrieve a Stripe payment intent by ID.\nReturns the payment intent object on success or an empty dictionary on failure."
    },
    {
      "name": "get_order",
      "parameters": {
        "properties": {
          "order_id": {
            "title": "Order Id",
            "type": "integer"
          }
        },
        "required": [
          "order_id"
        ],
        "title": "get_order_args",
        "type": "object",
        "additionalProperties": false
      },
      "strict": true,
      "type": "function",
      "description": "Retrieve an order by ID from a predefined list of orders.\nReturns the corresponding order object or 'No order found'."
    },
    {
      "name": "transfer_to_accept_dispute_agent",
      "parameters": {
        "additionalProperties": false,
        "type": "object",
        "properties": {},
        "required": []
      },
      "strict": true,
      "type": "function",
      "description": "Handoff to the Accept Dispute Agent agent to handle the request. "
    },
    {
      "name": "transfer_to_dispute_intake_agent",
      "parameters": {
        "additionalProperties": false,
        "type": "object",
        "properties": {},
        "required": []
      },
      "strict": true,
      "type": "function",
      "description": "Handoff to the Dispute Intake Agent agent to handle the request. "
    }
  ]
}
DEBUG:openai.agents:LLM resp:
[
  {
    "arguments": "{\"payment_intent_id\":\"pi_3RngVxQuMzbiv2kf1qfcy34X\"}",
    "call_id": "call_UTYO3lPU4b3mt90Aes1MjPle",
    "name": "retrieve_payment_intent",
    "type": "function_call",
    "id": "fc_687f970c3e8c8191a25f81365010a29a0a3349a30bf8c3a5",
    "status": "completed"
  }
]
DEBUG:openai.agents:Tool retrieve_payment_intent returned
{
  "amount": 2000,
  "amount_capturable": 0,
  "amount_details": {
    "tip": {}
  },
  "amount_received": 2000,
  "application": null,
  "application_fee_amount": null,
  "automatic_payment_methods": {
    "allow_redirects": "always",
    "enabled": true
  },
  "canceled_at": null,
  "cancellation_reason": null,
  "capture_method": "automatic_async",
  "client_secret": "pi_3RngVxQuMzbiv2kf1qfcy34X_secret_FuyAdGh94lLsssgNnKe2e7oKx",
  "confirmation_method": "automatic",
  "created": 1753191953,
  "currency": "usd",
  "customer": null,
  "description": null,
  "id": "pi_3RngVxQuMzbiv2kf1qfcy34X",
  "last_payment_error": null,
  "latest_charge": "ch_3RngVxQuMzbiv2kf1zQ9coOo",
  "livemode": false,
  "metadata": {
    "order_id": "1234"
  },
  "next_action": null,
  "object": "payment_intent",
  "on_behalf_of": null,
  "payment_method": "pm_1RngVwQuMzbiv2kfsyFBt3Iu",
  "payment_method_configuration_details": {
    "id": "pmc_1RlmnJQuMzbiv2kfOw1kPhMl",
    "parent": null
  },
  "payment_method_options": {
    "amazon_pay": {
      "express_checkout_element_session_id": null
    },
    "card": {
      "installments": null,
      "mandate_options": null,
      "network": null,
      "request_three_d_secure": "automatic"
    },
    "link": {
      "persistent_token": null
    }
  },
  "payment_method_types": [
    "card",
    "link",
    "amazon_pay"
  ],
  "processing": null,
  "receipt_email": null,
  "review": null,
  "setup_future_usage": null,
  "shipping": null,
  "source": null,
  "statement_descriptor": null,
  "statement_descriptor_suffix": null,
  "status": "succeeded",
  "transfer_data": null,
  "transfer_group": null
}

Turn 2 (Triage Agent Log level DEBUG)

DEBUG:openai.agents:Running agent Triage Agent Log level DEBUG (turn 2)
...
DEBUG:openai._base_client:Sending HTTP Request: POST https://api.openai.com/v1/responses
{
  "include": [],
  "input": [
    {
      "content": "{\"dispute_id\": \"dp_1RngVxQuMzbiv2kflcD3SYfK\", \"amount\": 2000, \"due_by\": 1754006399, \"payment_intent\": \"pi_3RngVxQuMzbiv2kf1qfcy34X\", \"reason\": \"product_not_received\", \"status\": \"needs_response\", \"card_brand\": \"visa\"}",
      "role": "user"
    },
    {
      "arguments": "{\"payment_intent_id\":\"pi_3RngVxQuMzbiv2kf1qfcy34X\"}",
      "call_id": "call_UTYO3lPU4b3mt90Aes1MjPle",
      "name": "retrieve_payment_intent",
      "type": "function_call",
      "id": "fc_687f970c3e8c8191a25f81365010a29a0a3349a30bf8c3a5",
      "status": "completed"
    },
    {
      "call_id": "call_UTYO3lPU4b3mt90Aes1MjPle",
      "output": "{\n  \"amount\": 2000,\n  \"amount_capturable\": 0,\n  \"amount_details\": {\n    \"tip\": {}\n  },\n  \"amount_received\": 2000,\n  \"application\": null,\n  \"application_fee_amount\": null,\n  \"automatic_payment_methods\": {\n    \"allow_redirects\": \"always\",\n    \"enabled\": true\n  },\n  \"canceled_at\": null,\n  \"cancellation_reason\": null,\n  \"capture_method\": \"automatic_async\",\n  \"client_secret\": \"pi_3RngVxQuMzbiv2kf1qfcy34X_secret_FuyAdGh94lLsssgNnKe2e7oKx\",\n  \"confirmation_method\": \"automatic\",\n  \"created\": 1753191953,\n  \"currency\": \"usd\",\n  \"customer\": null,\n  \"description\": null,\n  \"id\": \"pi_3RngVxQuMzbiv2kf1qfcy34X\",\n  \"last_payment_error\": null,\n  \"latest_charge\": \"ch_3RngVxQuMzbiv2kf1zQ9coOo\",\n  \"livemode\": false,\n  \"metadata\": {\n    \"order_id\": \"1234\"\n  },\n  \"next_action\": null,\n  \"object\": \"payment_intent\",\n  \"on_behalf_of\": null,\n  \"payment_method\": \"pm_1RngVwQuMzbiv2kfsyFBt3Iu\",\n  \"payment_method_configuration_details\": {\n    \"id\": \"pmc_1RlmnJQuMzbiv2kfOw1kPhMl\",\n    \"parent\": null\n  },\n  \"payment_method_options\": {\n    \"amazon_pay\": {\n      \"express_checkout_element_session_id\": null\n    },\n    \"card\": {\n      \"installments\": null,\n      \"mandate_options\": null,\n      \"network\": null,\n      \"request_three_d_secure\": \"automatic\"\n    },\n    \"link\": {\n      \"persistent_token\": null\n    }\n  },\n  \"payment_method_types\": [\n    \"card\",\n    \"link\",\n    \"amazon_pay\"\n  ],\n  \"processing\": null,\n  \"receipt_email\": null,\n  \"review\": null,\n  \"setup_future_usage\": null,\n  \"shipping\": null,\n  \"source\": null,\n  \"statement_descriptor\": null,\n  \"statement_descriptor_suffix\": null,\n  \"status\": \"succeeded\",\n  \"transfer_data\": null,\n  \"transfer_group\": null\n}",
      "type": "function_call_output"
    }
  ],
  "instructions": "Please do the following:\n1. Find the order ID from the payment intent's metadata.\n2. Retrieve detailed information about the order (e.g., shipping status).\n3. If the order has shipped, escalate this dispute to the investigator agent.\n4. If the order has not shipped, accept the dispute.\n",
  "model": "gpt-4o",
  "stream": false,
  "tools": [<same_as_above>]
}
DEBUG:openai.agents:LLM resp:
[
  {
    "arguments": "{\"order_id\":1234}",
    "call_id": "call_aH4uuFY9Py3B8voBDvJqxjxP",
    "name": "get_order",
    "type": "function_call",
    "id": "fc_687f970defd88191b1ee5e5c7ededc950a3349a30bf8c3a5",
    "status": "completed"
  }
]
DEBUG:openai.agents:Tool get_order returned
{
  "order_id": 1234,
  "fulfillment_details": "not_shipped"
}

Turn 3 (Triage Agent Log level DEBUG)

DEBUG:openai.agents:Running agent Triage Agent Log level DEBUG (turn 3)
...
DEBUG:openai._base_client:Sending HTTP Request: POST https://api.openai.com/v1/responses
{
  "include": [],
  "input": [
    {
      "content": "{\"dispute_id\": \"dp_1RngVxQuMzbiv2kflcD3SYfK\", \"amount\": 2000, \"due_by\": 1754006399, \"payment_intent\": \"pi_3RngVxQuMzbiv2kf1qfcy34X\", \"reason\": \"product_not_received\", \"status\": \"needs_response\", \"card_brand\": \"visa\"}",
      "role": "user"
    },
    {
      "arguments": "{\"payment_intent_id\":\"pi_3RngVxQuMzbiv2kf1qfcy34X\"}",
      "call_id": "call_UTYO3lPU4b3mt90Aes1MjPle",
      "name": "retrieve_payment_intent",
      "type": "function_call",
      "id": "fc_687f970c3e8c8191a25f81365010a29a0a3349a30bf8c3a5",
      "status": "completed"
    },
    {
      "call_id": "call_UTYO3lPU4b3mt90Aes1MjPle",
      "output": "{\n  \"amount\": 2000,\n  \"amount_capturable\": 0,\n  \"amount_details\": {\n    \"tip\": {}\n  },\n  \"amount_received\": 2000,\n  \"application\": null,\n  \"application_fee_amount\": null,\n  \"automatic_payment_methods\": {\n    \"allow_redirects\": \"always\",\n    \"enabled\": true\n  },\n  \"canceled_at\": null,\n  \"cancellation_reason\": null,\n  \"capture_method\": \"automatic_async\",\n  \"client_secret\": \"pi_3RngVxQuMzbiv2kf1qfcy34X_secret_FuyAdGh94lLsssgNnKe2e7oKx\",\n  \"confirmation_method\": \"automatic\",\n  \"created\": 1753191953,\n  \"currency\": \"usd\",\n  \"customer\": null,\n  \"description\": null,\n  \"id\": \"pi_3RngVxQuMzbiv2kf1qfcy34X\",\n  \"last_payment_error\": null,\n  \"latest_charge\": \"ch_3RngVxQuMzbiv2kf1zQ9coOo\",\n  \"livemode\": false,\n  \"metadata\": {\n    \"order_id\": \"1234\"\n  },\n  \"next_action\": null,\n  \"object\": \"payment_intent\",\n  \"on_behalf_of\": null,\n  \"payment_method\": \"pm_1RngVwQuMzbiv2kfsyFBt3Iu\",\n  \"payment_method_configuration_details\": {\n    \"id\": \"pmc_1RlmnJQuMzbiv2kfOw1kPhMl\",\n    \"parent\": null\n  },\n  \"payment_method_options\": {\n    \"amazon_pay\": {\n      \"express_checkout_element_session_id\": null\n    },\n    \"card\": {\n      \"installments\": null,\n      \"mandate_options\": null,\n      \"network\": null,\n      \"request_three_d_secure\": \"automatic\"\n    },\n    \"link\": {\n      \"persistent_token\": null\n    }\n  },\n  \"payment_method_types\": [\n    \"card\",\n    \"link\",\n    \"amazon_pay\"\n  ],\n  \"processing\": null,\n  \"receipt_email\": null,\n  \"review\": null,\n  \"setup_future_usage\": null,\n  \"shipping\": null,\n  \"source\": null,\n  \"statement_descriptor\": null,\n  \"statement_descriptor_suffix\": null,\n  \"status\": \"succeeded\",\n  \"transfer_data\": null,\n  \"transfer_group\": null\n}",
      "type": "function_call_output"
    },
    {
      "arguments": "{\"order_id\":1234}",
      "call_id": "call_aH4uuFY9Py3B8voBDvJqxjxP",
      "name": "get_order",
      "type": "function_call",
      "id": "fc_687f970defd88191b1ee5e5c7ededc950a3349a30bf8c3a5",
      "status": "completed"
    },
    {
      "call_id": "call_aH4uuFY9Py3B8voBDvJqxjxP",
      "output": "{'order_id': 1234, 'fulfillment_details': 'not_shipped'}",
      "type": "function_call_output"
    }
  ],
  "instructions": "Please do the following:\n1. Find the order ID from the payment intent's metadata.\n2. Retrieve detailed information about the order (e.g., shipping status).\n3. If the order has shipped, escalate this dispute to the investigator agent.\n4. If the order has not shipped, accept the dispute.\n",
  "model": "gpt-4o",
  "stream": false,
  "tools": [<same_as_above>]
}
DEBUG:openai.agents:LLM resp:
[
  {
    "arguments": "{}",
    "call_id": "call_9AP4RbNZXJWP3W9JC2rV6YhB",
    "name": "transfer_to_accept_dispute_agent",
    "type": "function_call",
    "id": "fc_687f970eebb881918b12d6ea5e4e668c0a3349a30bf8c3a5",
    "status": "completed"
  }
]

Turn 4 (Accept Dispute Agent)

DEBUG:openai.agents:Running agent Accept Dispute Agent (turn 4)
...
DEBUG:openai._base_client:Sending HTTP Request: POST https://api.openai.com/v1/responses
{
  "include": [],
  "input": [
    {
      "content": "{\"dispute_id\": \"dp_1RngVxQuMzbiv2kflcD3SYfK\", \"amount\": 2000, \"due_by\": 1754006399, \"payment_intent\": \"pi_3RngVxQuMzbiv2kf1qfcy34X\", \"reason\": \"product_not_received\", \"status\": \"needs_response\", \"card_brand\": \"visa\"}",
      "role": "user"
    },
    {
      "arguments": "{\"payment_intent_id\":\"pi_3RngVxQuMzbiv2kf1qfcy34X\"}",
      "call_id": "call_UTYO3lPU4b3mt90Aes1MjPle",
      "name": "retrieve_payment_intent",
      "type": "function_call",
      "id": "fc_687f970c3e8c8191a25f81365010a29a0a3349a30bf8c3a5",
      "status": "completed"
    },
    {
      "call_id": "call_UTYO3lPU4b3mt90Aes1MjPle",
      "output": "{\n  \"amount\": 2000,\n  \"amount_capturable\": 0,\n  \"amount_details\": {\n    \"tip\": {}\n  },\n  \"amount_received\": 2000,\n  \"application\": null,\n  \"application_fee_amount\": null,\n  \"automatic_payment_methods\": {\n    \"allow_redirects\": \"always\",\n    \"enabled\": true\n  },\n  \"canceled_at\": null,\n  \"cancellation_reason\": null,\n  \"capture_method\": \"automatic_async\",\n  \"client_secret\": \"pi_3RngVxQuMzbiv2kf1qfcy34X_secret_FuyAdGh94lLsssgNnKe2e7oKx\",\n  \"confirmation_method\": \"automatic\",\n  \"created\": 1753191953,\n  \"currency\": \"usd\",\n  \"customer\": null,\n  \"description\": null,\n  \"id\": \"pi_3RngVxQuMzbiv2kf1qfcy34X\",\n  \"last_payment_error\": null,\n  \"latest_charge\": \"ch_3RngVxQuMzbiv2kf1zQ9coOo\",\n  \"livemode\": false,\n  \"metadata\": {\n    \"order_id\": \"1234\"\n  },\n  \"next_action\": null,\n  \"object\": \"payment_intent\",\n  \"on_behalf_of\": null,\n  \"payment_method\": \"pm_1RngVwQuMzbiv2kfsyFBt3Iu\",\n  \"payment_method_configuration_details\": {\n    \"id\": \"pmc_1RlmnJQuMzbiv2kfOw1kPhMl\",\n    \"parent\": null\n  },\n  \"payment_method_options\": {\n    \"amazon_pay\": {\n      \"express_checkout_element_session_id\": null\n    },\n    \"card\": {\n      \"installments\": null,\n      \"mandate_options\": null,\n      \"network\": null,\n      \"request_three_d_secure\": \"automatic\"\n    },\n    \"link\": {\n      \"persistent_token\": null\n    }\n  },\n  \"payment_method_types\": [\n    \"card\",\n    \"link\",\n    \"amazon_pay\"\n  ],\n  \"processing\": null,\n  \"receipt_email\": null,\n  \"review\": null,\n  \"setup_future_usage\": null,\n  \"shipping\": null,\n  \"source\": null,\n  \"statement_descriptor\": null,\n  \"statement_descriptor_suffix\": null,\n  \"status\": \"succeeded\",\n  \"transfer_data\": null,\n  \"transfer_group\": null\n}",
      "type": "function_call_output"
    },
    {
      "arguments": "{\"order_id\":1234}",
      "call_id": "call_aH4uuFY9Py3B8voBDvJqxjxP",
      "name": "get_order",
      "type": "function_call",
      "id": "fc_687f970defd88191b1ee5e5c7ededc950a3349a30bf8c3a5",
      "status": "completed"
    },
    {
      "call_id": "call_aH4uuFY9Py3B8voBDvJqxjxP",
      "output": "{'order_id': 1234, 'fulfillment_details': 'not_shipped'}",
      "type": "function_call_output"
    },
    {
      "arguments": "{}",
      "call_id": "call_9AP4RbNZXJWP3W9JC2rV6YhB",
      "name": "transfer_to_accept_dispute_agent",
      "type": "function_call",
      "id": "fc_687f970eebb881918b12d6ea5e4e668c0a3349a30bf8c3a5",
      "status": "completed"
    },
    {
      "call_id": "call_9AP4RbNZXJWP3W9JC2rV6YhB",
      "output": "{\"assistant\": \"Accept Dispute Agent\"}",
      "type": "function_call_output"
    }
  ],
  "instructions": "You are an agent responsible for accepting disputes. Please do the following:\n1. Use the provided dispute ID to close the dispute.\n2. Provide a short explanation of why the dispute is being accepted.\n3. Reference any relevant order details (e.g., unfulfilled order, etc.) retrieved from the database.\n\nThen, produce your final output in this exact format:\n\nDispute Details:\n- Dispute ID\n- Amount\n- Reason for Dispute\n\nOrder Details:\n- Fulfillment status of the order\n\nReasoning for closing the dispute\n",
  "model": "gpt-4o",
  "stream": false,
  "tools": [
    {
      "name": "close_dispute",
      "parameters": {
        "properties": {
          "dispute_id": {
            "title": "Dispute Id",
            "type": "string"
          }
        },
        "required": [
          "dispute_id"
        ],
        "title": "close_dispute_args",
        "type": "object",
        "additionalProperties": false
      },
      "strict": true,
      "type": "function",
      "description": "Close a Stripe dispute by ID.\nReturns the dispute object on success or an empty dictionary on failure."
    }
  ]
}
DEBUG:openai.agents:LLM resp:
[
  {
    "arguments": "{\"dispute_id\":\"dp_1RngVxQuMzbiv2kflcD3SYfK\"}",
    "call_id": "call_6Y8Mda7AuefchFFEBLf5TQQE",
    "name": "close_dispute",
    "type": "function_call",
    "id": "fc_687f970fcfb08191a3ebbce355dee8b10a3349a30bf8c3a5",
    "status": "completed"
  }
]
DEBUG:openai.agents:Tool close_dispute returned
{
  "amount": 2000,
  "balance_transaction": "txn_1RngVxQuMzbiv2kf1cwRKdpG",
  "balance_transactions": [
    {
      "amount": -2000,
      "available_on": 1753191953,
      "balance_type": "payments",
      "created": 1753191953,
      "currency": "eur",
      "description": "Chargeback withdrawal for ch_3RngVxQuMzbiv2kf1zQ9coOo",
      "exchange_rate": null,
      "fee": 2000,
      "fee_details": [
        {
          "amount": 2000,
          "application": null,
          "currency": "eur",
          "description": "Dispute fee",
          "type": "stripe_fee"
        }
      ],
      "id": "txn_1RngVxQuMzbiv2kf1cwRKdpG",
      "net": -4000,
      "object": "balance_transaction",
      "reporting_category": "dispute",
      "source": "dp_1RngVxQuMzbiv2kflcD3SYfK",
      "status": "available",
      "type": "adjustment"
    }
  ],
  "charge": "ch_3RngVxQuMzbiv2kf1zQ9coOo",
  "created": 1753191953,
  "currency": "usd",
  "enhanced_eligibility_types": [],
  "evidence": {
    "access_activity_log": null,
    "billing_address": null,
    "cancellation_policy": null,
    "cancellation_policy_disclosure": null,
    "cancellation_rebuttal": null,
    "customer_communication": null,
    "customer_email_address": null,
    "customer_name": null,
    "customer_purchase_ip": null,
    "customer_signature": null,
    "duplicate_charge_documentation": null,
    "duplicate_charge_explanation": null,
    "duplicate_charge_id": null,
    "enhanced_evidence": {},
    "product_description": null,
    "receipt": null,
    "refund_policy": null,
    "refund_policy_disclosure": null,
    "refund_refusal_explanation": null,
    "service_date": null,
    "service_documentation": null,
    "shipping_address": null,
    "shipping_carrier": null,
    "shipping_date": null,
    "shipping_documentation": null,
    "shipping_tracking_number": null,
    "uncategorized_file": null,
    "uncategorized_text": null
  },
  "evidence_details": {
    "due_by": 1754006399,
    "enhanced_eligibility": {},
    "has_evidence": false,
    "past_due": false,
    "submission_count": 0
  },
  "id": "dp_1RngVxQuMzbiv2kflcD3SYfK",
  "is_charge_refundable": false,
  "livemode": false,
  "metadata": {},
  "object": "dispute",
  "payment_intent": "pi_3RngVxQuMzbiv2kf1qfcy34X",
  "payment_method_details": {
    "card": {
      "brand": "visa",
      "case_type": "chargeback",
      "network_reason_code": "13.1"
    },
    "type": "card"
  },
  "reason": "product_not_received",
  "status": "lost"
}

Turn 5 (Accept Dispute Agent)

DEBUG:openai.agents:Running agent Accept Dispute Agent (turn 5)
...
DEBUG:openai._base_client:Sending HTTP Request: POST https://api.openai.com/v1/responses
{
  "include": [],
  "input": [
    {
      "content": "{\"dispute_id\": \"dp_1RngVxQuMzbiv2kflcD3SYfK\", \"amount\": 2000, \"due_by\": 1754006399, \"payment_intent\": \"pi_3RngVxQuMzbiv2kf1qfcy34X\", \"reason\": \"product_not_received\", \"status\": \"needs_response\", \"card_brand\": \"visa\"}",
      "role": "user"
    },
    {
      "arguments": "{\"payment_intent_id\":\"pi_3RngVxQuMzbiv2kf1qfcy34X\"}",
      "call_id": "call_UTYO3lPU4b3mt90Aes1MjPle",
      "name": "retrieve_payment_intent",
      "type": "function_call",
      "id": "fc_687f970c3e8c8191a25f81365010a29a0a3349a30bf8c3a5",
      "status": "completed"
    },
    {
      "call_id": "call_UTYO3lPU4b3mt90Aes1MjPle",
      "output": "{\n  \"amount\": 2000,\n  \"amount_capturable\": 0,\n  \"amount_details\": {\n    \"tip\": {}\n  },\n  \"amount_received\": 2000,\n  \"application\": null,\n  \"application_fee_amount\": null,\n  \"automatic_payment_methods\": {\n    \"allow_redirects\": \"always\",\n    \"enabled\": true\n  },\n  \"canceled_at\": null,\n  \"cancellation_reason\": null,\n  \"capture_method\": \"automatic_async\",\n  \"client_secret\": \"pi_3RngVxQuMzbiv2kf1qfcy34X_secret_FuyAdGh94lLsssgNnKe2e7oKx\",\n  \"confirmation_method\": \"automatic\",\n  \"created\": 1753191953,\n  \"currency\": \"usd\",\n  \"customer\": null,\n  \"description\": null,\n  \"id\": \"pi_3RngVxQuMzbiv2kf1qfcy34X\",\n  \"last_payment_error\": null,\n  \"latest_charge\": \"ch_3RngVxQuMzbiv2kf1zQ9coOo\",\n  \"livemode\": false,\n  \"metadata\": {\n    \"order_id\": \"1234\"\n  },\n  \"next_action\": null,\n  \"object\": \"payment_intent\",\n  \"on_behalf_of\": null,\n  \"payment_method\": \"pm_1RngVwQuMzbiv2kfsyFBt3Iu\",\n  \"payment_method_configuration_details\": {\n    \"id\": \"pmc_1RlmnJQuMzbiv2kfOw1kPhMl\",\n    \"parent\": null\n  },\n  \"payment_method_options\": {\n    \"amazon_pay\": {\n      \"express_checkout_element_session_id\": null\n    },\n    \"card\": {\n      \"installments\": null,\n      \"mandate_options\": null,\n      \"network\": null,\n      \"request_three_d_secure\": \"automatic\"\n    },\n    \"link\": {\n      \"persistent_token\": null\n    }\n  },\n  \"payment_method_types\": [\n    \"card\",\n    \"link\",\n    \"amazon_pay\"\n  ],\n  \"processing\": null,\n  \"receipt_email\": null,\n  \"review\": null,\n  \"setup_future_usage\": null,\n  \"shipping\": null,\n  \"source\": null,\n  \"statement_descriptor\": null,\n  \"statement_descriptor_suffix\": null,\n  \"status\": \"succeeded\",\n  \"transfer_data\": null,\n  \"transfer_group\": null\n}",
      "type": "function_call_output"
    },
    {
      "arguments": "{\"order_id\":1234}",
      "call_id": "call_aH4uuFY9Py3B8voBDvJqxjxP",
      "name": "get_order",
      "type": "function_call",
      "id": "fc_687f970defd88191b1ee5e5c7ededc950a3349a30bf8c3a5",
      "status": "completed"
    },
    {
      "call_id": "call_aH4uuFY9Py3B8voBDvJqxjxP",
      "output": "{'order_id': 1234, 'fulfillment_details': 'not_shipped'}",
      "type": "function_call_output"
    },
    {
      "arguments": "{}",
      "call_id": "call_9AP4RbNZXJWP3W9JC2rV6YhB",
      "name": "transfer_to_accept_dispute_agent",
      "type": "function_call",
      "id": "fc_687f970eebb881918b12d6ea5e4e668c0a3349a30bf8c3a5",
      "status": "completed"
    },
    {
      "call_id": "call_9AP4RbNZXJWP3W9JC2rV6YhB",
      "output": "{\"assistant\": \"Accept Dispute Agent\"}",
      "type": "function_call_output"
    },
    {
      "arguments": "{\"dispute_id\":\"dp_1RngVxQuMzbiv2kflcD3SYfK\"}",
      "call_id": "call_6Y8Mda7AuefchFFEBLf5TQQE",
      "name": "close_dispute",
      "type": "function_call",
      "id": "fc_687f970fcfb08191a3ebbce355dee8b10a3349a30bf8c3a5",
      "status": "completed"
    },
    {
      "call_id": "call_6Y8Mda7AuefchFFEBLf5TQQE",
      "output": "{\n  \"amount\": 2000,\n  \"balance_transaction\": \"txn_1RngVxQuMzbiv2kf1cwRKdpG\",\n  \"balance_transactions\": [\n    {\n      \"amount\": -2000,\n      \"available_on\": 1753191953,\n      \"balance_type\": \"payments\",\n      \"created\": 1753191953,\n      \"currency\": \"eur\",\n      \"description\": \"Chargeback withdrawal for ch_3RngVxQuMzbiv2kf1zQ9coOo\",\n      \"exchange_rate\": null,\n      \"fee\": 2000,\n      \"fee_details\": [\n        {\n          \"amount\": 2000,\n          \"application\": null,\n          \"currency\": \"eur\",\n          \"description\": \"Dispute fee\",\n          \"type\": \"stripe_fee\"\n        }\n      ],\n      \"id\": \"txn_1RngVxQuMzbiv2kf1cwRKdpG\",\n      \"net\": -4000,\n      \"object\": \"balance_transaction\",\n      \"reporting_category\": \"dispute\",\n      \"source\": \"dp_1RngVxQuMzbiv2kflcD3SYfK\",\n      \"status\": \"available\",\n      \"type\": \"adjustment\"\n    }\n  ],\n  \"charge\": \"ch_3RngVxQuMzbiv2kf1zQ9coOo\",\n  \"created\": 1753191953,\n  \"currency\": \"usd\",\n  \"enhanced_eligibility_types\": [],\n  \"evidence\": {\n    \"access_activity_log\": null,\n    \"billing_address\": null,\n    \"cancellation_policy\": null,\n    \"cancellation_policy_disclosure\": null,\n    \"cancellation_rebuttal\": null,\n    \"customer_communication\": null,\n    \"customer_email_address\": null,\n    \"customer_name\": null,\n    \"customer_purchase_ip\": null,\n    \"customer_signature\": null,\n    \"duplicate_charge_documentation\": null,\n    \"duplicate_charge_explanation\": null,\n    \"duplicate_charge_id\": null,\n    \"enhanced_evidence\": {},\n    \"product_description\": null,\n    \"receipt\": null,\n    \"refund_policy\": null,\n    \"refund_policy_disclosure\": null,\n    \"refund_refusal_explanation\": null,\n    \"service_date\": null,\n    \"service_documentation\": null,\n    \"shipping_address\": null,\n    \"shipping_carrier\": null,\n    \"shipping_date\": null,\n    \"shipping_documentation\": null,\n    \"shipping_tracking_number\": null,\n    \"uncategorized_file\": null,\n    \"uncategorized_text\": null\n  },\n  \"evidence_details\": {\n    \"due_by\": 1754006399,\n    \"enhanced_eligibility\": {},\n    \"has_evidence\": false,\n    \"past_due\": false,\n    \"submission_count\": 0\n  },\n  \"id\": \"dp_1RngVxQuMzbiv2kflcD3SYfK\",\n  \"is_charge_refundable\": false,\n  \"livemode\": false,\n  \"metadata\": {},\n  \"object\": \"dispute\",\n  \"payment_intent\": \"pi_3RngVxQuMzbiv2kf1qfcy34X\",\n  \"payment_method_details\": {\n    \"card\": {\n      \"brand\": \"visa\",\n      \"case_type\": \"chargeback\",\n      \"network_reason_code\": \"13.1\"\n    },\n    \"type\": \"card\"\n  },\n  \"reason\": \"product_not_received\",\n  \"status\": \"lost\"\n}",
      "type": "function_call_output"
    }
  ],
  "instructions": "You are an agent responsible for accepting disputes. Please do the following:\n1. Use the provided dispute ID to close the dispute.\n2. Provide a short explanation of why the dispute is being accepted.\n3. Reference any relevant order details (e.g., unfulfilled order, etc.) retrieved from the database.\n\nThen, produce your final output in this exact format:\n\nDispute Details:\n- Dispute ID\n- Amount\n- Reason for Dispute\n\nOrder Details:\n- Fulfillment status of the order\n\nReasoning for closing the dispute\n",
  "model": "gpt-4o",
  "stream": false,
  "tools": [<same_as_above>]
}
DEBUG:openai.agents:LLM resp:
[
  {
    "id": "msg_687f97118ed48191bf3ce12c8578bbb40a3349a30bf8c3a5",
    "content": [
      {
        "annotations": [],
        "text": "Dispute Details:\n- Dispute ID: dp_1RngVxQuMzbiv2kflcD3SYfK\n- Amount: $2000\n- Reason for Dispute: Product not received\n\nOrder Details:\n- Fulfillment status of the order: Not shipped\n\nReasoning for closing the dispute:\nThe dispute was accepted and closed in favor of the customer because the order was not shipped, validating the claim of the product not being received.",
        "type": "output_text",
        "logprobs": []
      }
    ],
    "role": "assistant",
    "status": "completed",
    "type": "message"
  }
]

And here is the final report:

Dispute Details:
- Dispute ID: dp_1RngVxQuMzbiv2kflcD3SYfK
- Amount: $2000
- Reason for Dispute: Product not received

Order Details:
- Fulfillment status of the order: Not shipped

Reasoning for closing the dispute:
The dispute was accepted and closed in favor of the customer because
the order was not shipped, validating the claim of the product not
being received.

(Probably, the amount should be $20.)

That's all I have for today! Talk soon 👋

Recent posts
latestHow I crafted TL;DRs with LLMs and modernized my blog (part 5)
See how impressed I was by GPT-4.1's meta descriptions
prompt
How I crafted TL;DRs with LLMs and modernized my blog (part 4)
Check how I optimized images for better blog performance
code
How I explored Google Sheets to Gmail automation through Zapier before building it in Python (part 1)
See how I built my first Zapier Gmail alert from Sheets updates
no-code
How I realized AI automation is all about what you automate
Check my favorite CRM AI automation (so far) from Zapier blog
misc
Curious about the tools I use?