Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Por lo general, los agentes se crean y borran mediante la consola.
Sin embargo, en ciertas situaciones avanzadas, puede que te resulte más fácil usar la API.
Crea un agente
En los siguientes ejemplos, se muestra cómo llamar al método SetAgent para el tipo Agent.
En estos ejemplos, se crean agentes, pero se pueden usar los mismos métodos para actualizar la configuración del agente, como la edición del agente.
REST
Antes de usar cualquiera de los datos de solicitud a continuación, realiza los siguientes reemplazos:
PROJECT_ID: El ID del proyecto de Google Cloud.
Método HTTP y 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();
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[[["\u003cp\u003eThe API can be used to create and delete agents, which are operations typically done via the console, in certain advanced scenarios.\u003c/p\u003e\n"],["\u003cp\u003eCreating or updating agents via the API involves using the \u003ccode\u003eSetAgent\u003c/code\u003e method and provides the ability to configure agent settings like display name, default language, and time zone.\u003c/p\u003e\n"],["\u003cp\u003eDeleting agents via the API is achieved using the \u003ccode\u003eDeleteAgent\u003c/code\u003e method, and successful deletion returns a 2xx status code with an empty response.\u003c/p\u003e\n"],["\u003cp\u003eBoth creating and deleting agents via the API requires a role with full or edit access.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication for API interactions with Dialogflow requires setting up Application Default Credentials, as outlined in the documentation.\u003c/p\u003e\n"]]],[],null,[]]