Hi,
After replacing our Intents and Entities via the API, we observe strange behaviours with intent detection. Actually, the intent detection behaves as if we had no entity at all (the result parameters key is an empty object). I need to manually save again all the intents (in Dialogflow's console) for the agent to work fine.
dialogflow version: 0.7.0In order to update our agent, we execute the following steps:
I tried to extract a sample code source that reproduces those steps:
import * as df from 'dialogflow';
/* PROJECT AND DIALOGFLOW CLIENTS SET UP */
const projectId = '[MY_PROJECT_ID]';
const agentsClient = new df.AgentsClient({
credentials: { private_key: '[MY_PRIVATE_KEY]', client_email: '[MY_CLIENT_EMAIL]' }
});
const intentsClient = new df.IntentsClient({
credentials: { private_key: '[MY_PRIVATE_KEY]', client_email: '[MY_CLIENT_EMAIL]' }
});
const entityTypesClient = new df.EntityTypesClient({
credentials: { private_key: '[MY_PRIVATE_KEY]', client_email: '[MY_CLIENT_EMAIL]' }
});
/* SAMPLE ENTITIES AND INTENT */
const myIntent = {
displayName: 'buy',
webhookState: 'WEBHOOK_STATE_DISABLED',
mlEnabled: false,
priority: 500000,
trainingPhrases: [
{
type: 'TYPE_EXAMPLE',
parts: [
{ text: 'I would like to buy some ' },
{ text: 'broccolis', entityType: '@vegetables', alias: 'vegetables' }
]
},
{
type: 'TYPE_EXAMPLE',
parts: [
{ text: 'Can I buy some ' },
{ text: 'banana', entityType: '@fruit', alias: 'fruit' },
{ text: ' ?' }
]
},
{
type: 'TYPE_EXAMPLE',
parts: [
{ text: 'I will have some ' },
{ text: 'apples', entityType: '@fruit', alias: 'fruit' }
]
},
{
type: 'TYPE_EXAMPLE',
parts: [
{ text: 'Spinach', entityType: '@vegetables', alias: 'vegetables' },
{ text: ' is what I need !' }
]
}
]
};
const myEntityTypes = [
{
displayName: 'vegetables',
kind: 'KIND_MAP',
autoExpansionMode: 'AUTO_EXPANSION_MODE_UNSPECIFIED',
entities: [
{ value: 'broccoli', synonyms: ['broccoli'] },
{ value: 'spinach', synonyms: ['spinach'] }
]
},
{
displayName: 'fruit',
kind: 'KIND_MAP',
autoExpansionMode: 'AUTO_EXPANSION_MODE_UNSPECIFIED',
entities: [{ value: 'apple', synonyms: ['apple'] }, { value: 'banana', synonyms: ['banana'] }]
}
];
/* RESOURCES HANDLERS */
function listIntents() {
const request = {
parent: intentsClient.projectAgentPath(projectId),
intentView: 'INTENT_VIEW_FULL'
};
return intentsClient.listIntents(request).then((responses) => responses[0]);
}
function createIntent(intent) {
const request = {
parent: intentsClient.projectAgentPath(projectId),
intent
};
return intentsClient.createIntent(request);
}
function deleteIntents(intents) {
const request = {
parent: intentsClient.projectAgentPath(projectId),
intents
};
return intentsClient.batchDeleteIntents(request);
}
function listEntityTypes() {
const request = {
parent: entityTypesClient.projectAgentPath(projectId)
};
return entityTypesClient.listEntityTypes(request).then((responses) => responses[0]);
}
function createMultipleEntityTypes(entityTypes) {
return Promise.all(entityTypes.map((entityType) => createOneEntityType(entityType)));
}
function createOneEntityType(entityType) {
const request = {
parent: entityTypesClient.projectAgentPath(projectId),
entityType
};
return entityTypesClient.createEntityType(request);
}
function deleteMultipleEntityTypes(entityTypes) {
return Promise.all(entityTypes.map((entityType) => deleteOneEntityType(entityType)));
}
function deleteOneEntityType(entityType) {
const requestEntities = {
parent: entityType.name,
entityValues: [entityType.entities]
};
const requestEntityType = {
name: entityType.name
};
return entityTypesClient
.batchDeleteEntities(requestEntities)
.then(() => entityTypesClient.deleteEntityType(requestEntityType));
}
/* THE ACTUAL DATA OPERATIONS */
listIntents()
.then((intents) => deleteIntents(intents))
.then(() => listEntityTypes())
.then((entityTypes) => deleteMultipleEntityTypes(entityTypes))
.then(() => createMultipleEntityTypes(myEntityTypes)) // Sample entities (declared at the top)
.then(() => createIntent(myIntent)) // Sample intent (declared at the top)
.then(() =>
agentsClient.trainAgent({
parent: agentsClient.projectPath(projectId)
})
);
Once the steps are executed, the entities and intent are effectively stored in Dialogflow. As you can see on the screenshot below.

Yet, when I try to detect intents, Dialogflow does not detect any entity (not via the API, nor via the console).

This is the DIAGNOSTIC INFO provided by the console (note the empty parameters object):
{
"responseId": "3a46e312-7900-456d-90af-39a04e3f5414",
"queryResult": {
"queryText": "I would like to buy some broccolis",
"parameters": {},
"allRequiredParamsPresent": true,
"intent": {
"name": "projects/[MY_PROJECT_ID]/agent/intents/[MY_INTENT_ID]",
"displayName": "buy"
},
"intentDetectionConfidence": 1,
"languageCode": "en"
}
}
Once I save again the intent, manually this time, in the console, it works perfectly. Same for the detect intent API.

I am not 100% sure that this is the appropriate place to post this issue, as the problem could be rooted in Dialogflow itself, but as the doc does not cover this use case, I would really enjoy if you could give an opinion on this implementation. This issue is really important to us as it prevents us from integrating Dialogflow to our system.
Thanks a lot for your time, this SDK is very (VERY) useful.
this is more a bug than a question
Hi,
Any news on this one ? You flagged the issue as a question, but I think it's a bug: when I export intents and entities, they do appear in Dialogflow, but the detectIntent API doesn't take them into account...
Thanks for your help !
This is affecting us as well - it seems like a lot of changes done via the API don't get taken into account and you either have to wait an indefinite amount of time (sometimes 1 second sometimes 10 etc.) or you re-save them via Console and they start working
I ran into the same issue today. Did anybody figure out a workaround by any chance?
We are getting around this by doing 2 things
This has been working without fail for us the past week
Thanks! May I ask: Does that also resolve the issue where the entities within the intents were not detected for you? It doesn't really seem to do that for us, even after we explicitly call train, no matter how long we wait.
Yes, we haven't had an issue since implementing it this way and detection with alias parameters show up in the detect results.
One thing that did catch us up was that we had to add parameters to the Intent directly even though we put them in the phrase parts. So basically in your API you're going to create a TrainingPhrase with all your parts. For any parts that also have an alias/entity type you're going to want to make sure you add an intent parameter with displayname = alias, entityTypeDisplayName = entityType, and mandatory = true. That's how we're doing it because before this, we had the same issue
Thanks! That last part actually did the trick for us as well.
You're welcome. Great to hear - the docs don't really make it clear that you have to do that
Looks like cain06 has answered this question.
Each time the agent changes in Dialogflow it runs through a training phase to update the ML model. It's more obvious in the UI, but not in the API.
Pops up a dialog box: "Agent Training Started" then a few seconds later "Agent Training Finished"
We are getting around this by doing 2 things
- Calling the Train Agent API
- Adding an additional 1500ms wait after making changes to give it chance to figure things out
This has been working without fail for us the past week
I am having the same issue and i tried both things but it doesn't get resolved.
We are getting around this by doing 2 things
- Calling the Train Agent API
- Adding an additional 1500ms wait after making changes to give it chance to figure things out
This has been working without fail for us the past week
I am facing same issue and I did both steps (even by adding more delay 5secs) but the problem is still there, still I should go and press the save button in each intent! No new solution for this bug?
It's making me crazy, even pressing the save button for each intent and manual training from settings. It not picking up the intent.
It was working just before importing some of the intent. It broke everything here.
Sometimes it works in the console but not in connected devices.
Now old intent is working from console dialog flow but from Google Assistant, all query getting into default fallback. Plesase help
@jaymovaliya, @shzamani, @abhinavkumar985
Can you folks open a new issue and provide some info about what you are doing in your code?
Most helpful comment
Hi,
Any news on this one ? You flagged the issue as a question, but I think it's a bug: when I export intents and entities, they do appear in Dialogflow, but the
detectIntentAPI doesn't take them into account...Thanks for your help !