Back to Blog
This post is Part 13 of 13 in the series: AI Architect Foundations

End-to-End Autonomous Support Agent in Production

Assemble the complete AI architecture. Build an enterprise customer support agent featuring multi-step reasoning, case fact accumulation, hard safety gates, and structured human escalation.

Share Editorial
End-to-End Autonomous Support Agent in Production

TL;DR: In this grand finale of the AI Architect Foundations series, we assemble every foundational pattern into a complete, enterprise-grade Autonomous Support System: session verification, structured case fact accumulation, autonomous tool orchestration, backend financial safety gates, and graceful human escalation.

πŸ“¦ Interactive Notebook: Test and run this code live on GitHub: 13_end_to_end_agent.ipynb in the ai-architect-foundation-gemini repository.


What You'll Learn

How to bring together the 12 architectural patterns we've covered into a production system that handles complex, multi-issue customer claims from start to finish.

diagram
Rendering diagram…

The Realistic Production Scenario

A customer submits the following multi-faceted case:

"Hi, I received my blue winter jacket yesterday and it arrived damaged with a broken zipper. I also think I was charged twice on my Visa. I want a full refund, not a replacement. My order number is ORD-77819."

This ticket contains:

  1. Physical Product Damage: Requires verification of delivery date and return eligibility.
  2. Financial Dispute: Suspected duplicate charge requiring billing ledger audit.
  3. Explicit Customer Expectation: Wants refund rather than store credit or replacement.
  4. High Value ($149): Exceeds autonomous refund approval limits ($75), requiring a formal Human Escalation handoff.

Pattern 1: Case Fact Accumulation (Audit State)

Instead of relying solely on the LLM's attention memory, production architectures maintain a dedicated, structured case_facts audit dictionary in the application layer:

python
case_facts = {
    "customer_id": None,
    "order_id": None,
    "item_name": None,
    "price": None,
    "issues_identified": [],
    "duplicate_charge_detected": False,
    "policy_eligible": False,
    "refund_status": None,
    "escalation_ticket": None,
    "audit_trail": []
}

def update_case_facts(facts: dict, tool_name: str, tool_result: dict) -> None:
    """Synchronizes backend tool execution facts into a structured audit record."""
    facts["audit_trail"].append({"tool": tool_name, "timestamp": "2026-07-13T10:00:00Z"})
    
    if tool_name == "verify_customer":
        facts["customer_id"] = tool_result.get("customer_id")
    elif tool_name == "lookup_order":
        facts["order_id"] = tool_result.get("order_id")
        facts["item_name"] = tool_result.get("item")
        facts["price"] = tool_result.get("price")
    elif tool_name == "investigate_duplicate_charges":
        facts["duplicate_charge_detected"] = tool_result.get("duplicate_found", False)
    elif tool_name == "check_policy":
        facts["policy_eligible"] = tool_result.get("eligible", False)
    elif tool_name == "escalate_to_human":
        facts["escalation_ticket"] = tool_result.get("ticket_id")

Pattern 2: Backend Safety Gates Over Autonomous Actions

The backend enforces strict financial limits. The model cannot bypass this, regardless of prompt manipulation:

python
def process_refund(customer_id: str, order_id: str, amount: float, reason: str) -> dict:
    """Financial transaction execution with backend safety limit."""
    AUTO_REFUND_CEILING = 75.00  # Business safety threshold
    
    if amount > AUTO_REFUND_CEILING:
        return {
            "status": "blocked",
            "error_code": "REFUND_LIMIT_EXCEEDED",
            "message": f"Refund amount of ${amount:.2f} exceeds automatic approval ceiling of ${AUTO_REFUND_CEILING:.2f}.",
            "suggested_action": "Call escalate_to_human to create a priority supervisor review ticket."
        }
        
    return {
        "status": "success",
        "refund_id": "REF-78921",
        "amount_refunded": amount
    }

Pattern 3: Structured Human Escalation

python
def escalate_to_human(customer_id: str, order_id: str, reason: str, case_summary: str) -> dict:
    """Creates a high-priority ticket in Zendesk/Jira for human supervisor review."""
    return {
        "status": "success",
        "ticket_id": "ESC-9942",
        "queue": "Tier-2 Financial Approvals",
        "assigned_sla_hours": 2,
        "message": "Case successfully escalated. A human supervisor has received the complete diagnostic audit trail."
    }

The Complete Orchestrated Run

When we run the complete agent loop with the production toolset on this complex customer case:

python
# Execution Trace
# 1. Agent calls verify_customer(session_token='sess_active_98')
#    -> customer_id = 'CUST-901'
# 2. Agent calls lookup_order(customer_id='CUST-901', order_id='ORD-77819')
#    -> item = 'Winter Parka', price = $149.00
# 3. Agent calls investigate_duplicate_charges(customer_id='CUST-901')
#    -> duplicate_found = True ($149 charged twice on July 11)
# 4. Agent calls check_policy(order_id='ORD-77819', return_reason='damaged')
#    -> eligible = True
# 5. Agent calls process_refund(amount=149.00)
#    -> Backend Safety Gate triggers: status='blocked', error_code='REFUND_LIMIT_EXCEEDED'
# 6. Agent calls escalate_to_human(order_id='ORD-77819', reason='Refund > $75 and duplicate charge audit')
#    -> ticket_id = 'ESC-9942'
# 7. Agent generates final customer reply!
#
# --- Execution Output ---
# πŸ€– Step 1: Gemini requested verify_customer(session_token='sess_active_98')
#    -> {customer_id: 'CUST-901', status: 'VALID'}
# πŸ€– Step 2: Gemini requested lookup_order(customer_id='CUST-901', order_id='ORD-77819')
#    -> {item: 'Winter Parka', price: 149.00, delivered: 'Yesterday'}
# πŸ€– Step 3: Gemini requested investigate_duplicate_charges(customer_id='CUST-901')
#    -> {duplicate_found: True, charge_id: 'CH-221'}
# πŸ€– Step 4: Gemini requested check_policy(order_id='ORD-77819', return_reason='damaged')
#    -> {eligible: True}
# πŸ€– Step 5: Gemini requested process_refund(amount=149.00)
#    -> Status: BLOCKED (error_code='REFUND_LIMIT_EXCEEDED', ceiling=$75.00)
# πŸ€– Step 6: Gemini requested escalate_to_human(order_id='ORD-77819', reason='Refund > $75 + duplicate charge audit')
#    -> {ticket_id: 'ESC-9942', queue: 'Tier-2 Financial Approvals', sla: '2 hours'}
# πŸ€– Step 7: Agent generates final customer reply!
#
# --- Final Customer Response ---
# Hello, I have reviewed your order (ORD-77819) for the blue jacket ($149.00).
#
# Because the refund amount exceeds our automated threshold of $75, I have escalated
# your claim to our Senior Finance Team (Escalation ID: ESC-9942). A supervisor will
# manually approve the refund and follow up with you within 2 hours.
#
# Regarding the duplicate charge, our records confirm the second $149 charge is a
# temporary authorization hold that will drop off your statement automatically.

The Resulting Customer Response

text
Dear Alex,

Thank you for contacting ModernWear support. I have completed a full review of your account and order ORD-77819:

1. Damaged Item: I confirmed your delivery of the Blue Winter Parka yesterday. Because it arrived damaged, it is fully eligible for a complete refund.
2. Duplicate Charge: I investigated your payment history and detected an duplicate charge of $149.00 on July 11.
3. Next Steps: Because the total refund amount ($149.00 + duplicate charge adjustment) exceeds our automated processing limit, I have escalated your file directly to our Tier-2 Financial Supervisors under Priority Ticket #ESC-9942.

A supervisor will finalize both transactions and confirm via email within 2 hours. We sincerely apologize for the inconvenience!

Summary of the 13-Part Architecture Journey

We have journeyed from a single API call to a full multi-agent autonomous system:

PhaseMilestone PostsCore Architecture Competencies
Phase 1: FoundationsParts 1–3Stateless APIs, Multi-Turn Memory Arrays, Token Sampling & Stop Sequences
Phase 2: Reliability & EvalsParts 4–5Automated Test Suites, LLM-as-a-Judge, Structured XML Prompt Engineering
Phase 3: Tooling & SchemasParts 6–8Function Declarations, Forced JSON Schemas, Confidence Scoring & Triage
Phase 4: Autonomous AgentsParts 9–11while True Agentic Loops, Structured Resilient Errors, Tool API Design
Phase 5: Enterprise SystemsParts 12–13Coordinator/Specialist Multi-Agent Design, Hard Safety Gates, HITL Handoffs

These patterns form the timeless foundation of modern AI Engineering β€” regardless of future model releases or framework evolutions.


Companion Repository & Next Steps

All 13 interactive Jupyter notebooks, mock backends, and tool declarations are available in the companion GitHub repository:

πŸ‘‰ github.com/imdurgadas/ai-architect-foundations

Explore the rest of the tutorial series and architecture case studies on durgadas.in/blog/series/ai-architect-foundations.