- Newest
- Most votes
- Most comments
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
]
}
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
Relevant content
- AWS OFFICIALUpdated 9 months ago
- AWS OFFICIALUpdated 5 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 months ago
Let me explain more... Working both with Terraform or aws-cli:
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::
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: