Python Agent
Generate a Python AI agent for building agents with tools, and optionally deploy it to Amazon Bedrock AgentCore Runtime. Choose the agent framework with the framework option: Strands (the default) or LangChain (built on LangGraph).
The generator exposes your agent over a server protocol. Both frameworks support HTTP (the default), the Agent-to-Agent (A2A) protocol for interoperability with other A2A-compatible agents, and the AG-UI protocol for direct frontend integration via CopilotKit.
Generate an Agent
Section titled “Generate an Agent”You can generate a Python Agent in two ways:
- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - py#agent - Fill in the required parameters
- Click
Generate
pnpm nx g @aws/nx-plugin:py#agentyarn nx g @aws/nx-plugin:py#agentnpx nx g @aws/nx-plugin:py#agentbunx nx g @aws/nx-plugin:py#agentYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:py#agent --dry-runyarn nx g @aws/nx-plugin:py#agent --dry-runnpx nx g @aws/nx-plugin:py#agent --dry-runbunx nx g @aws/nx-plugin:py#agent --dry-runOptions
Section titled “Options”| Parameter | Type | Default | Description |
|---|---|---|---|
| project Required | string | - | The project to add the Agent to |
| framework | strands | langchain | strands | The agent SDK to use. |
| name | string | - | The name of your Agent (default: agent) |
| auth | iam | cognito | iam | The method used to authenticate with your Agent. Only applicable when infra is set (ignored when infra is none). |
| protocol | http | a2a | ag-ui | http | The server protocol for your Agent. HTTP exposes a FastAPI HTTP server. A2A exposes an Agent-to-Agent protocol server. AG-UI exposes an Agent-User Interaction protocol server for direct frontend integration. |
| iac | inherit | cdk | terraform | inherit | The preferred IaC provider. By default this is inherited from your initial selection. |
| infra | agentcore | none | agentcore | The type of infrastructure to host your Agent. |
| preferInstallDependencies | boolean | true | Whether to prefer installing dependencies after the generator runs. Set to false to defer installing when batching multiple generators (an install still runs if needed so subsequent generators can compute the Nx project graph); install once at the end. |
Generator Output
Section titled “Generator Output”The generator will add the following files to your existing Python project. The files generated depend on the chosen protocol:
HTTP Protocol (default)
Section titled “HTTP Protocol (default)”Directoryyour-project/
Directoryyour_module/
Directoryagent/ (or custom name if specified)
- __init__.py Python package initialization
- init.py FastAPI application setup with CORS and error handling middleware
- agent.py Main agent definition with sample tools
- main.py FastAPI entry point for Bedrock AgentCore Runtime
- Dockerfile Entry point for hosting your agent (excluded when
infrais set toNone)
- pyproject.toml Updated with Strands dependencies
- project.json Updated with agent serve targets
A2A Protocol
Section titled “A2A Protocol”The entry point exposes your agent over the A2A protocol (Strands uses the Strands A2A Server; LangChain wraps the graph in an a2a-sdk executor), mounted onto a FastAPI app:
Directoryyour-project/
Directoryyour_module/
Directoryagent/ (or custom name if specified)
- __init__.py Python package initialization
- agent.py Main agent definition with sample tools
- main.py A2A server entry point
- Dockerfile Entry point for hosting your agent (excluded when
infrais set toNone)
- pyproject.toml Updated with framework and A2A dependencies
- project.json Updated with agent serve targets
AG-UI Protocol
Section titled “AG-UI Protocol”The entry point exposes your agent via the AG-UI protocol for direct frontend integration with CopilotKit. Strands agents use the ag-ui-strands integration; LangChain agents use ag-ui-langgraph:
Directoryyour-project/
Directoryyour_module/
Directoryagent/ (or custom name if specified)
- __init__.py Python package initialization
- agent.py Main agent definition with sample tools
- main.py AG-UI server entry point
- Dockerfile Entry point for hosting your agent (excluded when
infrais set toNone)
- pyproject.toml Updated with framework and AG-UI dependencies
- project.json Updated with agent serve targets
Infrastructure
Section titled “Infrastructure”Since this generator vends infrastructure as code based on your chosen iacProvider, it will create a project in packages/common which includes the relevant CDK constructs or Terraform modules.
The common infrastructure as code project is structured as follows:
Directorypackages/common/constructs
Directorysrc
Directoryapp/ Constructs for infrastructure specific to a project/generator
- …
Directorycore/ Generic constructs which are reused by constructs in
app- …
- index.ts Entry point exporting constructs from
app
- project.json Project build targets and configuration
Directorypackages/common/terraform
Directorysrc
Directoryapp/ Terraform modules for infrastructure specific to a project/generator
- …
Directorycore/ Generic modules which are reused by modules in
app- …
- project.json Project build targets and configuration
For deploying your Agent, the following files are generated:
Directorypackages/common/constructs/src
Directoryapp
Directoryagents
Directory<project-name>
- <project-name>.ts CDK construct for deploying your agent
Directorypackages/common/terraform/src
Directoryapp
Directoryagents
Directory<project-name>
- <project-name>.tf Module for deploying your agent
Directorycore
Directoryagent-core
- runtime.tf Generic module for deploying to Bedrock AgentCore Runtime
If you selected none for infra, no CDK constructs or Terraform modules are generated — the Agent can only be run locally. The auth option is ignored in this mode since there is no hosted endpoint to authenticate.
Architecture
Section titled “Architecture”When deployed to Bedrock AgentCore Runtime, the agent is built into a container image, pushed to Amazon ECR and run in AgentCore Runtime. Clients invoke the AgentCore Runtime data plane endpoint, which forwards requests to your agent. The agent calls Amazon Bedrock for model inference and may invoke tools, MCP servers, or downstream APIs.
With infra: none, no AWS infrastructure is generated. The agent runs as a local process and calls Amazon Bedrock for model inference.
Working with Your Agent
Section titled “Working with Your Agent”You can edit agent.py to add tools, configure the model and customize the system prompt. The API depends on the framework you chose.
Adding Tools
Section titled “Adding Tools”Tools are functions that the AI agent can call to perform actions. Both frameworks use a decorator-based approach for defining tools, derive the tool name and description from the function name and docstring, and generate the input schema from your type hints.
from strands import Agent, tool
@tooldef calculate_sum(numbers: list[int]) -> int: """Calculate the sum of a list of numbers""" return sum(numbers)
@tooldef get_weather(city: str) -> str: """Get weather information for a city""" # Your weather API integration here return f"Weather in {city}: Sunny, 25°C"
# Add tools to your agentagent = Agent( system_prompt="You are a helpful assistant with access to various tools.", tools=[calculate_sum, get_weather],)from langchain.agents import create_agentfrom langchain_aws import ChatBedrockConversefrom langchain_core.tools import tool
@tooldef calculate_sum(numbers: list[int]) -> int: """Calculate the sum of a list of numbers""" return sum(numbers)
@tooldef get_weather(city: str) -> str: """Get weather information for a city""" # Your weather API integration here return f"Weather in {city}: Sunny, 25°C"
# Add tools to your agentagent = create_agent( model=ChatBedrockConverse(model=MODEL_ID, region_name=REGION), tools=[calculate_sum, get_weather], system_prompt="You are a helpful assistant with access to various tools.",)Using Pre-built Tools
Section titled “Using Pre-built Tools”Strands provides a collection of pre-built tools through the strands-tools package:
from strands_tools import current_time, http_request, file_read
agent = Agent( system_prompt="You are a helpful assistant.", tools=[current_time, http_request, file_read],)LangChain provides a large ecosystem of tools and integrations. Install the relevant integration package, then pass the tools to create_agent:
from langchain_community.tools import DuckDuckGoSearchRun
agent = create_agent( model=ChatBedrockConverse(model=MODEL_ID, region_name=REGION), tools=[DuckDuckGoSearchRun()], system_prompt="You are a helpful assistant.",)Model Configuration
Section titled “Model Configuration”By default, Strands agents use Claude 4 Sonnet, but you can customize the model provider. See the Strands documentation on model providers for configuration options:
from strands import Agentfrom strands.models import BedrockModel
# Create a BedrockModelbedrock_model = BedrockModel( model_id="anthropic.claude-sonnet-4-20250514-v1:0", region_name="us-west-2", temperature=0.3,)
agent = Agent(model=bedrock_model)LangChain agents use a ChatBedrockConverse model. The generated agent reads the model id and region from the MODEL_ID and AWS_REGION environment variables, but you can configure the model directly in agent.py:
from langchain_aws import ChatBedrockConverse
model = ChatBedrockConverse( model="anthropic.claude-sonnet-4-20250514-v1:0", region_name="us-west-2", temperature=0.3,)Consuming MCP Servers
Section titled “Consuming MCP Servers”For consuming MCP Servers which you have created using the py#mcp-server or ts#mcp-server generators you can make use of the connection generator, which wires the MCP server’s tools into your agent for both frameworks.
- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - connection - Fill in the required parameters
- Click
Generate
pnpm nx g @aws/nx-plugin:connectionyarn nx g @aws/nx-plugin:connectionnpx nx g @aws/nx-plugin:connectionbunx nx g @aws/nx-plugin:connectionYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:connection --dry-runyarn nx g @aws/nx-plugin:connection --dry-runnpx nx g @aws/nx-plugin:connection --dry-runbunx nx g @aws/nx-plugin:connection --dry-runRefer to the connection generator guide for details about how the connection is set up.
For other MCP servers, refer to the Strands or LangChain MCP documentation.
For a more in-depth guide to writing agents, refer to the Strands or LangChain documentation.
Protocol
Section titled “Protocol”Your agent’s server protocol determines how it communicates. All options are served by FastAPI — the entry point differs:
- HTTP (default): A standard FastAPI server with a custom
/invocationsendpoint, CORS, and streaming. Best for custom client integrations. - A2A: An Agent-to-Agent server mounted onto a FastAPI app (Strands uses the Strands A2A Server; LangChain uses the framework-agnostic
a2a-sdk). Best when your agent needs to be discoverable and invokable by other A2A-compatible agents. - AG-UI: The AG-UI protocol over SSE (Strands uses
ag-ui-strands; LangChain usesag-ui-langgraph). Best for direct frontend integration with CopilotKit in a React website.
The server entry point differs by framework (Strands yields a context-managed Agent, while LangChain drives a compiled create_agent graph), but the external contract for each protocol is the same.
All protocols expose /ping for the AgentCore runtime health check contract. A2A agents listen on port 9000; HTTP and AG-UI agents listen on port 8080. The generated Dockerfile and infrastructure are configured for you.
FastAPI Server (HTTP protocol)
Section titled “FastAPI Server (HTTP protocol)”The generated HTTP server includes:
- FastAPI application setup with CORS middleware
- Error handling middleware
- OpenAPI schema generation
- Health check endpoint (
/ping) - Agent invocation endpoint (
/invocations)
Customizing Invoke Inputs and Outputs with Pydantic
Section titled “Customizing Invoke Inputs and Outputs with Pydantic”The agent’s invocation endpoint uses Pydantic models to define and validate the request and response schemas. You can customize these models in main.py to match your agent’s requirements.
Defining Input Models
Section titled “Defining Input Models”The default InvokeInput model accepts a message.
from pydantic import BaseModel
class InvokeInput(BaseModel): message: strYou can extend this model to include any additional fields your agent needs.
The session ID is extracted from the x-amzn-bedrock-agentcore-runtime-session-id HTTP header, consistent with the Bedrock AgentCore Runtime session contract. If the header is not provided, a random UUID is generated as a fallback.
Defining Output Models
Section titled “Defining Output Models”For streaming responses, the generator provides JsonStreamingResponse which automatically serializes Pydantic models to JSON Lines format (application/jsonl). This format is compatible with OpenAPI 3.2’s streaming specification and works seamlessly with the generated TypeScript client.
By default, the agent yields StreamChunk objects containing the agent’s response text:
class StreamChunk(BaseModel): content: strYou can customise the StreamChunk model to suit your needs:
from pydantic import BaseModel
class StreamChunk(BaseModel): content: str timestamp: str token_count: intThere is an open feature request for native support in FastAPI.
Bedrock AgentCore Python SDK
Section titled “Bedrock AgentCore Python SDK”The generator includes a dependency on the Bedrock AgentCore Python SDK for the PingStatus constants. If desired, it is straightforward to use BedrockAgentCoreApp instead of FastAPI, however note that type-safety is lost.
You can find more details about the SDK’s capabilities in the documentation here.
A2A Server (A2A protocol)
Section titled “A2A Server (A2A protocol)”The generated main.py mounts an A2A server onto a parent FastAPI app that also exposes /ping. Strands agents use the Strands A2AServer; LangChain agents wrap the compiled graph in an a2a-sdk AgentExecutor. When deployed to AgentCore, the entry point resolves the runtime’s public ARN from AppConfig and advertises it in the agent card.
Most users will not need to modify this file; edit agent.py to change tools or the system prompt. The A2A server populates the agent card (/.well-known/agent-card.json) from the agent’s name and description.
AG-UI Server (AG-UI protocol)
Section titled “AG-UI Server (AG-UI protocol)”The generated main.py exposes a single POST endpoint that streams AG-UI events over Server-Sent Events (SSE), as well as /ping for the AgentCore runtime health check. The wiring depends on the framework:
- Strands: wraps your
Agentin anag_ui_strands.StrandsAgentand creates the FastAPI app viacreate_strands_app(). - LangChain: wraps the compiled graph in an
ag_ui_langgraph.LangGraphAgentand serves it from a hand-rolled FastAPI/invocationsloop.
Most users will not need to modify this file — edit agent.py to change tools or the system prompt.
Running Your Agent
Section titled “Running Your Agent”Local Development
Section titled “Local Development”To run your Agent (and everything connected to it) locally, use the project’s dev target:
pnpm nx dev your-projectyarn nx dev your-projectnpx nx dev your-projectbunx nx dev your-projectIf you have added multiple components to your project (agents, MCP servers, etc.), this starts them all. To run just this agent, target its <your-agent-name>-dev target:
pnpm nx agent-dev your-projectyarn nx agent-dev your-projectnpx nx agent-dev your-projectbunx nx agent-dev your-projectThis uses uv run to execute your Agent using the Bedrock AgentCore Python SDK.
Chat with Your Agent
Section titled “Chat with Your Agent”The generator configures a <your-agent-name>-chat Nx target that drops you into an interactive terminal chat with your agent.
The chat target runs standalone. By default it connects to your locally running agent, so start the agent’s <your-agent-name>-dev target first (in a separate terminal):
pnpm nx agent-dev your-projectyarn nx agent-dev your-projectnpx nx agent-dev your-projectbunx nx agent-dev your-projectThen, in another terminal, start the chat:
pnpm nx run your-project:agent-chatyarn nx run your-project:agent-chatnpx nx run your-project:agent-chatbunx nx run your-project:agent-chatThe generator emits a scripts/<your-agent-name>/chat.ts for every protocol. It connects to the local agent by default, or to your deployed agent when RUNTIME_CONFIG_APP_ID is set (see Chat with your deployed agent below).
For HTTP agents, the chat script uses a type-safe TypeScript client generated from the agent’s OpenAPI spec. The generator also emits:
scripts/<your-agent-name>_openapi.py— a small script that exports the agent’s OpenAPI spec- An
<your-agent-name>-openapiNx target that runs it - An
<your-agent-name>-generate-clientNx target that produces a type-safe TypeScript client underscripts/<your-agent-name>/generated/
When you customize the agent’s input shape (e.g. add new fields to InvokeInput), update chat.ts to pass the new fields when invoking the agent and the rest works automatically.
Chat with your deployed agent
Section titled “Chat with your deployed agent”To chat with your agent deployed to Bedrock AgentCore, set the RUNTIME_CONFIG_APP_ID environment variable to the AppConfig application id of the deployment (output as RuntimeConfigApplicationId by the deployed stack). The chat script resolves your agent’s runtime ARN from runtime configuration and connects to the deployed endpoint:
For IAM-authenticated agents, requests are signed with SigV4 using your default AWS credentials. Ensure the environment has AWS credentials with permission to invoke the runtime:
RUNTIME_CONFIG_APP_ID=<app-id> pnpm nx run your-project:agent-chatRUNTIME_CONFIG_APP_ID=<app-id> yarn nx run your-project:agent-chatRUNTIME_CONFIG_APP_ID=<app-id> npx nx run your-project:agent-chatRUNTIME_CONFIG_APP_ID=<app-id> bunx nx run your-project:agent-chatFor Cognito-authenticated agents, provide a Cognito access token via the AGENT_ACCESS_TOKEN environment variable, which is sent as a bearer token:
RUNTIME_CONFIG_APP_ID=<app-id> AGENT_ACCESS_TOKEN=<access-token> pnpm nx run your-project:agent-chatRUNTIME_CONFIG_APP_ID=<app-id> AGENT_ACCESS_TOKEN=<access-token> yarn nx run your-project:agent-chatRUNTIME_CONFIG_APP_ID=<app-id> AGENT_ACCESS_TOKEN=<access-token> npx nx run your-project:agent-chatRUNTIME_CONFIG_APP_ID=<app-id> AGENT_ACCESS_TOKEN=<access-token> bunx nx run your-project:agent-chatYou can obtain an access token using the AWS CLI’s cognito-idp admin-initiate-auth command, for example:
aws cognito-idp admin-initiate-auth \ --user-pool-id <user-pool-id> \ --client-id <user-pool-client-id> \ --auth-flow ADMIN_NO_SRP_AUTH \ --auth-parameters USERNAME=<username>,PASSWORD=<password> \ --query 'AuthenticationResult.AccessToken' \ --output textDeploying Your Agent to Bedrock AgentCore Runtime
Section titled “Deploying Your Agent to Bedrock AgentCore Runtime”Infrastructure as Code
Section titled “Infrastructure as Code”If you selected agentcore for infra, the relevant CDK or Terraform infrastructure is generated which you can use to deploy your Agent to Amazon Bedrock AgentCore Runtime.
A CDK construct is generated for your agent, named based on the name you chose when running the generator, or <ProjectName>Agent by default.
You can use this CDK construct in a CDK application:
import { MyProjectAgent } from ':my-scope/common-constructs';
export class ExampleStack extends Stack { constructor(scope: Construct, id: string) { new MyProjectAgent(this, 'MyProjectAgent'); }}A Terraform module is generated for you, named based on the name you chose when running the generator, or <ProjectName>-agent by default.
Pass the shared runtime_config_appconfig module’s outputs into the agent module:
module "my_project_agent" { source = "../../common/terraform/src/app/agents/my-project-agent"
appconfig_application_id = module.runtime_config_appconfig.application_id appconfig_application_arn = module.runtime_config_appconfig.application_arn}Authentication
Section titled “Authentication”The generator provides an auth option to configure authentication for your Agent. You can choose between IAM (default) or Cognito authentication when generating your agent.
By default, your Agent will be secured using IAM authentication, simply deploy it without any arguments:
import { MyProjectAgent } from ':my-scope/common-constructs';
export class ExampleStack extends Stack { constructor(scope: Construct, id: string) { new MyProjectAgent(this, 'MyProjectAgent'); }}You can grant access to invoke your agent on Bedrock AgentCore Runtime using the grantInvokeAccess method, for example:
import { MyProjectAgent } from ':my-scope/common-constructs';
export class ExampleStack extends Stack { constructor(scope: Construct, id: string) { const agent = new MyProjectAgent(this, 'MyProjectAgent'); const lambdaFunction = new Function(this, ...);
agent.grantInvokeAccess(lambdaFunction); }}# Agentmodule "my_project_agent" { # Relative path to the generated module in the common/terraform project source = "../../common/terraform/src/app/agents/my-project-agent"
appconfig_application_id = module.runtime_config_appconfig.application_id appconfig_application_arn = module.runtime_config_appconfig.application_arn}To grant access to invoke your agent, you will need to add a policy such as the following, referencing the module.my_project_agent.agent_core_runtime_arn output:
{ Effect = "Allow" Action = [ "bedrock-agentcore:InvokeAgentRuntime" ] Resource = [ module.my_project_agent.agent_core_runtime_arn, "${module.my_project_agent.agent_core_runtime_arn}/*" ]}Cognito Authentication
Section titled “Cognito Authentication”When you select Cognito authentication, the generator configures the agent to use Cognito for authentication.
The generated construct accepts an identity prop which configures Cognito authentication:
import { MyProjectAgent, UserIdentity } from ':my-scope/common-constructs';
export class ExampleStack extends Stack { constructor(scope: Construct, id: string) { const identity = new UserIdentity(this, 'Identity');
new MyProjectAgent(this, 'MyProjectAgent', { identity, }); }}The UserIdentity construct can be generated using the ts#website#auth generator, or you can create your own CDK UserPool and UserPoolClient.
The generated module accepts user_pool_id and user_pool_client_ids variables for Cognito authentication:
module "user_identity" { source = "../../common/terraform/src/core/user-identity"}
module "my_project_agent" { source = "../../common/terraform/src/app/agents/my-project-agent"
appconfig_application_id = module.runtime_config_appconfig.application_id appconfig_application_arn = module.runtime_config_appconfig.application_arn
user_pool_id = module.user_identity.user_pool_id user_pool_client_ids = [module.user_identity.user_pool_client_id]}Bundle and Docker Targets
Section titled “Bundle and Docker Targets”In order to build your Agent for Bedrock AgentCore Runtime, a bundle target is added to your project, which:
- Exports your Python dependencies to a
requirements.txtfile usinguv export - Installs dependencies for the target platform (
aarch64-manylinux_2_28) usinguv pip install
A docker target specific to your Agent is also added, which copies the Dockerfile and bundled artifacts into a docker context directory. This co-locates the Dockerfile with the built output, allowing CDK to build the Docker image directly using AgentRuntimeArtifact.fromAsset.
Observability
Section titled “Observability”Your agent is automatically configured with observability using the AWS Distro for Open Telemetry (ADOT), by configuring auto-instrumentation in your Dockerfile.
You can find traces in the CloudWatch AWS Console, by selecting “GenAI Observability” in the menu. Note that for traces to be populated you will need to enable Transaction Search.
For more details, refer to the AgentCore documentation on observability.
Invoking your Agent
Section titled “Invoking your Agent”Invoke the Local Server
Section titled “Invoke the Local Server”To invoke an Agent running locally via the <your-agent-name>-serve target, you can send a simple POST request to /invocations on the port your local agent is running on. For example, with curl:
curl -N -X POST http://localhost:8081/invocations \ -d '{"message": "what is 3 + 5?"}' \ -H "Content-Type: application/json"Invoke the Deployed Agent
Section titled “Invoke the Deployed Agent”To invoke your Agent deployed to Bedrock AgentCore Runtime, you can send a POST request to the Bedrock AgentCore Runtime dataplane endpoint with your URL-encoded runtime ARN.
You can obtain the runtime ARN from your infrastructure as follows:
import { CfnOutput } from 'aws-cdk-lib';import { MyProjectAgent } from ':my-scope/common-constructs';
export class ExampleStack extends Stack { constructor(scope: Construct, id: string) { const agent = new MyProjectAgent(this, 'MyProjectAgent');
new CfnOutput(this, 'AgentArn', { value: agent.agentCoreRuntime.agentRuntimeArn, }); }}# Agentmodule "my_project_agent" { # Relative path to the generated module in the common/terraform project source = "../../common/terraform/src/app/agents/my-project-agent"
appconfig_application_id = module.runtime_config_appconfig.application_id appconfig_application_arn = module.runtime_config_appconfig.application_arn}
output "agent_arn" { value = module.my_project_agent.agent_core_runtime_arn}The ARN will have the following format: arn:aws:bedrock-agentcore:<region>:<account>:runtime/<agent-runtime-id>.
You can then URL-encode the ARN by replacing : with %3A and / with %2F.
The Bedrock AgentCore Runtime dataplane URL for invoking the agent is as follows:
https://bedrock-agentcore.<region>.amazonaws.com/runtimes/<url-encoded-arn>/invocationsThe exact way to invoke this URL depends upon the authentication method used.
IAM Authentication
Section titled “IAM Authentication”For IAM Authentication, the request must be signed using AWS Signature Version 4 (SigV4).
acurl <region> bedrock-agentcore -N -X POST \'https://bedrock-agentcore.<region>.amazonaws.com/runtimes/<url-encoded-arn>/invocations' \-d '{"message": "what is 3 + 5?"}' \-H 'Content-Type: application/json'Sigv4 enabled curl
You can either add the following script to your .bashrc file (and source it) or paste the following into the same terminal you wish to run the command in.
acurl () { REGION=$1 SERVICE=$2 shift; shift; curl --aws-sigv4 "aws:amz:$REGION:$SERVICE" --user "$(aws configure get aws_access_key_id):$(aws configure get aws_secret_access_key)" -H "X-Amz-Security-Token: $(aws configure get aws_session_token)" "$@"}To make a sigv4 authenticated curl request, invoke acurl as follows:
acurl <region> <service> <other-curl-arguments>For example:
API Gateway
Section titled “API Gateway”acurl ap-southeast-2 execute-api -X GET https://xxxStreaming Lambda function url
Section titled “Streaming Lambda function url”acurl ap-southeast-2 lambda -N -X POST https://xxxYou can either add the following function to your PowerShell profile or paste the following into the same PowerShell session you wish to run the command in.
# PowerShell profile or current sessionfunction acurl { param( [Parameter(Mandatory=$true)][string]$Region, [Parameter(Mandatory=$true)][string]$Service, [Parameter(ValueFromRemainingArguments=$true)][string[]]$CurlArgs )
$AccessKey = aws configure get aws_access_key_id $SecretKey = aws configure get aws_secret_access_key $SessionToken = aws configure get aws_session_token
& curl --aws-sigv4 "aws:amz:$Region`:$Service" --user "$AccessKey`:$SecretKey" -H "X-Amz-Security-Token: $SessionToken" @CurlArgs}To make a sigv4 authenticated curl request, invoke acurl using these examples:
API Gateway
Section titled “API Gateway”acurl ap-southeast-2 execute-api -X GET https://xxxStreaming Lambda function url
Section titled “Streaming Lambda function url”acurl ap-southeast-2 lambda -N -X POST https://xxxJWT / Cognito Authentication
Section titled “JWT / Cognito Authentication”For Cognito Authentication, pass the Cognito Access Token in the Authorization header:
curl -N -X POST 'https://bedrock-agentcore.<region>.amazonaws.com/runtimes/<url-encoded-arn>/invocations' \ -d '{"message": "what is 3 + 5?"}' \ -H "Content-Type: application/json" \ -H "Authorization: Bearer <access-token>"You can obtain the access token using the AWS CLI’s cognito-idp admin-initiate-auth command, for example:
aws cognito-idp admin-initiate-auth \ --user-pool-id <user-pool-id> \ --client-id <user-pool-client-id> \ --auth-flow ADMIN_NO_SRP_AUTH \ --auth-parameters USERNAME=<username>,PASSWORD=<password> \ --region <region> \ --query 'AuthenticationResult.AccessToken' \ --output textBrowser / React Website
Section titled “Browser / React Website”For invoking your Agent from a React website, you can make use of the connection generator, which automatically sets up a client with the correct authentication (IAM or Cognito).
- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - connection - Fill in the required parameters
- Click
Generate
pnpm nx g @aws/nx-plugin:connectionyarn nx g @aws/nx-plugin:connectionnpx nx g @aws/nx-plugin:connectionbunx nx g @aws/nx-plugin:connectionYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:connection --dry-runyarn nx g @aws/nx-plugin:connection --dry-runnpx nx g @aws/nx-plugin:connection --dry-runbunx nx g @aws/nx-plugin:connection --dry-runRefer to the connection generator guide for details about how the connection is set up.
Invoking an A2A Agent as a Tool
Section titled “Invoking an A2A Agent as a Tool”To delegate work from this agent to a remote A2A agent (either TypeScript or Python), use the connection generator. It vends a SigV4-authenticated client for the target agent and AST-transforms this agent’s agent.py to register the remote A2A agent as a @tool-decorated delegate.
- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - connection - Fill in the required parameters
- Click
Generate
pnpm nx g @aws/nx-plugin:connectionyarn nx g @aws/nx-plugin:connectionnpx nx g @aws/nx-plugin:connectionbunx nx g @aws/nx-plugin:connectionYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:connection --dry-runyarn nx g @aws/nx-plugin:connection --dry-runnpx nx g @aws/nx-plugin:connection --dry-runbunx nx g @aws/nx-plugin:connection --dry-runRefer to the connection generator guide for details about how the connection is set up.
Invoking an AG-UI Agent
Section titled “Invoking an AG-UI Agent”To invoke your AG-UI agent from a React website, use the connection generator, which wires up a CopilotKit client configured for your deployed agent with the correct authentication (IAM or Cognito).
- Install the Nx Console VSCode Plugin if you haven't already
- Open the Nx Console in VSCode
- Click
Generate (UI)in the "Common Nx Commands" section - Search for
@aws/nx-plugin - connection - Fill in the required parameters
- Click
Generate
pnpm nx g @aws/nx-plugin:connectionyarn nx g @aws/nx-plugin:connectionnpx nx g @aws/nx-plugin:connectionbunx nx g @aws/nx-plugin:connectionYou can also perform a dry-run to see what files would be changed
pnpm nx g @aws/nx-plugin:connection --dry-runyarn nx g @aws/nx-plugin:connection --dry-runnpx nx g @aws/nx-plugin:connection --dry-runbunx nx g @aws/nx-plugin:connection --dry-runRefer to the connection generator guide for details about how the connection is set up.
Connections
Section titled “Connections”Use the connection generator to integrate this project with others in your workspace. The following connections involve this project: