ã¯ããã«
ããã«ã¡ã¯ããµã¼ãã¼ã¯ã¼ã¯ã¹ã®ãã£ããããã¡ã³ããµã¼ãã¹2課ã®æ± ç°ã§ãã
è¿å¹´ãå´å人å£ã®æ¸å°ãæ·±å»åããä¸ãã«ã¹ã¿ãã¼ãµã¼ãã¹ã®èªååãå¹çåãæ±ãããã¦ãã¾ãããã®ãããªç¶æ³ã«ããã¦ãé³å£°å¯¾è©±ã·ã¹ãã ã«ãèªååãæ±ãããã¦ãã¾ãã
ç¹ã«ãé»è©±ã§ã®æ³¨æãåãåããã«å¯¾ãã¦èªåå¿çã·ã¹ãã ãå°å
¥ãããã¨ã§ããªãã¬ã¼ã¿ã¼ã®è² æ
ã軽æ¸ããã¨åæã«ãéããã人å¡ã§é¡§å®¢æºè¶³åº¦ã®åä¸ãå®ç¾ãããã¨ãå¯è½ã§ãã
ä»åã¯ãAmazon Connectãæ´»ç¨ããé³å£°å¯¾è©±ã·ã¹ãã ã«ãClaudeã®Toolsæ©è½ãçµã¿åããã¦ãé話ã®å 容ãå ã«APIã®å¼ã³åºããå®è£ ããæ¹æ³ããç´¹ä»ãã¾ããããã«ãããé³å£°ã§é¡§å®¢æ å ±ã®ç»é²ã注æå¦çãèªååãããã¨ãå¯è½ã«ãªãã¾ãã
Toolsã¨ã¯
Toolsã¯ãClaudeã対話ä¸ã«APIãå¼ã³åºããã¨ãå¯è½ã«ããæ©è½ã§ããããã«ãããã¦ã¼ã¶ã¼ã¨ã®å¯¾è©±ã®ä¸ã§ãªã¢ã«ã¿ã¤ã ã«ãã¼ã¿ãåå¾ããããç¹å®ã®ã¢ã¯ã·ã§ã³ãå®è¡ããããããã¨ãã§ãã¾ãã
å ·ä½çã«ã¯ã対話ã®æèã«å¿ãã¦APIãå¼ã³åºãããã®çµæãã¦ã¼ã¶ã¼ã«è¿ããã¨ãã§ãã¾ããããã«ããã以ä¸ã®ãããªå©ç¹ãããã¾ãã
- ãªã¢ã«ã¿ã¤ã ãã¼ã¿ã®åå¾: ææ°ã®æ å ±ãåå¾ãã¦ã¦ã¼ã¶ã¼ã«æä¾ã§ãã¾ãã
- åçãªå¯¾è©±: ã¦ã¼ã¶ã¼ã®å ¥åã«åºã¥ãã¦æè»ã«å¯¾å¿ã§ãã¾ãã
- èªååãããã¢ã¯ã·ã§ã³: ãã¼ã¿ã®ç»é²ãæ´æ°ãªã©ã®æä½ãèªåã§è¡ãã¾ãã
ã·ããªãª
ä»åã¯ãé»è©±ãéãã¦ãã¶ã®æ³¨æãèªååããã·ããªãªãå®ç¾ãã¾ãã
ã客æ§ããã®é»è©±ã«å¯¾ããé³å£°å¯¾è©±ãéãã¦å¿
è¦ãªæ
å ±ãåå¾ããAPIã使ç¨ãã¦é¡§å®¢æ
å ±ã注æå
容ãç»é²ãã¾ãã
以ä¸ã¯ãã客æ§ã¨èªåå¿çã·ã¹ãã ã¨ã®æ³å®ãããä¼è©±ã®æµãã§ãã
çºè¨è | çºè¨å 容 |
---|---|
ãå®¢æ§ | ï¼é»è©±ããããï¼ |
èªåå¿ç | ãµãã¯ãã¶ã§ããã客æ§æ å ±ã®ç¢ºèªããããã¾ãããé»è©±çªå·ãæãã¦ãã ããã |
ãå®¢æ§ | 08012345678ã§ãã |
èªåå¿ç | ã客æ§ã®ãé»è©±çªå·ã¯08012345678ã§ããããã§ããããï¼ |
ãå®¢æ§ | ã¯ãã |
Lambda | ï¼Toolã§APIãå®è¡ãã¦ã¦ã¼ã¶æ å ±åå¾ï¼ |
èªåå¿ç | ã客æ§æ å ±ãè¦ã¤ããã¾ããã§ãããã客æ§æ å ±ãç»é²ãã¾ãã®ã§ãååãéµä¾¿çªå·ãä½æãæãã¦ããã ãã¾ããï¼ |
ãå®¢æ§ | ååã¯å±±ç°å¤ªéã§ããéµä¾¿çªå·ã¯131-0045ã§ãã |
èªåå¿ç | ãããã¨ããããã¾ãã次ã«ä½æãæãã¦ãã ããã |
ãå®¢æ§ | æ±äº¬é½å¢¨ç°åºæ¼ä¸ï¼ä¸ç®ï¼âï¼ã§ãã |
èªåå¿ç | ã客æ§ã®ãååã¯å±±ç°å¤ªéæ§ãéµä¾¿çªå·ã¯131-0045ãä½æã¯æ±äº¬é½å¢¨ç°åºæ¼ä¸ï¼ä¸ç®ï¼âï¼ã§ããããã§ããããï¼ |
ãå®¢æ§ | ã¯ãã |
Lambda | ï¼Toolã§APIãå®è¡ãã¦ã¦ã¼ã¶æ å ±ç»é²ï¼ |
èªåå¿ç | ãããã¨ããããã¾ããã客æ§æ å ±ãç»é²ãã¾ããã次ã«ã注æãããã¶ãæãã¦ãã ããã |
ãå®¢æ§ | 注æãããã¶ã¯ã¯ã¢ããã»ãã©ã«ããã¸ãLãµã¤ãºã1æãé¡ããã¾ãã |
èªåå¿ç | ã注æã確èªãããã¾ããã注æå 容ã¯ã¯ã¢ããã»ãã©ã«ããã¸ã®Lãµã¤ãºã1æã§ããããã§ããããï¼ |
ãå®¢æ§ | ã¯ãã以ä¸ã§å¤§ä¸å¤«ã§ãã |
Lambda | ï¼Toolã§APIãå®è¡ãã¦æ³¨ææ å ±ç»é²ï¼ |
èªåå¿ç | ã注æãæ¿ãã¾ãããããã§ã¯ãå°çã¾ã§ãå¾ ã¡ãã ãããã注æãããã¨ããããã¾ããã |
ãã®ããã«ãé³å£°å¯¾è©±ãéãã¦ã客æ§ããå¿ è¦ãªæ å ±ãåéããèªåçã«æ³¨æå¦çãè¡ãã·ã¹ãã ãæ§ç¯ãã¾ãã
åææ¡ä»¶
- Amazon Connectã®ã¤ã³ã¹ã¿ã³ã¹ãä½ææ¸ã¿ã§ãããã¨
- Claude 3.5 Sonetãæå¹åãã¦ãããã¨
æ§ç¯æé
1. Lambdaãä½æ
AWS ããã¸ã¡ã³ãã³ã³ã½ã¼ã«ããä¸è¨ã®Lambdaãä½æãã¾ãã
ã©ã³ã¿ã¤ã ã¯Pythonãååã[bedrock-tool]ã¨ãã¦ä½æãã¾ãã
import boto3 import json import os from decimal import Decimal import urllib.request # Bedrock ã¯ã©ã¤ã¢ã³ãã®åæå bedrock_client = boto3.client('bedrock-runtime', region_name='ap-northeast-1') model_id = "anthropic.claude-3-5-sonnet-20240620-v1:0" def get_user(phone_number) -> str: # TODO:ã¦ã¼ã¶æ å ±åå¾ã®APIå®è¡ãä»åã®è¨äºã§ã¯çç¥ãã¾ãã return "none" def create_user(post_code,address,name,phone_number) -> str: # TODO:ã¦ã¼ã¶æ å ±ç»é²ã®APIå®è¡ãä»åã®è¨äºã§ã¯çç¥ãã¾ãã return "success" def create_order(phone_number,order) -> str: # TODO:ãªã¼ãã¼ç»é²ã®APIå®è¡ãä»åã®è¨äºã§ã¯çç¥ãã¾ãã return "success" def get_claude_response(user_prompt, session_attributes): # ä¼è©±å±¥æ´ã®åæå conversation_history = "" # session_attributes ãã質åã¨åçãåå¾ããããã³ãããä½æ question_count = int(session_attributes.get("question_count", "0")) for i in range(1, question_count + 1): question_key = f"question{i}" answer_key = f"answer{i}" question = session_attributes.get(question_key, "") answer = session_attributes.get(answer_key, "") if question and answer: conversation_history += f"\n\nHuman: {question}\n\nAssistant: {answer}" # ç¾å¨ã®ã¦ã¼ã¶ã¼å ¥åã追å conversation_history += f"\n\nHuman: {user_prompt}\n\nAssistant:" # ãªã¯ã¨ã¹ããã¤ãã¼ãã®ä½æ body = json.dumps({ "anthropic_version": "bedrock-2023-05-31", "max_tokens": 2000, "temperature": 0.1, "top_p": 0.999, "top_k": 300, "system": """ # è¦ä»¶ - ããªãã¯ãµãã¯ãã¶ã®æ³¨æãèãããã©ã³ãªãã¬ã¼ã¿ã§ãã - ããªãã®åçã®å 容ãé³å£°ã§èªã¿ä¸ãã¦åçãã¦ãã¾ãããããè¸ã¾ãã¦åçãã¦ãã ããã - ããªãã¯é«é¡ãªå ±é ¬ãããã ãã¦ããã®ã§ããæ°ã«æºã¡æºã¡ã§ãã¾ãã - ä¼è©±ã¯ç«¯çã«çããªãã¬ã¼ã¿ã¨ãã¦ä¼è©±ãã¦ãã ããã - åtoolãå®è¡ããã®ã¯1åã®ã¿ã§ããè¤æ°åå®è¡ã¯ã§ãã¾ããã - ä¸è¨ã®ããã«toolãå©ç¨ããåã¯å¿ ãã確èªãåãããã«ãã¦ãã ãããå¿ è¦ãªãã©ã¡ã¼ã¿ãæã£ãæã«ç¢ºèªãã¦ãã ããã - ã客æ§ã®ãé»è©±çªå·ã¯ããã§ããããã§ããããï¼ - ã客æ§æ å ±ã確èªãã¾ãããååã¯ããæ§ãéµä¾¿çªå·ã¯ãããä½æã¯ããã§ããããã§ããããï¼ - ã注æã確èªãããã¾ããã注æå 容ã¯ããã§è¯ãã§ããããï¼ # 注æãåããæµã 1. ã¯ããã«ã客æ§ã®é»è©±çªå·ãèãã¦get_userãå®è¡ãã¾ãã 2. 次ã«ãã客æ§æ å ±ãåå¨ããªãå ´åãcreate_userãå®è¡ãã¾ããã客æ§æ å ±ãåå¨ããå ´åã¯ãã®ã¹ãããã¯ã¹ããããã¾ãã 3. create_userãå®äºãããããã¶ã®æ³¨æãè¡ãcreate_orderãå®è¡ãã¾ãã """, "tools": [ { "name": "get_user", "description": "ã客æ§æ å ±ãåå¾ãã¾ãã", "input_schema": { "type": "object", "properties": { "phone_number": { "type": "string", "description": "ã客æ§ã®é»è©±çªå·ãæå®ãã¾ããä¾: 08012345678" } }, "required": ["phone_number"] } }, { "name": "create_user", "description": "ã客æ§æ å ±ãç»é²ãã¾ãã", "input_schema": { "type": "object", "properties": { "post_code": { "type": "string", "description": "ã客æ§ã®éµä¾¿çªå·ãæå®ãã¾ããä¾: 332-0001" }, "address": { "type": "string", "description": "ã客æ§ã®ä½æãæå®ãã¾ããä¾: æ±äº¬é½èå·åºè¥¿æ¥æ®é1-2-3" }, "name": { "type": "string", "description": "ã客æ§ã®ååãæå®ãã¾ããä¾: ã¤ãã ã¿ãã¦" }, "phone_number": { "type": "string", "description": "ã客æ§ã®é»è©±çªå·ãæå®ãã¾ããä¾: 08012345678" } }, "required": ["post_code", "address", "name", "phone_number"] } }, { "name": "create_order", "description": "ãã¶ã®ãªã¼ãã¼ãç»é²ãã¾ãã", "input_schema": { "type": "object", "properties": { "phone_number": { "type": "string", "description": "ã客æ§ã®é»è©±çªå·ãæå®ãã¾ããä¾: 08012345678" }, "order": { "type": "string", "description": "ãªã¼ãã¼ãæå®ãã¾ããä¾: ãã«ã²ãªã¼ã¿ Lãµã¤ãº 1æ" } }, "required": ["phone_number", "order"] } } ], "messages": [ { "role": "user", "content": [ { "type": "text", "text": conversation_history } ] } ] }) try: # Bedrock API ã®å¼ã³åºã response = bedrock_client.invoke_model( modelId=model_id, contentType="application/json", accept="application/json", body=body ) # ã¬ã¹ãã³ã¹ã®èªã¿åã response_body = json.loads(response["body"].read().decode()) # ãã¼ã«ã使ç¨ãããå ´åã®å¦ç for content in response_body.get("content", []): if content.get("type") == "tool_use": tool_name = content.get("name") tool_input = content.get("input", {}) if tool_name == "get_user": phone_number = tool_input.get("phone_number", "") if get_user(phone_number) is "none": return "ã客æ§æ å ±ãè¦ã¤ããã¾ããã§ãããã客æ§æ å ±ãç»é²ãã¾ãã®ã§ãååãéµä¾¿çªå·ãä½æãæãã¦ããã ãã¾ããï¼" else: return "ã¦ã¼ã¶ãè¦ã¤ããã¾ããã" elif tool_name == "create_user": post_code = tool_input.get("post_code", "") address = tool_input.get("address", "") name = tool_input.get("name", "") phone_number = tool_input.get("phone_number", "") if create_user(post_code, address, name, phone_number) is "success": return "ãããã¨ããããã¾ããã客æ§æ å ±ãç»é²ãã¾ããã次ã«ã注æãããã¶ãæãã¦ãã ããã" else: return "ã客æ§æ å ±ã®ç»é²ã«å¤±æãã¾ããã" elif tool_name == "create_order": phone_number = tool_input.get("phone_number", "") order = tool_input.get("order", "") if create_order(phone_number, order) is "success": return "exit" else: return "ãªã¼ãã¼ã®ç»é²ã«å¤±æãã¾ããã" else: return "æªç¥ã®ãã¼ã«ãæå®ããã¾ãã: {tool_name}" # é常ã®å¿çãè¿ã if "content" in response_body: return "\n".join([result.get("text", "") for result in response_body.get("content", [])]) else: return "APIããã®ç¡å¹ãªã¬ã¹ãã³ã¹å½¢å¼ã§ãã" completion = "\n".join([result.get("text", "") for result in response_body.get("content", [])]) return completion except Exception as e: return f"ã¨ã©ã¼ãçºçãã¾ãã: {str(e)}" def main(event): input_text = event['inputTranscript'] session_state = event.get('sessionState', {}) session_attributes = session_state.get('sessionAttributes', {}) # 質åã¨åçãä¿åããããã®ã«ã¦ã³ã¿ãåå¾ question_count = int(session_attributes.get("question_count", "0")) # å ¥åãçµäºã®å ´åã®å¦ç if input_text == "çµäº": event['messages'] = [{'contentType': 'PlainText', 'content': 'ãé»è©±ãããã¨ããããã¾ãããé»è©±ãåãã¾ãã'}] event['sessionState']['dialogAction'] = {'type': 'Close'} return event # Claude APIãå¼ã³åºãã¦å¿çãåå¾ response_text = get_claude_response(input_text, session_attributes) # ãªã¼ãã¼å®äºæã®å¦ç if response_text == "exit": event['messages'] = [{'contentType': 'PlainText', 'content': 'ã注æãæ¿ãã¾ãããããã§ã¯ãå°çã¾ã§ãå¾ ã¡ãã ãããã注æãããã¨ããããã¾ããã'}] event['sessionState']['dialogAction'] = {'type': 'Close'} return event # 質åã¨åçãã»ãã·ã§ã³å±æ§ã«ä¿å question_key = f"question{question_count + 1}" answer_key = f"answer{question_count + 1}" session_attributes[question_key] = input_text session_attributes[answer_key] = response_text session_attributes["question_count"] = str(question_count + 1) # ã¡ãã»ã¼ã¸ã¨ç¶æ ãç´æ¥è¨å® event['messages'] = [{'contentType': 'PlainText', 'content': response_text}] event['sessionState']['dialogAction'] = {'type': 'ConfirmIntent'} event['sessionState']['sessionAttributes'] = session_attributes return event def lambda_handler(event, context): return main(event)
2. Amazon Lex Botã®ä½æ
1.Amazon Lexç»é¢ã§[create bot]ãã¯ãªãã¯
2.次ã®è¨å®ã§ã[Next]ãã¯ãªãã¯
3.次ã®è¨å®ã§ã[Done]ãã¯ãªãã¯
3.ã¤ã³ãã³ãä½æ
NewIntentã®ç»é¢ã«é·ç§»ããã®ã§ã[utterances]ã«é©å½ãªå¤ãå
¥åã[Add utterance]ãã¯ãªãã¯ãã[save intent]ãã¯ãªãã¯ã
â»ä»åã¤ã³ãã³ãã®ä»£ããã«toolã使ãããããã®ã¤ã³ãã³ãã¯å©ç¨ãã¾ããã
4.FallbackIntentã®è¨å®
FallbackIntentã®ç»é¢ã§ã[Closing response]ã[Active]ã«ãã¦ã[Use a Lambda function for initialization and validation]ã«ãã§ãã¯ãå ¥ãã¦ã[Save intent]ãã¯ãªãã¯ãã¾ãã
5.Lex Botã«Lambdaãè¨å®
[Aliases]ãã¯ãªãã¯ãã[Japanese]ã¯ãªãã¯ãã¦ãå ã»ã©ä½æããLambdaãè¨å®ãã¦[Save]ãã¯ãªãã¯ãã¾ãã
6.ãã«ã
[Build]ãã¯ãªãã¯ãã¾ãã
7.Amazon Lexãã¹ã
[Test]ãã¯ãªãã¯ãã¦[ãã¹ã]ã¨å
¥åãã¾ãã
ä¸è¨ã®ããã«ããã¶ãªãã¬ã¼ã¿ã®åçãããã°æ£å¸¸ã§ãã
8.Amazon Connectã«Botã追å
Amazon Connectã®ã¤ã³ã¹ã¿ã³ã¹ã®ã¡ãã¥ã¼ãã[åãåããããã¼]ãã¯ãªãã¯ããä½æããBotãé¸æãã[Amazon Lexãããã追å ]ãã¯ãªãã¯ãã¾ãã
9.ããã¼ä½æ
次ã®åãåããããã¼ãä½æãã¾ãã
åãããã¯ã®è¨å®ã¯ä¸è¨ã®ã¨ããã§ãã
- é³å£°ã®è¨å®
- 顧客ã®å ¥åãåå¾ãã
åä½ç¢ºèª
çµãã
ãã®è¨äºã§ã¯ãAmazon Connectãæ´»ç¨ããçæAIã®Claudeã®Toolsæ©è½ãçµã¿åããã¦é³å£°å¯¾è©±ã·ã¹ãã ãæ§ç¯ããæ¹æ³ããç´¹ä»ãã¾ããã
ä»åã¯ãClaudeã®Toolsæ©è½ãå©ç¨ãã¦ãå®è£
ãã¾ããããAmazon Lexã§ãé³å£°å¯¾è©±ã·ã¹ãã ãæ§ç¯ã§ãã¾ãã
Lexã¯äºåå®ç¾©ãããããã¼ã§ã®å¯¾å¿ãå¾æã§ãããClaudeã®Toolsæ©è½ã¯APIå¼ã³åºããæ´»ç¨ãã¦æè»ãªå¯¾å¿ãå¯è½ã§ãã
æ¬è¨äºã§ãç´¹ä»ããæ¹æ³ãåèã«ãã¦ããã ããæ¥å課é¡ã®è§£æ±ºã«ãå½¹ç«ã¦ããã ããã°å¹¸ãã§ãã
ãµã¼ãã¼ã¯ã¼ã¯ã¹ã¯ãçæAIã¨Amazon Connectãæ´»ç¨ãã顧客対å¿æ¥åã®å¹çåã¨é¡§å®¢æºè¶³åº¦åä¸ãç®æãPoCæ¯æ´ãã£ã³ãã¼ã³ãéå§ãã¾ããã
ãç³ãè¾¼ã¿ã¯2025å¹´2æ28æ¥ã¾ã§ã§ãå
ç10社éå®ã¨ãªãã¾ãã詳細ã¯ãã¡ããã覧ãã ããã