createAgent method

Future<CreateAgentResponse> createAgent({
  1. required String agentName,
  2. AgentCollaboration? agentCollaboration,
  3. String? agentResourceRoleArn,
  4. String? clientToken,
  5. CustomOrchestration? customOrchestration,
  6. String? customerEncryptionKeyArn,
  7. String? description,
  8. String? foundationModel,
  9. GuardrailConfiguration? guardrailConfiguration,
  10. int? idleSessionTTLInSeconds,
  11. String? instruction,
  12. MemoryConfiguration? memoryConfiguration,
  13. OrchestrationType? orchestrationType,
  14. PromptOverrideConfiguration? promptOverrideConfiguration,
  15. Map<String, String>? tags,
})

Creates an agent that orchestrates interactions between foundation models, data sources, software applications, user conversations, and APIs to carry out tasks to help customers.

  • Specify the following fields for security purposes.
    • agentResourceRoleArn – The Amazon Resource Name (ARN) of the role with permissions to invoke API operations on an agent.
    • (Optional) customerEncryptionKeyArn – The Amazon Resource Name (ARN) of a KMS key to encrypt the creation of the agent.
    • (Optional) idleSessionTTLinSeconds – Specify the number of seconds for which the agent should maintain session information. After this time expires, the subsequent InvokeAgent request begins a new session.
  • To enable your agent to retain conversational context across multiple sessions, include a memoryConfiguration object. For more information, see Configure memory.
  • To override the default prompt behavior for agent orchestration and to use advanced prompts, include a promptOverrideConfiguration object. For more information, see Advanced prompts.
  • If your agent fails to be created, the response returns a list of failureReasons alongside a list of recommendedActions for you to troubleshoot.
  • The agent instructions will not be honored if your agent has only one knowledge base, uses default prompts, has no action group, and user input is disabled.

May throw AccessDeniedException. May throw ConflictException. May throw InternalServerException. May throw ServiceQuotaExceededException. May throw ThrottlingException. May throw ValidationException.

Parameter agentName : A name for the agent that you create.

Parameter agentCollaboration : The agent's collaboration role.

Parameter agentResourceRoleArn : The Amazon Resource Name (ARN) of the IAM role with permissions to invoke API operations on the agent.

Parameter clientToken : A unique, case-sensitive identifier to ensure that the API request completes no more than one time. If this token matches a previous request, Amazon Bedrock ignores the request, but does not return an error. For more information, see Ensuring idempotency.

Parameter customOrchestration : Contains details of the custom orchestration configured for the agent.

Parameter customerEncryptionKeyArn : The Amazon Resource Name (ARN) of the KMS key with which to encrypt the agent.

Parameter description : A description of the agent.

Parameter foundationModel : The identifier for the model that you want to be used for orchestration by the agent you create.

The modelId to provide depends on the type of model or throughput that you use:

Parameter guardrailConfiguration : The unique Guardrail configuration assigned to the agent when it is created.

Parameter idleSessionTTLInSeconds : The number of seconds for which Amazon Bedrock keeps information about a user's conversation with the agent.

A user interaction remains active for the amount of time specified. If no conversation occurs during this time, the session expires and Amazon Bedrock deletes any data provided before the timeout.

Parameter instruction : Instructions that tell the agent what it should do and how it should interact with users.

Parameter memoryConfiguration : Contains the details of the memory configured for the agent.

Parameter orchestrationType : Specifies the type of orchestration strategy for the agent. This is set to DEFAULT orchestration type, by default.

Parameter promptOverrideConfiguration : Contains configurations to override prompts in different parts of an agent sequence. For more information, see Advanced prompts.

Parameter tags : Any tags that you want to attach to the agent.

Implementation

Future<CreateAgentResponse> createAgent({
  required String agentName,
  AgentCollaboration? agentCollaboration,
  String? agentResourceRoleArn,
  String? clientToken,
  CustomOrchestration? customOrchestration,
  String? customerEncryptionKeyArn,
  String? description,
  String? foundationModel,
  GuardrailConfiguration? guardrailConfiguration,
  int? idleSessionTTLInSeconds,
  String? instruction,
  MemoryConfiguration? memoryConfiguration,
  OrchestrationType? orchestrationType,
  PromptOverrideConfiguration? promptOverrideConfiguration,
  Map<String, String>? tags,
}) async {
  _s.validateNumRange(
    'idleSessionTTLInSeconds',
    idleSessionTTLInSeconds,
    60,
    5400,
  );
  final $payload = <String, dynamic>{
    'agentName': agentName,
    if (agentCollaboration != null)
      'agentCollaboration': agentCollaboration.value,
    if (agentResourceRoleArn != null)
      'agentResourceRoleArn': agentResourceRoleArn,
    'clientToken': clientToken ?? _s.generateIdempotencyToken(),
    if (customOrchestration != null)
      'customOrchestration': customOrchestration,
    if (customerEncryptionKeyArn != null)
      'customerEncryptionKeyArn': customerEncryptionKeyArn,
    if (description != null) 'description': description,
    if (foundationModel != null) 'foundationModel': foundationModel,
    if (guardrailConfiguration != null)
      'guardrailConfiguration': guardrailConfiguration,
    if (idleSessionTTLInSeconds != null)
      'idleSessionTTLInSeconds': idleSessionTTLInSeconds,
    if (instruction != null) 'instruction': instruction,
    if (memoryConfiguration != null)
      'memoryConfiguration': memoryConfiguration,
    if (orchestrationType != null)
      'orchestrationType': orchestrationType.value,
    if (promptOverrideConfiguration != null)
      'promptOverrideConfiguration': promptOverrideConfiguration,
    if (tags != null) 'tags': tags,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'PUT',
    requestUri: '/agents/',
    exceptionFnMap: _exceptionFns,
  );
  return CreateAgentResponse.fromJson(response);
}