You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: agent/README.md
+48-30Lines changed: 48 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ No other permissions are needed.
32
32
33
33
The agent uses Amazon Bedrock for Claude inference. You need credentials with `bedrock:InvokeModel` and `bedrock:InvokeModelWithResponseStream` permissions.
34
34
35
-
Two options for passing credentials to the container:
35
+
Common ways to pass credentials into the container (when using `run.sh`):
36
36
37
37
**Option A** — Environment variables:
38
38
```bash
@@ -42,7 +42,9 @@ export AWS_SESSION_TOKEN="..." # if using temporary credentials
**Option B** — AWS CLI resolution (recommended for SSO): `run.sh` runs `aws configure export-credentials` when the AWS CLI is installed, so you can use `aws sso login` and optionally `AWS_PROFILE` without mounting `~/.aws`.
46
+
47
+
**Option C** — Mount `~/.aws` read-only (static access keys in files; SSO often does not work inside the container):
46
48
```bash
47
49
export AWS_PROFILE="my-profile"
48
50
export AWS_REGION="us-east-1"
@@ -53,6 +55,7 @@ export AWS_REGION="us-east-1"
53
55
```bash
54
56
export GITHUB_TOKEN="ghp_..."
55
57
export AWS_REGION="us-east-1"
58
+
# Either export keys, or run `aws sso login` (and optionally AWS_PROFILE) and let run.sh resolve credentials
56
59
export AWS_ACCESS_KEY_ID="..."
57
60
export AWS_SECRET_ACCESS_KEY="..."
58
61
@@ -86,19 +89,19 @@ The `run.sh` script overrides the container's default CMD to run `python /app/en
86
89
|----------|----------|---------|-------------|
87
90
|`GITHUB_TOKEN`| Yes || Fine-grained PAT (see permissions above) |
88
91
|`AWS_REGION`| Yes || AWS region for Bedrock (e.g., `us-east-1`) |
89
-
|`AWS_ACCESS_KEY_ID`|Yes*||AWS credentials|
90
-
|`AWS_SECRET_ACCESS_KEY`|Yes*||AWS credentials|
92
+
|`AWS_ACCESS_KEY_ID`|Conditional†||Explicit keys, if you are not using CLI-based resolution|
93
+
|`AWS_SECRET_ACCESS_KEY`|Conditional†||Explicit keys, if you are not using CLI-based resolution|
91
94
|`AWS_SESSION_TOKEN`| No || For temporary credentials |
92
-
|`AWS_PROFILE`|Yes*||Alternative to explicit keys (mounts `~/.aws`)|
95
+
|`AWS_PROFILE`|No||Profile for `aws configure export-credentials` in `run.sh`, or default profile when using the `~/.aws` mount fallback|
93
96
|`ANTHROPIC_MODEL`| No |`us.anthropic.claude-sonnet-4-6`| Bedrock model ID |
94
97
|`MAX_TURNS`| No |`100`| Max agent turns before stopping |
95
-
|`MAX_BUDGET_USD`| No ||Max cost budget in USD (0.01–100). Agent stops when budget is reached. |
98
+
|`MAX_BUDGET_USD`| No ||**Local batch only** (shell env when running `entrypoint.py` directly). Range 0.01–100; agent stops when the budget is reached. For deployed AgentCore **server** mode and production tasks, set **`max_budget_usd`** on task creation (REST API, CLI `--max-budget`, or Blueprint default); the orchestrator sends it in the `/invocations` JSON body — server mode does not read `MAX_BUDGET_USD` from the environment. |
96
99
|`DRY_RUN`| No || Set to `1` to validate config and print the prompt without running the agent |
97
100
|`ANTHROPIC_DEFAULT_HAIKU_MODEL`| No |`anthropic.claude-haiku-4-5-20251001-v1:0`| Bedrock model ID for the pre-flight safety check (see below) |
98
101
99
102
**Pre-flight check model**: Claude Code runs a quick safety verification using a small Haiku model before executing each tool command. On Bedrock, the default Haiku model ID may not be enabled in your account, causing the check to time out with *"Pre-flight check is taking longer than expected"* warnings. The agent sets `ANTHROPIC_DEFAULT_HAIKU_MODEL` to a known-available Bedrock Haiku model ID to avoid this. If you see pre-flight timeout warnings, verify that this model is enabled in your Bedrock model access settings.
100
103
101
-
\* Provide either `AWS_ACCESS_KEY_ID`/`AWS_SECRET_ACCESS_KEY` or `AWS_PROFILE`.
104
+
† You need valid Bedrock credentials in the container: export keys (Option A), let `run.sh` inject keys from the AWS CLI after `aws sso login` or similar (Option B), or mount `~/.aws` (Option C). `run.sh` also sets `CLAUDE_CODE_USE_BEDROCK=1` so Claude Code uses Bedrock.
@@ -131,47 +137,51 @@ To be safe, the agent isolates each task into its own workspace directory:
131
137
132
138
**`GET /ping`** — Health check. Returns `{"status": "healthy"}`. Stays responsive while the agent runs.
133
139
134
-
**`POST /invocations`** — Run the agent. Blocks until complete.
140
+
**`POST /invocations`** — Accept a task and start the agent in a **background thread**. The handler returns **immediately** with an acceptance payload; it does not wait for the agent to finish. While the task runs, progress and the final outcome are written to **DynamoDB** when `TASK_TABLE_NAME` is set (see `task_state.py`); the deployed platform polls that table via the orchestrator. For ad-hoc local testing without DynamoDB, follow **`docker logs -f bgagent-run`** (or your container name).
141
+
142
+
Request payload (representative fields — the API orchestrator sends a fuller object including hydrated GitHub/issue context):
135
143
136
-
Request payload:
137
144
```json
138
145
{
139
146
"input": {
140
-
"prompt": "update the rfc issue template to add a codeowners field",
147
+
"task_id": "9e285dba622d",
141
148
"repo_url": "owner/repo",
149
+
"prompt": "update the rfc issue template to add a codeowners field",
All fields in `input` fall back to container environment variables if omitted. Secrets like `GITHUB_TOKEN` should be set as runtime environment variables via the CDK stack — not sent in the payload, since AgentCore logs the full request payload in plain text.
159
+
-`task_id` — Correlates with DynamoDB and logs; if omitted for local experiments, the agent generates a short id.
160
+
-`model_id` — Preferred key from the orchestrator; `anthropic_model` is also accepted.
161
+
- Optional platform fields (when using the full stack) include `hydrated_context`, `system_prompt_overrides`, `prompt_version`, and `memory_id`.
162
+
163
+
All fields in `input` fall back to container environment variables when omitted. Secrets like `GITHUB_TOKEN` should be set as runtime environment variables via the CDK stack — not sent in the payload, since AgentCore logs the full request payload in plain text.
Final metrics (PR URL, cost, turns, build status, etc.) appear in **container logs**, in **DynamoDB** when configured, and in the **REST API** for deployed tasks (`GET /v1/tasks/{task_id}` via the `bgagent` CLI or HTTP client).
184
+
175
185
### Testing Server Mode Locally
176
186
177
187
Use `run.sh --server` to build and start the server locally. It handles credentials, port mapping, and resource constraints automatically:
2.**Context hydration** — fetches the GitHub issue (title, body, comments) if an issue number is provided
249
259
3.**Prompt assembly** — combines the system prompt (behavioral contract) with the issue context and task description
250
-
4.**Deterministic pre-hooks** — clones repo, creates branch, configures git auth, runs `mise trust`, `mise install`, and `mise run build`
260
+
4.**Deterministic pre-hooks** — clones repo, creates branch, configures git auth, runs `mise trust`, `mise install`, `mise run build`, and `mise run lint`
251
261
5.**Agent execution** — invokes the Claude Agent SDK via the `ClaudeSDKClient` class (connect/query/receive_response pattern) in unattended mode. The agent:
252
262
- Understands the codebase
253
263
- Makes changes, runs tests and linters
254
264
- Commits and pushes after each unit of work
255
265
- Creates a pull request with summary, testing notes, and decisions
256
-
6.**Deterministic post-hooks** — verifies build (`mise run build`), ensures PR exists (creates one if the agent didn't)
266
+
6.**Deterministic post-hooks** — verifies `mise run build` and `mise run lint`, ensures a PR exists (creates one if the agent did not)
257
267
7.**Metrics** — returns duration, disk usage, turn count, cost, and PR URL
The container **CMD** runs the app under `opentelemetry-instrument` with **uvicorn** using the **asyncio** event loop (not uvloop), avoiding known subprocess issues with uvloop.
- A **GitHub personal access token** (PAT) with permission to access every repository you onboard (clone, push to branches, create and update pull requests). After deployment, store it in the Secrets Manager secret the stack creates ([Post-deployment setup](#post-deployment-setup)); for local agent runs, export `GITHUB_TOKEN` (see **Local testing** below). Required scopes are documented in `agent/README.md`.
Without this, `cdk deploy` will fail with: *"X-Ray Delivery Destination is supported with CloudWatch Logs as a Trace Segment Destination."*
90
90
91
-
You can use the command below to install the dependencies listed above
92
-
```
91
+
Install [mise](https://mise.jdx.dev/getting-started.html) using the official guide; it is not installed via npm. For the Node-based CLIs, run:
92
+
93
+
```bash
93
94
npm install -g npm aws-cdk yarn projen
94
95
```
95
96
@@ -188,11 +189,13 @@ docker exec -it bgagent-run bash # shell into the container
188
189
|`MAX_TURNS`|`100`| Max agent turns before stopping |
189
190
|`DRY_RUN`|| Set to `1` to validate config and print prompt without running the agent |
190
191
192
+
**Cost budget** is not configured here for production tasks: set **`max_budget_usd`** when creating a task (REST API, CLI `--max-budget`, or per-repo Blueprint). The orchestrator passes it in the runtime invocation payload. The optional env var `MAX_BUDGET_USD` applies only to **local batch** runs; see `agent/README.md`.
193
+
191
194
For the full list of environment variables and GitHub PAT permissions, see `agent/README.md`.
192
195
193
196
### Deployment
194
197
195
-
Once your agent works locally, you can deploy it on AWS.
198
+
Once your agent works locally, you can deploy it on AWS. A **full**`npx projen deploy` of this stack has been observed at **~572 seconds (~9.5 minutes)** total (CDK-reported *Total time*); expect variation by Region, account state, and whether container layers are already cached.
196
199
197
200
1. Generate project files (dependencies, etc.) from the configuration file and install them.
Use the **same AWS Region** (and profile) as `npx projen deploy`. If you omit `--region`, the CLI uses your default from `aws configure`; when the stack lives in another Region, `describe-stacks` fails, **stderr** shows the error, and capturing stdout into a shell variable (for example `SECRET_ARN=$(...)`) yields **empty** with no obvious hint—run the `aws` command without `$(...)` to see the message. Add `--region your-region` to every command below if needed.
249
+
250
+
If `put-secret-value` returns **`Invalid endpoint: https://secretsmanager..amazonaws.com`** (note the **double dot**), the effective Region string is **empty**—for example `REGION=` was never set, `export REGION` is blank, or `--region "$REGION"` expands to nothing. Set `REGION` to a real value (e.g. `us-east-1`) or run `aws configure set region your-region` so the default is non-empty.
251
+
245
252
#### Set the GitHub token
246
253
247
254
The agent reads the GitHub personal access token from Secrets Manager at startup. After deploying, store your PAT in the secret:
If `SECRET_ARN` is still empty after setting `REGION`, list outputs in that Region (`describe-stacks` … `--query 'Stacks[0].Outputs' --output table`) and confirm the row `GitHubTokenSecretArn` exists—wrong stack name or an incomplete deployment are the other common causes.
274
+
258
275
See `agent/README.md` for the required PAT permissions.
0 commit comments