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):
Most NLP tools rely on contexts to carry data between intent turns. This is the most straightforward method:
- In your
search.categoryintent, 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 likeoriginal_query.
- For example, in Dialogflow, you can set this via the intent’s "Output contexts" section: create a context (say,
- Ensure your
get_brandfollow-up intent is linked to this context (set it as an input context). The follow-up intent will automatically have access to theoriginal_queryparameter from the active context.
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.categoryintent, grab the user’s input using your platform’s built-in method (e.g.,agent.queryin 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_brandintent 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...`); } }
Some platforms let you skip code entirely by linking system variables to follow-up intent parameters:
- In your
get_brandintent, 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_querydirectly in the parameter’s default value).
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

