By using AWS re:Post, you agree to the AWS re:Post Terms of Use

Bedrock CLI/API: how to associate an Action Group to an Agent Version

0

Hi guys,

can you please point me in the right direction to create/update an Agent Version with an Action Group associated?

Right now I can do it from AWS Console UI only...

Also, I see a command to associate a Knowledge-Bases to an Agent Version:

  associate-agent-knowledge-base \
     --agent-id <value> \
     --agent-version <value> \
     --description <value> \
     --knowledge-base-id <value>

But cannot find anything similar for Action Groups.

Thanks.

profile picture
asked 2 months ago125 views
2 Answers
0
Accepted Answer

Okay I got it... Looks like there is a bug in the Terraform Agent resource attribute prepare_agent=true. The preparation does not happen.

I solved it by forcing the preparation with a Terraform null_resource and running aws cli commands. It is mandatory to wait for the Agent to be PREPARED before creating the Alias to then have the Action Group associated to it.

I leave this part of Terraform configuration below for reference.. Note that I commended the prepare_agent=true:

## AGENT >> components coordinator ====================================
resource "aws_bedrockagent_agent" "pm_monitor_agent" {
  agent_name              = "pm_monitor_agent"
  agent_resource_role_arn = aws_iam_role.pm_monitor_agent_role.arn
  description             = file("${path.module}/agent-description.txt")
  foundation_model        = data.aws_bedrock_foundation_model.pm_monitor_llm.id
  instruction             = file("${path.module}/agent-instructions.txt")
#   prepare_agent           = true
}

//@fix: the "prepare_agent=true" in the agent resource above does not work
// as expected, so here you force the agent preparation and then you wait
// for it for about 1 minute before creating an agent alias from the agent
// draft prepared.
resource "null_resource" "prepare_agent" {
  depends_on = [aws_bedrockagent_agent.pm_monitor_agent]
  provisioner "local-exec" {
    command = <<EOF
      aws bedrock-agent prepare-agent \
          --region ${var.aws_region} \
          --agent-id ${aws_bedrockagent_agent.pm_monitor_agent.agent_id}
    EOF
    }
}

// MUST adjust this values according to the instructions
// and time needed by the agent to come in "PREPARED" status.
// A better way would be use the Agent events to notify a
// lambda and create the Agent Alias from the lambda
resource "time_sleep" "waiting_agent_to_be_prepared" {
  depends_on = [null_resource.prepare_agent]
  create_duration = local.waiting_agent_to_be_prepared_time_delay
}

resource "aws_bedrockagent_agent_alias" "pm_monitor_agent_alias" {
  agent_alias_name = "pm_monitor_agent_alias"
  agent_id         = aws_bedrockagent_agent.pm_monitor_agent.agent_id
  depends_on = [
    time_sleep.waiting_agent_to_be_prepared
  ]
}
profile picture
answered 2 months ago
0

hello , after you set up an agent, a working draft (DRAFT) version of your agent is created. You can continually iterate on the working draft by modifying its configurations, action groups, and knowledge bases. When you are ready to deploy your agent, you can create a version of your agent, which works as a snapshot of your agent at the time that you create the version. You create a version by creating an alias that points to it. You set up your application to invoke your agent by referring to the alias. Also you can find agentVersion examples in these links when using api to CreateAgentActionGroup: https://docs.aws.amazon.com/bedrock/latest/userguide/agents-action-add.html https://docs.aws.amazon.com/zh_cn/bedrock/latest/APIReference/API_agent_CreateAgentActionGroup.html

profile pictureAWS
SUPPORT ENGINEER
answered 2 months ago
  • Let me explain more... Working both with Terraform or aws-cli:

    1. I have Agent in DRAFT,
    2. DRAFT Agent has a fully working Action Group (tested)
    3. I have a Alias Version 1 created by the DRAFT
  • Issue 1: Alias Version 1 does not have the Action Group associated Rationate: Since the Agent prepare step is async and might take time, either Terraform/aws-cli might have created the Alias before the Agent is in prepared state. To make sure the Alias is created when the Agent is prepared, I did run the aws-cli command to update the existing alias::

    aws bedrock-agent update-agent-alias \
    --agent-alias-id xx \
    --agent-alias-name xx \
    --agent-id xx
    

    But the new Version 2 is created from Version 1 instead of from the DRAFT. As such also Version 2 does not have any Action Group associated.

  • I had a look and tried the API you are referring to, BTW they create new resources from scratch (CreateAgentActionGroup > creates it to the DRAF agent... not my case since I have it already. )

    That's why I was asking about command to associate an Action Group to an Agent Version... I see something similar for knowledge-bases:

    associate-agent-knowledge-base \
         --agent-id  \
         --agent-version > \
         --knowledge-base-id 
    

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions