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

Dialogflow:如何将主意图原始查询参数传递至后续意图?

Absolutely, you can pass the original user query from your main search.category intent to the follow-up get_brand intent—here’s how to do it across common conversational AI platforms (I’ll cover practical, platform-agnostic steps plus code examples for tools like Dialogflow):

1. Use Contexts to Share the Query Between Intents

Most NLP tools rely on contexts to carry data between intent turns. This is the most straightforward method:

  • In your search.category intent, when the user sends a query like "32gb phones", capture the full raw input (or the structured parts you need) and save it to a custom parameter in an output context.
    • For example, in Dialogflow, you can set this via the intent’s "Output contexts" section: create a context (say, search_session), then map the system variable $query (which holds the user’s exact input) to a parameter like original_query.
  • Ensure your get_brand follow-up intent is linked to this context (set it as an input context). The follow-up intent will automatically have access to the original_query parameter from the active context.
2. Persist the Query in Session Variables

If you’re using fulfillment code (webhooks), you can store the original query in a session variable that stays active for the user’s conversation:

  • When handling the search.category intent, grab the user’s input using your platform’s built-in method (e.g., agent.query in Dialogflow’s Node.js webhook) and save it to a session context with a lifespan long enough to cover the follow-up turn.
  • When the get_brand intent triggers, retrieve that session variable to access the original query. Here’s a quick code example:
    // Handling search.category intent
    function handleSearchCategory(agent) {
      const userQuery = agent.query; // Captures "32gb phones"
      // Set a context with the query
      agent.context.set({
        name: 'search_context',
        lifespan: 3, // Keeps context active for 3 conversation turns
        parameters: { original_query: userQuery }
      });
      agent.add("Do you have any specific brand?");
    }
    
    // Handling get_brand intent
    function handleGetBrand(agent) {
      const originalQuery = agent.context.get('search_context').parameters.original_query;
      const userResponse = agent.query;
    
      if (userResponse !== "I don't know.") {
        agent.add(`Got it! Let's find ${originalQuery} from ${userResponse}...`);
      } else {
        agent.add(`No worries—here are all our ${originalQuery} options...`);
      }
    }
    
3. Directly Map System Variables to Follow-Up Parameters

Some platforms let you skip code entirely by linking system variables to follow-up intent parameters:

  • In your get_brand intent, add a custom parameter (e.g., original_query).
  • Set the parameter’s value to the system variable that stores the previous user input (check your platform’s docs—for example, Dialogflow allows referencing $contexts.search_context.parameters.original_query directly in the parameter’s default value).
Quick Note on Entities

You mentioned seeing two entities in your second image—if those are structured data from the original query (like 32gb as a storage_size entity and phones as product_category), you can pass those alongside the full query. Just add them to the same context/session variable, so your follow-up intent can use both the raw user input and the structured entity data for more precise handling.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 12:31:46