You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Alexa与Dialogflow同一意图中获取多组动态及未知文本

Hey there! I’ve dealt with similar setup challenges when building voice experiences with Alexa and Dialogflow, so let’s break this down step by step for your two questions:

1. How to collect dynamic, multiple inputs in the same intent

The key here is tracking conversation state so your assistant knows what information it still needs to gather. Here’s how to implement this for both platforms:

For Dialogflow

  • Use Contexts to keep track of what input you’re expecting next. Create a context (e.g., awaiting_content_details) with a lifespan of 2-3 rounds (enough to cover the user’s response).
  • Optimize Training Phrases to include both single and multi-input scenarios, like:
    • "I want to add content: title is [title], description is [description]"
    • "First the title: [title], then the description is [description]"
    • "Title is [title], I’ll tell you the description later"
  • Build Fulfillment Logic to check which fields are missing, prompt the user, and retain the context. Example Node.js code:
function handleContentIntent(agent) {
  const title = agent.parameters.title;
  const description = agent.parameters.description;
  const currentContext = agent.context.get('awaiting_content_details');

  if (!title) {
    agent.context.set({ name: 'awaiting_content_details', lifespan: 2 });
    agent.add("Could you tell me the title of your content?");
  } else if (!description) {
    agent.context.set({ name: 'awaiting_content_details', lifespan: 2 });
    agent.add(`Got it, title is ${title}. Now can you share the description?`);
  } else {
    agent.add(`Perfect! I've saved your content: Title - ${title}, Description - ${description}`);
  }
}
  • Don’t forget to add awaiting_content_details as an Input Context for your intent, so Dialogflow routes follow-up responses back to this intent.

For Alexa

  • Use Session Attributes to store information collected so far during the conversation.
  • Implement Intent Handling that checks the session state to know what input to request next. Example Node.js code:
const ContentIntentHandler = {
  canHandle(handlerInput) {
    return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
      && Alexa.getIntentName(handlerInput.requestEnvelope) === 'ContentIntent';
  },
  handle(handlerInput) {
    const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
    const userInput = handlerInput.requestEnvelope.request.intent.slots.FreeText.value;

    if (!sessionAttributes.title) {
      sessionAttributes.title = userInput;
      handlerInput.attributesManager.setSessionAttributes(sessionAttributes);
      return handlerInput.responseBuilder
        .speak(`Got the title: ${userInput}. Now please tell me the description.`)
        .reprompt("Could you share the description for your content?")
        .getResponse();
    } else if (!sessionAttributes.description) {
      sessionAttributes.description = userInput;
      return handlerInput.responseBuilder
        .speak(`Great! I've recorded your content: Title is ${sessionAttributes.title}, Description is ${userInput}`)
        .getResponse();
    }
  }
};
  • Use AMAZON.SearchQuery as the slot type (equivalent to Dialogflow’s @sys.any) to capture arbitrary user text.
2. How to capture two distinct text types (title/description) when the user doesn’t explicitly label them

This relies on guiding the conversation and training your model to infer which input corresponds to which field:

  • Leverage Step-by-Step Prompting: Instead of letting the user ramble, explicitly ask for one field at a time. For example:

    1. First prompt: "What’s the title of your content?"
    2. After receiving the title: "Thanks! Now can you describe the content?"
      This eliminates ambiguity because each user response is tied to a specific request.
  • Optimize Training Phrases for Ambiguous Inputs: Add examples where the user provides both fields without labels, like:

    • "[title] [description]"
    • "[title], it’s about [description]"
      Dialogflow’s ML will learn to map the first part to the title slot and the rest to the description slot over time.
  • Use Dialogflow’s Auto Slot Filling: If you’ve defined title and description as separate slots (both using @sys.any), enable auto slot filling. Configure prompts for each missing slot, and Dialogflow will automatically ask for the missing information if the user only provides one field.

  • Lightweight Semantic Checks (Optional): In fulfillment, you can add simple logic to guess which field the user provided (e.g., short text = title, longer text = description), but this is a fallback—context-guided prompting is much more reliable.


内容的提问来源于stack exchange,提问作者Ruby

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 10:47:04