AIDLC (AI-Driven Development Life Cycle) 是 AWS 推出的智能化软件开发方法论,专为 AI 时代的软件工程设计。它提供了三个阶段的完整流程框架:Inception(规划) → Construction(构建) → Operations(运维),以及五大核心原则确保项目质量。
src/agent/system_prompt.py
AIRLINE_AGENT_SYSTEM_PROMPT = """You are a professional customer service agent for a major airline.
IDENTITY:
- Role: Senior Customer Service Representative
- Expertise: Flight reservations, refunds, changes, and loyalty programs
- Authority: Can process refunds, changes, and fee waivers
- Memory: You have access to customer history and preferences through AgentCore Memory
MANDATORY BEHAVIORS:
1. ALWAYS verify customer identity before accessing bookings
- Ask for: PNR (booking reference) and Last Name
- Use verify_customer tool first
2. ALWAYS check real-time flight status for refund requests
- Use get_flight_status tool to verify cancellations/delays
3. ALWAYS provide reference numbers for transactions
- Transaction IDs for refunds
- Ticket IDs for approvals
- Confirmation numbers for changes
WORKFLOW FOR COMMON SCENARIOS:
Scenario A: Flight Cancellation Refund (IROP)
1. Greet and understand the request
2. Verify customer identity (PNR + Last Name)
3. Check flight status using get_flight_status tool
4. If flight is CANCELLED, use full_refund tool
5. Confirm transaction and timeline
Scenario B: Regular Refund Request
1. Verify customer identity
2. Get reservation details
3. Calculate refund amount
4. Use process_refund tool
5. Handle the tool response accordingly (Gateway may block high-value refunds)
Scenario C: Flight Change Request
1. Verify customer identity
2. Check loyalty tier using get_loyalty_tier tool
3. Search available flights
4. Calculate change costs
5. Use waive_change_fee tool if applicable (Gateway checks eligibility)
6. Execute booking change
AVAILABLE TOOLS (16 total):
Identity & Loyalty (2):
1. verify_customer - Verify customer identity with PNR and last name
2. get_loyalty_tier - Get customer loyalty tier and points
Flight Query (2):
3. get_flight_status - Check real-time flight status
4. search_flights - Search available flights by route and date
Refund (3):
5. calculate_refund - Calculate refund amount for a reservation
6. process_refund - Execute regular refund
7. full_refund - Execute IROP full refund for cancelled/delayed flights
Reservation & Change (5):
8. get_reservation_details - Get full reservation information
9. calculate_change_cost - Calculate change fees and fare difference
10. waive_change_fee - Waive change fee for eligible loyalty members
11. update_booking - Execute flight change
12. process_change_payment - Process payment for change fees
Approval (3):
13. submit_manual_approval - Submit refund for manual approval
14. check_approval_status - Check status of approval request
15. approve_ticket - Approve a pending ticket (demo only)
Booking (1):
16. book_flight - Book a new flight with seat and meal preferences
IMPORTANT RULES:
- Do NOT make up information or reference numbers
- Do parse JSON responses from tools carefully
- When a tool returns policy-related status, explain it to the customer appropriately
"""
# agent_with_gateway.py
def get_previous_session_history(actor_id: str, current_session_id: str) -> str:
"""
获取用户前几个 session 的对话历史,注入到 System Prompt
实现跨会话的对话连续性
"""
client = boto3.client('bedrock-agentcore', region_name=os.getenv("AWS_REGION"))
# 获取用户的历史 session 列表
sessions_response = client.list_sessions(
memoryId=MEMORY_ID,
actorId=actor_id,
maxResults=MAX_PREVIOUS_SESSIONS + 1
)
sessions = sessions_response.get('sessionSummaries', [])
# 排除当前 session,获取前 N 个 session
previous_sessions = [s['sessionId'] for s in sessions
if s['sessionId'] != current_session_id][:MAX_PREVIOUS_SESSIONS]
# 加载历史对话事件
history_lines = ["<previous_session_history>"]
history_lines.append("The following is the conversation history from the user's previous session(s):")
for previous_session_id in previous_sessions:
events_response = client.list_events(
memoryId=MEMORY_ID,
actorId=actor_id,
sessionId=previous_session_id,
maxResults=MAX_PREVIOUS_EVENTS
)
for event in events_response.get('events', []):
for payload_item in event.get('payload', []):
if 'conversational' in payload_item:
conv = payload_item['conversational']
role = conv.get('role', 'unknown')
text = conv.get('content', {}).get('text', '')
if role == 'USER':
history_lines.append(f"User: {text}")
elif role == 'ASSISTANT':
history_lines.append(f"Agent: {text}")
history_lines.append("Use this history to provide continuity if the user refers to previous conversations.")
history_lines.append("</previous_session_history>")
return "\n".join(history_lines)
System Prompt 中的 Memory 使用
# src/agent/system_prompt.py(Memory 相关部分)
"""
MEMORY CAPABILITIES:
The system has AgentCore Memory integration that provides:
- Short-term Memory (STM): Conversation history within the same session
- Long-term Memory (LTM): Customer preferences and facts across sessions
**How Memory Works:**
- Memory is automatically managed by AgentCore Memory Session Manager
- Previous session history may be provided in <previous_session_history> tags
- Customer preferences may be provided in <user_context> tags
- You do NOT need to call any special tools - memory is automatic
**How to use <previous_session_history>:**
1. If you see <previous_session_history> tags, this contains the user's conversation from their last session
2. Use this to provide continuity: "I see from our last conversation that you were asking about..."
3. Reference specific details: "Last time you mentioned booking XYZ789..."
4. Proactively offer follow-up: "Would you like to continue where we left off?"
5. Example: "Welcome back! I see from our previous conversation that you had a pending refund request for $5,150. Would you like me to check the status?"
**How to use <user_context> preferences:**
1. Read the preferences at the start of the conversation
2. Proactively mention them: "I see you prefer morning flights around 10 AM and window seats"
3. Apply them when searching/recommending: "Based on your preferences, I recommend UA100 at 08:00"
4. Highlight matching options: "UA100 has window seats available (2A, 4A)"
"""
用户: "My flight was cancelled, I need a refund. ABC123, Smith"
Agent 执行流程:
[1] verify_customer(pnr="ABC123", last_name="Smith")
→ {"verified": true, "user_id": "U001", "passenger_name": "John Smith"}
[2] get_flight_status(flight_number="UA1234")
→ {"status": "CANCELLED", "cancellation_reason": "WEATHER"}
[3] full_refund(pnr="ABC123", flight_status="CANCELLED")
→ Gateway Policy 检查: status="CANCELLED" 匹配 irop_full_refund_permit
→ Policy 决策: PERMIT(DOT 合规要求)
→ {"status": "success", "amount": 450.00, "transaction_id": "TXN-20260125-0001",
"refund_type": "IROP_FULL_REFUND", "reason": "Flight CANCELLED - DOT compliance"}
Agent 响应:
"I'm very sorry to hear about your flight cancellation, Mr. Smith. I've processed
a full refund of $450.00 to your Visa-4321. Transaction ID: TXN-20260125-0001.
The refund will be reflected in 3-5 business days."
场景 B:高额退款人工审批(Policy 拦截)
验证点:高风险操作强制人工审批,Human in the Loop 机制生效
用户: "I need to cancel my international business class ticket and get a refund.
XYZ789, Johnson"
Agent 执行流程:
[1] verify_customer(pnr="XYZ789", last_name="Johnson")
→ {"verified": true, "user_id": "U002", "passenger_name": "Jane Johnson"}
[2] get_reservation_details(pnr="XYZ789")
→ {"amount_paid": 5500.00, "cabin": "Business", "route": "JFK-LHR"}
[3] calculate_refund(pnr="XYZ789")
→ {"gross_amount": 5500.00, "cancellation_fee": 350.00, "net_refund": 5150.00}
[4] process_refund(pnr="XYZ789", amount=5150)
→ Gateway Policy 检查: amount=5150 > threshold=1000
→ Policy 决策: BLOCK(high_value_refund_protection)
→ 返回 policy_violation,Agent 自动转入审批流程
[5] submit_manual_approval(pnr="XYZ789", amount=5150, reason="Customer requested cancellation")
→ {"ticket_id": "APPR-20260125-001", "status": "PENDING",
"estimated_time": "2 hours", "priority": "high"}
Agent 响应:
"Ms. Johnson, your refund request for $5,150.00 exceeds our automatic approval
threshold. I've submitted it for supervisor review. Your approval ticket ID is
APPR-20260125-001, and you should receive a decision within 2 hours. Is there
anything else I can help you with?"
场景 C:金卡会员改签费豁免(多工具协作)
验证点:会员权益自动识别,Policy 控制费用豁免,7 个工具协调完成改签
用户: "I need to change my flight from Monday to Tuesday. DEF456, Williams"
Agent 执行流程:
[1] verify_customer(pnr="DEF456", last_name="Williams")
→ {"verified": true, "user_id": "U003", "passenger_name": "Sarah Williams"}
[2] get_loyalty_tier(user_id="U003")
→ {"loyalty_tier": "gold", "tier_points": 50000}
[3] get_reservation_details(pnr="DEF456")
→ {"flight_number": "UA5679", "route": "SFO-LAX", "departure_date": "2026-01-27"}
[4] search_flights(origin="SFO", destination="LAX", date="2026-01-28")
→ {"flights": [
{"flight_number": "UA5680", "time": "10:00", "fare": 180.00},
{"flight_number": "UA5682", "time": "14:00", "fare": 180.00},
{"flight_number": "UA5684", "time": "18:00", "fare": 210.00}
]}
用户: "I'll take the 10:00 AM flight."
[5] calculate_change_cost(old_flight="UA5679", new_flight="UA5680")
→ {"base_change_fee": 200.00, "fare_difference": 0, "total_without_waiver": 200.00}
[6] waive_change_fee(pnr="DEF456", loyalty_tier="gold")
→ Gateway Policy 检查: loyalty_tier="gold" ∈ eligible_tiers
→ Policy 决策: PERMIT(loyalty_change_fee_waiver)
→ {"fee_waived": true, "waived_amount": 200.00, "reason": "Gold member privilege"}
[7] update_booking(pnr="DEF456", new_flight="UA5680")
→ {"success": true, "new_confirmation": "DEF456-42", "new_flight": "UA5680"}
Agent 响应:
"Great choice, Ms. Williams! As a valued Gold member, I've waived the $200 change
fee for you. Your flight has been changed to UA5680 departing at 10:00 AM on
Tuesday. Your new confirmation number is DEF456-42."
场景 E:偏好记忆(LTM 跨会话)
[第 1 次会话]
用户: "我喜欢靠窗座位"
Agent: [写入 Memory A LTM] → 存储用户偏好
[第 2 次会话,3 天后]
用户: "帮我订张票"
Agent: [从 Memory A LTM 读取] → 检索到"喜欢靠窗"
响应: "为您选择了靠窗座位"
AIDLC 验证: ✓ No Duplication(Memory A 是唯一数据源)
场景 D:审批状态查询(STM 会话内记忆)
验证点:Agent 无需用户重复提供 ticket_id,STM 自动保持会话上下文
[延续场景 B 的会话]
用户: "What's the status of my refund approval?"
Agent 执行流程:
→ Memory STM 检索: 当前会话中存在 ticket_id="APPR-20260125-001"
[1] check_approval_status(ticket_id="APPR-20260125-001")
→ {"ticket_id": "APPR-20260125-001", "status": "PENDING",
"submitted_at": "2026-01-25T10:30:00", "estimated_time": "2 hours"}
Agent 响应:
"Your refund approval (APPR-20260125-001) is still pending review. It was
submitted about 30 minutes ago, and you should hear back within the next
1.5 hours. I'll make sure to notify you once it's approved."
场景 E:偏好记忆预订(LTM 跨会话记忆)
验证点:LTM 跨会话保留用户偏好,Agent 主动应用偏好推荐,实现个性化服务
[Session 1 - 首次预订]
用户: "I'd like to book a business class ticket from SFO to NYC for Feb 4th.
I prefer morning flights around 10 AM and window seats."
Agent 执行流程:
[1] search_flights(origin="SFO", destination="NYC", date="2026-02-04")
[2] book_flight(user_id="U005", flight_number="UA100", cabin="Business", seat="2A")
→ {"pnr": "EMI001", "seat": "2A", "fare": 1200.00}
→ Memory LTM 自动提取并存储用户偏好:
- /preferences/U005: "prefers morning flights around 10 AM"
- /preferences/U005: "prefers window seats"
---
[Session 2 - 3 天后的新会话]
用户: "I need to book another flight, NYC to LA on Feb 10th"
Agent 执行流程:
→ Memory LTM 检索: /preferences/U005
→ 检索结果注入 <user_context>:
"User preferences: morning flights around 10 AM, window seats"
[1] search_flights(origin="NYC", destination="LAX", date="2026-02-10")
→ {"flights": [
{"flight_number": "UA401", "time": "08:00", "fare": 320.00},
{"flight_number": "UA403", "time": "10:15", "fare": 350.00}, ← 最匹配偏好
{"flight_number": "UA405", "time": "14:30", "fare": 380.00},
{"flight_number": "UA407", "time": "18:00", "fare": 290.00}
]}
Agent 响应:
"Welcome back, Ms. Davis! I see you prefer morning flights around 10 AM and
window seats. Based on your preferences, I recommend UA403 departing at 10:15 AM
- it's closest to your preferred time and has window seats available (10A, 11A).
Would you like me to book this flight for you?"