Wallgent
Integrations

Add Payments to AWS Bedrock Agents

Connect Wallgent financial operations to AWS Bedrock Agents using action groups and Lambda.

Prerequisites

  • A Wallgent account and API key (get one here)
  • An AWS account with Bedrock access
  • Python 3.9+, boto3

1. Create the Lambda Handler

Bedrock Agents invoke a Lambda function for each action group tool call. This handler routes Wallgent operations:

import json
import os
import requests

API_KEY = os.environ["WALLGENT_API_KEY"]
BASE = "https://api.wallgent.com"
HEADERS = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
}


def lambda_handler(event, context):
    action = event["actionGroup"]
    function = event["function"]
    params = {p["name"]: p["value"] for p in event.get("parameters", [])}

    if function == "check_balance":
        wallet_id = params["wallet_id"]
        resp = requests.get(f"{BASE}/v1/wallets/{wallet_id}/balance", headers=HEADERS)
        body = resp.text

    elif function == "send_payment":
        resp = requests.post(
            f"{BASE}/v1/payments",
            headers=HEADERS,
            json={
                "from": params["from_wallet"],
                "to": params["to_wallet"],
                "amount": params["amount"],
                "description": params.get("description", ""),
            },
        )
        body = resp.text

    else:
        body = json.dumps({"error": f"Unknown function: {function}"})

    return {
        "messageVersion": "1.0",
        "response": {
            "actionGroup": action,
            "function": function,
            "functionResponse": {"responseBody": {"TEXT": {"body": body}}},
        },
    }

Deploy this Lambda with the WALLGENT_API_KEY environment variable set and requests included as a layer or in the deployment package.

2. Define the Action Group

In the Bedrock console (or via CloudFormation), create an action group with these function definitions:

Functions:
  - name: check_balance
    description: Check the available balance of a Wallgent wallet
    parameters:
      wallet_id:
        type: string
        description: The wallet ID to check
        required: true

  - name: send_payment
    description: Send a payment between two Wallgent wallets
    parameters:
      from_wallet:
        type: string
        description: Source wallet ID
        required: true
      to_wallet:
        type: string
        description: Destination wallet ID
        required: true
      amount:
        type: string
        description: Amount in USD (e.g. "25.00")
        required: true
      description:
        type: string
        description: Payment description
        required: false

Attach the Lambda function as the action group executor.

3. Invoke the Agent

import boto3
import json

client = boto3.client("bedrock-agent-runtime")

response = client.invoke_agent(
    agentId="YOUR_AGENT_ID",
    agentAliasId="YOUR_ALIAS_ID",
    sessionId="session-001",
    inputText="Check the balance of wal_ops, then send $25 to wal_vendor for hosting.",
)

for event in response["completion"]:
    if "chunk" in event:
        print(event["chunk"]["bytes"].decode(), end="")

Next Steps

  • Store your WALLGENT_API_KEY in AWS Secrets Manager for production use
  • Explore spending policies to set per-agent budgets
  • Set up webhooks for event-driven Lambda triggers
  • See the full REST API Reference for all available endpoints

On this page