Stay organized with collections
Save and categorize content based on your preferences.
Normally, you create and delete agents using the console.
However, in certain advanced scenarios,
you may find it easier to use the API.
Create an agent
The following examples show how to call the SetAgent method for the
Agent
type.
These examples are creating agents,
but the same methods can be used to update agent settings,
like agent edition.
REST
Before using any of the request data,
make the following replacements:
PROJECT_ID: your Google Cloud project ID
HTTP method and URL:
POST https://dialogflow.googleapis.com/v2/projects/PROJECT_ID/agent
importcom.google.cloud.dialogflow.v2.Agent;importcom.google.cloud.dialogflow.v2.Agent.Builder;importcom.google.cloud.dialogflow.v2.AgentsClient;importcom.google.cloud.dialogflow.v2.AgentsSettings;importjava.io.IOException;publicclassSetAgent{publicstaticvoidmain(String[]args)throwsIOException{StringprojectId="my-project-id";// The display name will set the name of your agentStringdisplayName="my-display-name";setAgent(projectId,displayName);}publicstaticAgentsetAgent(Stringparent,StringdisplayName)throwsIOException{AgentsSettingsagentsSettings=AgentsSettings.newBuilder().build();try(AgentsClientclient=AgentsClient.create(agentsSettings)){// Set the details of the Agent to createBuilderbuild=Agent.newBuilder();build.setDefaultLanguageCode("en");build.setDisplayName(displayName);Agentagent=build.build();// Make API request to create agentAgentresponse=client.setAgent(agent);System.out.println(response);returnresponse;}}}
const{AgentsClient}=require('@google-cloud/dialogflow');// make sure to pass projectID as the input parameterconstparent='projects/'+parentId+'/locations/global';constagent={parent:parent,displayName:displayName,defaultLanguageCode:'en',timeZone:'America/Los_Angeles',};constclient=newAgentsClient();asyncfunctionsetAgent(){constrequest={agent,};const[response]=awaitclient.setAgent(request);console.log(`response: ${JSON.stringify(response,null,2)}`);}awaitsetAgent();
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-01-27 UTC."],[],[]]