DEV Community

Budiono Santoso
Budiono Santoso

Posted on

Deploy and Invoke AI Agent to AgentCore Runtime with Github Actions

What is Github Actions? Github Actions is a Github CI/CD (continuous integration/continous deployment or continous delivery) feature that automate end-to-end (build, test and deploy) workflow.

This tutorial blog explained how to deploy AI agent to AgentCore Runtime and test invoke AI agent using Github Actions.

REQUIREMENTS :

  1. AWS account (or AWS credentials), you can sign up/sign in here
  2. Google Gemini account, you can sign up/sign in here
  3. Langgraph
  4. Github account, you can sign up/sign in here.
  5. To get an IAM role for AgentCore Runtime, you can see this notebook then open and run the notebook.

FLASHBACK : I have already deploy production AI candidate screening agent to AgentCore Runtime in this tutorial blog. I think it is time to automate end-to-end workflow from deployment to testing invocation using CI/CD by Github Actions.

STEP-BY-STEP :

A. Follow this tutorial blog.

B. Follow this steps in Github repository:

  1. Create new repository, click Settings, click Secrets and variables in Security section, click Actions.
  2. Click Repository secrets then click "New repository secret".
  3. Input secret name and secret key : AWSACCESSKEY and your AWS access key & AWSSECRETKEY and your AWS secret key. Secret in Actions
  4. Click "Add secret". Now go to Github Codespaces to create IDE online.
  5. Choose repository, click "Create codespace".

C. Create workflow file to execute CI/CD automation workflow. In this tutorial, file name is workflow.yaml in .github/workflows folder. Write workflow code like this workflow code.

Explanation this workflow file :

  • on: push: mean when developer ready to deploy to AgentCore Runtime and invoke AI agent with git push automatically running.
  • on: push: paths: mean when developer update code from several files then push to repository and automatically running.
  • jobs: deploy: mean job running deploy to AgentCore Runtime.
  • steps mean running several steps with name of explanation.
  • outputs: mean workflow have output (agent runtime ID).
  • jobs: test: mean job running test invoke AI agent on AgentCore Runtime.
  • needs: mean need deploy job must running before running test job. If deploy job is failed, test job is not running.

D. Copy langgraph_agentcore.py and requirements.txt in requirements notebook then paste to runtime folder (in Github Codespaces).

E. Create deployment file to deploy AI agent to AgentCore Runtime. In this tutorial, file name is deploy-runtime.py. Write deployment code like this code.

Explanation this deployment code file :

  • # Retrieve AWS Account ID comment mean get AWS account ID that used in IAM execution role for AgentCore Runtime.
  • What different? Requirements notebook writing auto_create_execution_role=True mean automatically create IAM execution role while this deployment code writing auto_create_execution_role=False mean not need new IAM execution role and need input IAM execution role to execution_role.
  • agent_id = launch_result.agent_id mean agent runtime ID for invoke-agent.py file.

F. Create invocation file to invoke AI agent on AgentCore Runtime. In this tutorial, file name is invoke-agent.py. Write invocation code like this code.

Explanation this invocation code file :

  • # Get Agent Runtime ID mean get agent runtime ID from result in deploy-runtime.py file then get agent runtime ARN from agent runtime ID.

G. Add, commit and push all code to Github repository and automatically deploy AI agent to AgentCore Runtime and invoke AI agent.
Git command

NOTE : After push to Github repository then when deploy AI agent to AgentCore Runtime get error like this screenshot below.

ECR problem

Go to Amazon Bedrock AgentCore -> Agent runtime then click your agent name that already created.

Click "Version 1" then click IAM service role of Permissions like this screenshot.

IAM

This error is happened because ECRImageAccess action is allow bedrock-agentcore-gemini_langgraph repository only. How to fix? Click permission name, edit/modify permissions from bedrock-agentcore-gemini_langgraph to /* in policy editor then click Next and click Save.

Edit or modify IAM

After edit or modify IAM

Then add, commit and push all code again to Github repository. Go to Actions in this repository to see first push action.

First push

First push

First push

First push

First push

First push

First push

Go to AgentCore Runtime console like this screenshot.

Runtime

Runtime

Click "Dashboard" of Observability in Endpoints section to open AgentCore Observability.

Runtime

Agent metrics of AI agent runtime.

Agent metrics

System error, client error and throttle.

System error, client error and throttle

Runtime metrics of AI agent runtime.

Runtime metrics

CONCLUSION : With CI/CD automation workflow provided by Github Actions, deploy and invoke AI agent is easy, need IAM execution role only.

RESOURCES :

GITHUB REPOSITORY : https://github.com/budionosanai/agentcore-runtime-github-actions

Thank you,
Budi :)

Top comments (0)