lambda-deploy

Ship the same agent code from react-tool-agent as an AWS Lambda function. Each event pushed to the S3 session bucket invokes the handler exactly once: same script, same log-replay shape, same fork/replay semantics, now running on serverless infrastructure. Full source on GitHub.

What’s in this example

FilePurpose
main.tfTerraform module that creates an S3 bucket, IAM role (via terraform/resources/aws/engine), and Lambda function (via terraform/resources/aws/function).
DockerfileContainer image bundling pugmark + the Python SDK + the handler. Lambda needs an OCI image, not a zipfile, for this use case.
handler.pyTrivially re-exports the react-tool-agent script so there’s only one source of truth.

Prerequisites

Deploy

# 1. Build and push the handler image (replace the ECR repo URI with your own).
docker build -t my-pugmark-handler:0.1.0 examples/lambda-deploy/
docker tag my-pugmark-handler:0.1.0 <account>.dkr.ecr.<region>.amazonaws.com/pugmark-handler:0.1.0
docker push                          <account>.dkr.ecr.<region>.amazonaws.com/pugmark-handler:0.1.0

# 2. Apply terraform.
cd examples/lambda-deploy
terraform init
terraform apply \
    -var "region=us-east-1" \
    -var "image=<account>.dkr.ecr.<region>.amazonaws.com/pugmark-handler:0.1.0"

Drive a session from your laptop

The local pugmark CLI talks directly to the S3 bucket; Lambda picks up the work via S3 object-creation events.

pugmark switch "$(terraform output -raw session_bucket_uri)"   # work against the S3 bucket

pugmark start
pugmark push <<<'{"kind":"user_message","text":"What is 17 * 23, then halve it?"}'

# Tail the Lambda's logs to watch each event land.
aws logs tail "$(terraform output -raw log_group)" --follow

# Once the agent pauses, inspect the result.
pugmark log -A

The same fork-mid-run trick on Lambda

Fork from any snapshot. The new session is just another S3 prefix, so subsequent pushes trigger the same handler:

pugmark fork -s <session>:3
pugmark push <<<'{"kind":"tool_result","id":"<id from log>","content":"42"}'
# Lambda fires automatically as the new event lands in S3.

The handler code never changed; the runtime is what moved. That’s the whole point of pugmark as substrate.