Certains produits et fonctionnalités sont en cours de changement de nom. Les fonctionnalités de playbook et de flux génératifs sont également en cours de migration vers une console unique. Consultez les détails.
Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
En temps normal, vous créez et supprimez des agents à l'aide de la console.
Toutefois, dans certains scénarios avancés, il peut s'avérer plus simple d'utiliser l'API.
Créer un agent
Les exemples suivants montrent comment appeler la méthode Create pour le type Agent.
Sélectionnez un protocole et une version pour la référence de l'agent :
importcom.google.cloud.dialogflow.cx.v3.Agent;importcom.google.cloud.dialogflow.cx.v3.Agent.Builder;importcom.google.cloud.dialogflow.cx.v3.AgentsClient;importcom.google.cloud.dialogflow.cx.v3.AgentsSettings;importjava.io.IOException;publicclassCreateAgent{publicstaticvoidmain(String[]args)throwsIOException{// TODO(developer): Replace these variables before running the sample.StringprojectId="my-project-id";StringdisplayName="my-display-name";createAgent(projectId,displayName);}publicstaticAgentcreateAgent(Stringparent,StringdisplayName)throwsIOException{StringapiEndpoint="global-dialogflow.googleapis.com:443";AgentsSettingsagentsSettings=AgentsSettings.newBuilder().setEndpoint(apiEndpoint).build();// Note: close() needs to be called on the AgentsClient object to clean up resources// such as threads. In the example below, try-with-resources is used,// which automatically calls close().try(AgentsClientclient=AgentsClient.create(agentsSettings)){// Set the details of the Agent to createBuilderbuild=Agent.newBuilder();build.setDefaultLanguageCode("en");build.setDisplayName(displayName);// Correct format for timezone is location/city// For example America/Los_Angeles, Europe/Madrid, Asia/Tokyobuild.setTimeZone("America/Los_Angeles");Agentagent=build.build();StringparentPath=String.format("projects/%s/locations/%s",parent,"global");// Calls the create agent api and returns the created AgentAgentresponse=client.createAgent(parentPath,agent);System.out.println(response);returnresponse;}}}
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/04/08 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/04/08 (UTC)."],[[["This page outlines how to create and delete Dialogflow CX agents using the API, which is useful for advanced scenarios beyond the console's capabilities."],["The API references for creating and deleting agents are available in REST and RPC protocols, along with specific client libraries for C++, C#, Go, Java, Node.js, and Python, providing comprehensive options for integration."],["To create an agent via REST, you need to send a POST request to a specified URL, including details like display name, default language, and time zone, with provided code examples using `curl` for Linux/macOS/Cloud Shell and PowerShell for Windows."],["To delete an agent via REST, you must send a DELETE request to the relevant agent's URL, requiring your project ID, region ID, and the agent's ID, with provided code examples using `curl` for Linux/macOS/Cloud Shell and PowerShell for Windows."],["The examples provided in Java, Node.js, and Python offer detailed code snippets and instructions for creating agents through their respective client libraries, including necessary authentication steps using Application Default Credentials."]]],[]]