From 54abc7e649477fdd2a706c7be4366c76428fc3cc Mon Sep 17 00:00:00 2001 From: Sai Abhishek Date: Thu, 19 Nov 2026 12:56:58 -0800 Subject: [PATCH 1/9] feat(gateway): Accept enableApplicationLogs and enableTraces The CDK library adds two optional fields to a gateway entry, on the branch `sa/box-gateway-vended-logs` of aws/agentcore-l3-cdk-constructs. When `enableApplicationLogs` is `true`, the gateway sends its `APPLICATION_LOGS` to CloudWatch Logs. When `enableTraces` is `true`, the gateway sends its `TRACES` to X-Ray. The CLI gateway schema does not accept an unknown field. Thus the CLI does not accept a project that sets one of the two fields, and a user cannot send the `TRACES` of a gateway to X-Ray. `AgentCoreGatewaySchema` has the two fields as optional booleans, with the same doc comments as the CDK library schema. The two fields have no schema default. The CLI writes the parsed spec back to `agentcore.json`, and a schema default adds the field to each project file. The default of `enableApplicationLogs` also changes with `boundRuntime`, and the CDK library applies it. The CLI has no other copy of the gateway schema that it must keep in step with the CDK library. The v0 schema in `src/projectSchemas/v0` is a frozen copy, and this change does not touch it. Tests: `gateway application logs and traces` in `src/projectSchemas/gateway.test.ts`. The schema accepts `true` and `false` for each field. Each value stays after the CLI writes the spec to JSON and reads it again. A gateway without the two fields has no such field after it is written and read again. The schema does not accept a string for each field. --- src/projectSchemas/gateway.test.ts | 31 ++++++++++++++++++++++++++++++ src/projectSchemas/gateway.ts | 13 +++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/projectSchemas/gateway.test.ts b/src/projectSchemas/gateway.test.ts index f4c788bf1..516a4481e 100644 --- a/src/projectSchemas/gateway.test.ts +++ b/src/projectSchemas/gateway.test.ts @@ -441,3 +441,34 @@ describe("gateway custom validation", () => { expect(imported.error?.issues[0]?.path).toEqual(["additionalPolicies"]); }); }); + +describe("gateway application logs and traces", () => { + const gateway = { name: "gateway", targets: [] }; + // FsReadWriteJson writes the parsed spec with JSON.stringify, so this is what agentcore.json keeps. + const roundTrip = (input: object) => + JSON.parse(JSON.stringify(AgentCoreGatewaySchema.parse(input))) as Record; + + it.each([true, false])("keeps enableApplicationLogs and enableTraces set to %p", (value) => { + const written = roundTrip({ ...gateway, enableApplicationLogs: value, enableTraces: value }); + + expect(written.enableApplicationLogs).toBe(value); + expect(written.enableTraces).toBe(value); + expect(roundTrip(written)).toEqual(written); + }); + + it("writes neither field back when the gateway does not set it", () => { + const written = roundTrip(gateway); + + expect("enableApplicationLogs" in written).toBe(false); + expect("enableTraces" in written).toBe(false); + }); + + it.each(["enableApplicationLogs", "enableTraces"])( + "rejects an %s that is not a boolean", + (field) => { + const parsed = AgentCoreGatewaySchema.safeParse({ ...gateway, [field]: "true" }); + + expect(parsed.error?.issues.map(({ path }) => path)).toEqual([[field]]); + }, + ); +}); diff --git a/src/projectSchemas/gateway.ts b/src/projectSchemas/gateway.ts index 48137dc0c..783f13c84 100644 --- a/src/projectSchemas/gateway.ts +++ b/src/projectSchemas/gateway.ts @@ -520,6 +520,19 @@ export const AgentCoreGatewaySchema = z * files relative to the project root. */ additionalPolicies: z.array(z.string().min(1)).optional(), + /** + * Deliver the gateway's `APPLICATION_LOGS` to the CloudWatch Logs group + * `/aws/vendedlogs/bedrock-agentcore/gateway/APPLICATION_LOGS/`. Defaults to true + * for a gateway with `boundRuntime` and to false for every other gateway. It has no schema + * default, because the default depends on `boundRuntime` and the CLI writes the parsed spec + * back to agentcore.json. + */ + enableApplicationLogs: z.boolean().optional(), + /** + * Deliver the gateway's `TRACES` to X-Ray. Defaults to false for every gateway, because the + * deploy fails in an account and Region without CloudWatch Transaction Search. + */ + enableTraces: z.boolean().optional(), tags: TagsSchema.optional(), }) .strict() From a2404eee3b54baa66e9b4dbe9d109cbe046152d2 Mon Sep 17 00:00:00 2001 From: Sai Abhishek Date: Thu, 19 Nov 2026 12:58:12 -0800 Subject: [PATCH 2/9] fix(status): Find the id of a target that two gateways have A project with two Box runtimes has two Box gateways. Each Box gateway has a `bedrock` target, and usually an `agentcore` target. The CDK library change on the branch `sa/box-gateway-vended-logs` of aws/agentcore-l3-cdk-constructs adds the gateway name to the export name of a target name that two or more gateways have: `GatewayTarget---Id`. `agentcore project status` looks for `GatewayTarget--Id` only. Thus, after a deploy, the status shows each of these targets as `local-only`. `identifierOf` in `src/core/project/backends/cdk.ts` looks for the name with the gateway first, and then for the name without the gateway. A target name that only one gateway has keeps the name without the gateway. Thus a project with one gateway finds its targets with no change. Tests: in `src/core/project/backends/cdk.test.ts`, the test `resolves a target name that two gateways share to each gateway's own id` gives two gateways with a `bedrock` target, and one of them also with an `egress-github` target. Each `bedrock` target gets the id of the gateway that has it, and `egress-github` gets the id from the name without the gateway. The test `resolves the target of one gateway through the export name without the gateway` gives one gateway with a `bedrock` target, and the target gets its id. --- src/core/project/backends/cdk.test.ts | 71 +++++++++++++++++++++++++++ src/core/project/backends/cdk.ts | 8 ++- 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/src/core/project/backends/cdk.test.ts b/src/core/project/backends/cdk.test.ts index d965a1c9d..d814c345d 100644 --- a/src/core/project/backends/cdk.test.ts +++ b/src/core/project/backends/cdk.test.ts @@ -1530,6 +1530,77 @@ describe("CdkBackend.resolveProjectResources", () => { expect(subject.accountCredentials).toEqual([]); }); + /** Each gateway's targets as `[gateway, [[target, id]...]]`; a target with no id has none. */ + const gatewayTargetIds = (resources: ResolvedProjectResource[]) => + resources + .filter(({ resourceType }) => resourceType === "gateway") + .map(({ name, children }) => [ + name, + (children ?? []).map((child) => [ + child.name, + child.deploymentState === "deployed" && "id" in child ? child.id : undefined, + ]), + ]); + + test("resolves a target name that two gateways share to each gateway's own id", async () => { + const input = await project(); + input.spec = { + ...input.spec, + agentCoreGateways: [ + { name: "agent-box", targets: [{ name: "bedrock" }, { name: "egress-github" }] }, + { name: "second_agent-box", targets: [{ name: "bedrock" }] }, + ], + } as unknown as typeof input.spec; + await updateTargetState(json, input.rootPath, TARGET.name, { stackArn: STACK_ARN }); + const subject = harness({ + describedStack: { + StackName: S, + CreationTime: new Date(0), + StackStatus: "CREATE_COMPLETE", + // The L3 adds the gateway name only for a target name that two or more gateways have. + Outputs: [ + out(`${S}-GatewayTarget-agent-box-bedrock-Id`, "bedrock-of-agent"), + out(`${S}-GatewayTarget-second-agent-box-bedrock-Id`, "bedrock-of-second"), + out(`${S}-GatewayTarget-egress-github-Id`, "github-of-agent"), + ], + }, + }); + + const resources = await subject.backend.resolveProjectResources(input, { target: TARGET }); + + expect(gatewayTargetIds(resources)).toEqual([ + [ + "agent-box", + [ + ["bedrock", "bedrock-of-agent"], + ["egress-github", "github-of-agent"], + ], + ], + ["second_agent-box", [["bedrock", "bedrock-of-second"]]], + ]); + }); + + test("resolves the target of one gateway through the export name without the gateway", async () => { + const input = await project(); + input.spec = { + ...input.spec, + agentCoreGateways: [{ name: "agent-box", targets: [{ name: "bedrock" }] }], + } as unknown as typeof input.spec; + await updateTargetState(json, input.rootPath, TARGET.name, { stackArn: STACK_ARN }); + const subject = harness({ + describedStack: { + StackName: S, + CreationTime: new Date(0), + StackStatus: "CREATE_COMPLETE", + Outputs: [out(`${S}-GatewayTarget-bedrock-Id`, "bedrock-1")], + }, + }); + + const resources = await subject.backend.resolveProjectResources(input, { target: TARGET }); + + expect(gatewayTargetIds(resources)).toEqual([["agent-box", [["bedrock", "bedrock-1"]]]]); + }); + test("nests a gateway's targets under the gateway", async () => { const input = await project(); input.spec = { diff --git a/src/core/project/backends/cdk.ts b/src/core/project/backends/cdk.ts index 94f5baa46..f3eb6c101 100644 --- a/src/core/project/backends/cdk.ts +++ b/src/core/project/backends/cdk.ts @@ -663,8 +663,12 @@ export class CdkBackend implements ProjectBackend { case "gateway": return asArn(byExportName("Gateway", name, "Arn")); case "gateway-target": - // The L3 exports an id for targets and never an ARN - return asId(byExportName("GatewayTarget", name, "Id")); + // The L3 exports an id for targets and never an ARN. A target name that two or more + // gateways have also has the gateway name: -GatewayTarget---Id. + return asId( + byExportName("GatewayTarget", owner ?? "", name, "Id") ?? + byExportName("GatewayTarget", name, "Id"), + ); case "policy": // ExportName: -Policy---Arn return asArn(byExportName("Policy", owner ?? "", name, "Arn")); From 34da4891c231e0c8a32270a371eea4b9e5fcf13f Mon Sep 17 00:00:00 2001 From: Sai Abhishek Date: Thu, 19 Nov 2026 13:59:04 -0800 Subject: [PATCH 3/9] feat(gateway): Write `enableApplicationLogs: true` in the Box gateway of a new Box project On the branch `sa/box-gateway-vended-logs` of aws/agentcore-l3-cdk-constructs, the CDK library sends the `APPLICATION_LOGS` of a gateway only when its entry sets `enableApplicationLogs: true`. This is the same for a gateway with `boundRuntime`. Before that change, a gateway with `boundRuntime` sent them when the entry did not set the field. Thus, after that change, a Box gateway without the field sends no logs. `boxGatewaySpec` writes `enableApplicationLogs: true`. Thus the Box gateway of a new Box project sends its `APPLICATION_LOGS`. `agentcore build` changes only the targets of a Box gateway. Thus a `false` that a user writes stays, and `agentcore build` does not add the field to a Box gateway without it. A Box project from a previous CLI version gets no new resources from a CDK update. The doc comment of the field gives the new default. Tests: in `manager.box.test.ts`, a Box template writes `enableApplicationLogs: true` in each Box gateway. In `manager.boxNetwork.test.ts`, `agentcore build` keeps a `false`, and does not add the field when the user removes it. Without the field in `boxGatewaySpec`, 2 tests show an error. With an `agentcore build` that writes `true` at each run, or only when the field is not there, 1 test shows an error. --- src/core/project/manager.box.test.ts | 1 + src/core/project/manager.boxNetwork.test.ts | 25 +++++++++++++++++++++ src/projectSchemas/gateway.ts | 7 +++--- src/projectSchemas/project.ts | 6 +++-- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/core/project/manager.box.test.ts b/src/core/project/manager.box.test.ts index 960638549..6fbd9948a 100644 --- a/src/core/project/manager.box.test.ts +++ b/src/core/project/manager.box.test.ts @@ -183,6 +183,7 @@ describe("agentcore create", () => { protocolType: "None", boundRuntime: "my_agent", discoveryPrefix: "AGENTCORE_GATEWAY_BOX", + enableApplicationLogs: true, targets: [], }); }); diff --git a/src/core/project/manager.boxNetwork.test.ts b/src/core/project/manager.boxNetwork.test.ts index c9c349d58..ee8af825f 100644 --- a/src/core/project/manager.boxNetwork.test.ts +++ b/src/core/project/manager.boxNetwork.test.ts @@ -201,6 +201,7 @@ async function boxGateway(root: string) { const spec = JSON.parse(await text(root, SPEC)); return spec.agentCoreGateways.find(({ name }: { name: string }) => name === GATEWAY) as { targets: Record[]; + enableApplicationLogs?: boolean; }; } @@ -301,6 +302,30 @@ describe("build writes the Box network of the box profile", () => { expect(Object.keys(await boxGateway(root))).not.toContain("enableSemanticSearch"); }); + test("keeps the enableApplicationLogs of the Box gateway as the user wrote it", async () => { + const { manager, root, box } = await strandsProject({ env: { GITHUB_TOKEN: "ghp_123" } }); + await editProfile(root, { tables: GITHUB_ROUTE }); + box.answer = shows({ github: GITHUB }); + expect((await boxGateway(root)).enableApplicationLogs).toBe(true); + + await editGateway(root, (gateway) => Object.assign(gateway, { enableApplicationLogs: false })); + await build(manager, root); + expect(await targetNames(root)).toContain("egress-github"); + expect((await boxGateway(root)).enableApplicationLogs).toBe(false); + + // Without the field the gateway sends no logs, and a build that changes the targets does not + // add the field back. + await editGateway(root, (gateway) => { + delete (gateway as { enableApplicationLogs?: boolean }).enableApplicationLogs; + }); + const profile = await text(root, PROFILE); + await writeFile(path(root, PROFILE), profile.replace(GITHUB_ROUTE, "")); + box.answer = shows(); + await build(manager, root); + expect(await targetNames(root)).not.toContain("egress-github"); + expect("enableApplicationLogs" in (await boxGateway(root))).toBe(false); + }); + test("writes no target for an env:// route whose key build cannot find, and says what to set", async () => { const { manager, root, box } = await strandsProject(); await editProfile(root, { tables: GITHUB_ROUTE }); diff --git a/src/projectSchemas/gateway.ts b/src/projectSchemas/gateway.ts index 783f13c84..b456a9c3d 100644 --- a/src/projectSchemas/gateway.ts +++ b/src/projectSchemas/gateway.ts @@ -522,10 +522,9 @@ export const AgentCoreGatewaySchema = z additionalPolicies: z.array(z.string().min(1)).optional(), /** * Deliver the gateway's `APPLICATION_LOGS` to the CloudWatch Logs group - * `/aws/vendedlogs/bedrock-agentcore/gateway/APPLICATION_LOGS/`. Defaults to true - * for a gateway with `boundRuntime` and to false for every other gateway. It has no schema - * default, because the default depends on `boundRuntime` and the CLI writes the parsed spec - * back to agentcore.json. + * `/aws/vendedlogs/bedrock-agentcore/gateway/APPLICATION_LOGS/`. Defaults to false + * for every gateway, because the logs can hold the request and response bodies of its MCP + * operations. */ enableApplicationLogs: z.boolean().optional(), /** diff --git a/src/projectSchemas/project.ts b/src/projectSchemas/project.ts index 81063b284..ed3644d7f 100644 --- a/src/projectSchemas/project.ts +++ b/src/projectSchemas/project.ts @@ -47,8 +47,9 @@ export const boxGatewayName = (runtimeName: string): string => `${runtimeName.replace(/_/g, "-")}${BOX_GATEWAY_SUFFIX}`; /** * The Box gateway entry of a runtime, as the CLI writes it: bound to that runtime, under the fixed - * variable prefix, `AWS_IAM` auth and `protocolType: "None"`. The CDK library binds it from - * `boundRuntime` and `discoveryPrefix`. + * variable prefix, `AWS_IAM` auth, `protocolType: "None"` and its `APPLICATION_LOGS` on. The CDK + * library binds it from `boundRuntime` and `discoveryPrefix`. Build changes only its targets, so a + * user's `enableApplicationLogs: false` stays. */ export const boxGatewaySpec = (runtimeName: string) => ({ name: boxGatewayName(runtimeName), @@ -56,6 +57,7 @@ export const boxGatewaySpec = (runtimeName: string) => ({ protocolType: "None" as const, boundRuntime: runtimeName, discoveryPrefix: BOX_GATEWAY_DISCOVERY_PREFIX, + enableApplicationLogs: true, targets: [], }); /** From 3b54f9846a50fb2ea75e9f49ff296b4d2210797b Mon Sep 17 00:00:00 2001 From: Sai Abhishek Date: Thu, 19 Nov 2026 18:23:43 -0800 Subject: [PATCH 4/9] fix(status): Find a gateway target id only by the export name that the CDK library writes Before this change, `identifierOf` looked for `GatewayTarget---Id` first, and then for `GatewayTarget--Id`. A gateway name and a target name can have a hyphen. Thus a target could get the id of a different target. An example is the gateway `a` with the target `b`, and the gateway `tools` with the target `a-b`. The target `b` got the id of `tools:a-b`. This occurred also with one gateway: `tools` with the targets `search` and `tools-search`. Also, a target of a new gateway that was not deployed got the id of the target of a different gateway with that name. After this change, the CLI counts the gateways in `agentCoreGateways` that have each target name. The CDK library does the same. For a target name that two or more gateways have, it looks only for `GatewayTarget-:-Id`. For a different target name, it looks only for `GatewayTarget--Id`. When the gateway itself has no deployed id, each of its targets is `local-only`. When a second gateway gets a target name of a deployed gateway, the two targets are `local-only` until the next deploy writes the new export names. Tests: in `cdk.test.ts`, one `test.each` with the gateway names of `boxGatewaySpec` has seven tests: a shared name, one gateway, the two hyphen examples above, a shared name with a hyphen, a shared name with only the export from before, and a gateway that is not deployed. The lookup of the previous commit makes 5 tests show an error. The two names in the other sequence with a fallback, a hyphen as the separator, and no check of the gateway each make 1 or 2 tests show an error. --- src/core/project/backends/cdk.test.ts | 159 ++++++++++++++++++++------ src/core/project/backends/cdk.ts | 34 ++++-- 2 files changed, 146 insertions(+), 47 deletions(-) diff --git a/src/core/project/backends/cdk.test.ts b/src/core/project/backends/cdk.test.ts index d814c345d..9259ffe4c 100644 --- a/src/core/project/backends/cdk.test.ts +++ b/src/core/project/backends/cdk.test.ts @@ -5,7 +5,7 @@ import { tmpdir } from "node:os"; import type { Stack } from "@aws-sdk/client-cloudformation"; import type { DeployResult, Project, ProjectEvent } from "../../../handlers/project/types"; import { FsReadWriteJson, ProcessFailedError } from "../../../io"; -import { ProjectSpecSchema } from "../../../projectSchemas/project"; +import { boxGatewaySpec, ProjectSpecSchema } from "../../../projectSchemas/project"; import { ProjectRuntimeSchema } from "../../../projectSchemas/runtime"; import { createSilentLogger } from "../../../testing"; import { TransactionSearchSetupError } from "../../../errors"; @@ -1542,49 +1542,127 @@ describe("CdkBackend.resolveProjectResources", () => { ]), ]); - test("resolves a target name that two gateways share to each gateway's own id", async () => { - const input = await project(); - input.spec = { - ...input.spec, - agentCoreGateways: [ - { name: "agent-box", targets: [{ name: "bedrock" }, { name: "egress-github" }] }, - { name: "second_agent-box", targets: [{ name: "bedrock" }] }, + const ONE = boxGatewaySpec("agent").name; + const TWO = boxGatewaySpec("second_agent").name; + /** A gateway and its target names; a deployed gateway, the target id exports, and the ids expected. */ + test.each([ + { + title: "a target name that two gateways share gets the id of its own gateway", + gateways: [ + [ONE, ["bedrock", "egress-github"]], + [TWO, ["bedrock"]], ], - } as unknown as typeof input.spec; - await updateTargetState(json, input.rootPath, TARGET.name, { stackArn: STACK_ARN }); - const subject = harness({ - describedStack: { - StackName: S, - CreationTime: new Date(0), - StackStatus: "CREATE_COMPLETE", - // The L3 adds the gateway name only for a target name that two or more gateways have. - Outputs: [ - out(`${S}-GatewayTarget-agent-box-bedrock-Id`, "bedrock-of-agent"), - out(`${S}-GatewayTarget-second-agent-box-bedrock-Id`, "bedrock-of-second"), - out(`${S}-GatewayTarget-egress-github-Id`, "github-of-agent"), - ], + deployed: [ONE, TWO], + exports: { + [`${ONE}:bedrock`]: "bedrock-of-one", + [`${TWO}:bedrock`]: "bedrock-of-two", + "egress-github": "github-of-one", }, - }); - - const resources = await subject.backend.resolveProjectResources(input, { target: TARGET }); - - expect(gatewayTargetIds(resources)).toEqual([ - [ - "agent-box", + expected: [ [ - ["bedrock", "bedrock-of-agent"], - ["egress-github", "github-of-agent"], + ONE, + [ + ["bedrock", "bedrock-of-one"], + ["egress-github", "github-of-one"], + ], ], + [TWO, [["bedrock", "bedrock-of-two"]]], ], - ["second_agent-box", [["bedrock", "bedrock-of-second"]]], - ]); - }); - - test("resolves the target of one gateway through the export name without the gateway", async () => { + }, + { + title: "the target of one gateway gets the export name without the gateway", + gateways: [[ONE, ["bedrock"]]], + deployed: [ONE], + exports: { bedrock: "bedrock-1" }, + expected: [[ONE, [["bedrock", "bedrock-1"]]]], + }, + { + title: + "a target name with a hyphen does not take the id of a gateway and target joined by a hyphen", + gateways: [ + ["a", ["b"]], + ["tools", ["a-b"]], + ], + deployed: ["a", "tools"], + exports: { b: "b-of-a", "a-b": "a-b-of-tools" }, + expected: [ + ["a", [["b", "b-of-a"]]], + ["tools", [["a-b", "a-b-of-tools"]]], + ], + }, + { + title: "a target of one gateway does not take the id of a target named after the gateway", + gateways: [["tools", ["search", "tools-search"]]], + deployed: ["tools"], + exports: { search: "search-1", "tools-search": "tools-search-1" }, + expected: [ + [ + "tools", + [ + ["search", "search-1"], + ["tools-search", "tools-search-1"], + ], + ], + ], + }, + { + title: + "a shared target name with a hyphen does not give its id to the target of another gateway", + gateways: [ + ["a", ["b-c"]], + ["x", ["b-c"]], + ["a-b", ["c"]], + ], + deployed: ["a", "x", "a-b"], + exports: { "a:b-c": "b-c-of-a", "x:b-c": "b-c-of-x", c: "c-of-a-b" }, + expected: [ + ["a", [["b-c", "b-c-of-a"]]], + ["x", [["b-c", "b-c-of-x"]]], + ["a-b", [["c", "c-of-a-b"]]], + ], + }, + { + title: + "a target name that two gateways share gives no id while the stack has only the export without the gateway", + gateways: [ + [ONE, ["bedrock"]], + [TWO, ["bedrock"]], + ], + deployed: [ONE], + exports: { bedrock: "bedrock-of-one" }, + expected: [ + [ONE, [["bedrock", undefined]]], + [TWO, [["bedrock", undefined]]], + ], + }, + { + title: + "a target of a gateway that is not deployed gives no id, also when an export has its name", + gateways: [ + [ONE, ["bedrock"]], + [TWO, ["egress-github"]], + ], + deployed: [ONE], + exports: { bedrock: "bedrock-of-one", "egress-github": "github-of-a-previous-deploy" }, + expected: [ + [ONE, [["bedrock", "bedrock-of-one"]]], + [TWO, [["egress-github", undefined]]], + ], + }, + ] as { + title: string; + gateways: [string, string[]][]; + deployed: string[]; + exports: Record; + expected: [string, [string, string | undefined][]][]; + }[])("$title", async ({ gateways, deployed, exports, expected }) => { const input = await project(); input.spec = { ...input.spec, - agentCoreGateways: [{ name: "agent-box", targets: [{ name: "bedrock" }] }], + agentCoreGateways: gateways.map(([name, targets]) => ({ + name, + targets: targets.map((target) => ({ name: target })), + })), } as unknown as typeof input.spec; await updateTargetState(json, input.rootPath, TARGET.name, { stackArn: STACK_ARN }); const subject = harness({ @@ -1592,13 +1670,18 @@ describe("CdkBackend.resolveProjectResources", () => { StackName: S, CreationTime: new Date(0), StackStatus: "CREATE_COMPLETE", - Outputs: [out(`${S}-GatewayTarget-bedrock-Id`, "bedrock-1")], + Outputs: [ + ...deployed.map((gateway) => + out(`${S}-Gateway-${gateway}-Arn`, `arn:gateway/${gateway}`), + ), + ...Object.entries(exports).map(([name, id]) => out(`${S}-GatewayTarget-${name}-Id`, id)), + ], }, }); const resources = await subject.backend.resolveProjectResources(input, { target: TARGET }); - expect(gatewayTargetIds(resources)).toEqual([["agent-box", [["bedrock", "bedrock-1"]]]]); + expect(gatewayTargetIds(resources)).toEqual(expected); }); test("nests a gateway's targets under the gateway", async () => { diff --git a/src/core/project/backends/cdk.ts b/src/core/project/backends/cdk.ts index f3eb6c101..a8ccfeb99 100644 --- a/src/core/project/backends/cdk.ts +++ b/src/core/project/backends/cdk.ts @@ -642,6 +642,14 @@ export class CdkBackend implements ProjectBackend { const asArn = (value: string | undefined) => (value ? { arn: value } : undefined); const asId = (value: string | undefined) => (value ? { id: value } : undefined); + // The L3 joins a target name that two or more gateways have to its gateway with a colon. + const gatewaysByTargetName = new Map(); + for (const gateway of spec.agentCoreGateways) { + for (const name of new Set((gateway.targets ?? []).map((target) => target.name))) { + gatewaysByTargetName.set(name, (gatewaysByTargetName.get(name) ?? 0) + 1); + } + } + const identifierOf = ( resourceType: DeployableResource, name: string, @@ -663,11 +671,11 @@ export class CdkBackend implements ProjectBackend { case "gateway": return asArn(byExportName("Gateway", name, "Arn")); case "gateway-target": - // The L3 exports an id for targets and never an ARN. A target name that two or more - // gateways have also has the gateway name: -GatewayTarget---Id. + // The L3 exports an id for targets and never an ARN. return asId( - byExportName("GatewayTarget", owner ?? "", name, "Id") ?? - byExportName("GatewayTarget", name, "Id"), + (gatewaysByTargetName.get(name) ?? 0) > 1 + ? byExportName("GatewayTarget", `${owner ?? ""}:${name}`, "Id") + : byExportName("GatewayTarget", name, "Id"), ); case "policy": // ExportName: -Policy---Arn @@ -734,13 +742,21 @@ export class CdkBackend implements ProjectBackend { ...spec.credentials.map(({ name }) => resolve("credential", name)), ...spec.evaluators.map(({ name }) => resolve("evaluator", name)), ...spec.onlineEvalConfigs.map(({ name }) => resolve("online-eval", name)), - ...spec.agentCoreGateways.map((gateway) => - resolve("gateway", gateway.name, { + ...spec.agentCoreGateways.map((gateway) => { + // A target of a gateway that is not deployed has no id, even when an export has its name. + const deployed = identifierOf("gateway", gateway.name) !== undefined; + return resolve("gateway", gateway.name, { children: (gateway.targets ?? []).map(({ name }) => - resolve("gateway-target", name, { owner: gateway.name }), + deployed + ? resolve("gateway-target", name, { owner: gateway.name }) + : { + resourceType: "gateway-target" as const, + name, + deploymentState: "local-only" as const, + }, ), - }), - ), + }); + }), ...spec.policyEngines.map((engine) => resolve("policy-engine", engine.name, { children: (engine.policies ?? []).map(({ name }) => From 14cf2109c33c93966ebb6da33b96840656f18ed4 Mon Sep 17 00:00:00 2001 From: Sai Abhishek Date: Thu, 19 Nov 2026 18:23:56 -0800 Subject: [PATCH 5/9] test: Remove the test that zod refuses a string, and a comment that tells the assertion again `gateway.test.ts` had a test that `AgentCoreGatewaySchema` refuses a string for each of the two fields. That is the behavior of `z.boolean()`, not a decision of this change. A comment in `manager.boxNetwork.test.ts` told again what the next assertion examines. The two are removed. --- src/core/project/manager.boxNetwork.test.ts | 2 -- src/projectSchemas/gateway.test.ts | 9 --------- 2 files changed, 11 deletions(-) diff --git a/src/core/project/manager.boxNetwork.test.ts b/src/core/project/manager.boxNetwork.test.ts index ee8af825f..174eae155 100644 --- a/src/core/project/manager.boxNetwork.test.ts +++ b/src/core/project/manager.boxNetwork.test.ts @@ -313,8 +313,6 @@ describe("build writes the Box network of the box profile", () => { expect(await targetNames(root)).toContain("egress-github"); expect((await boxGateway(root)).enableApplicationLogs).toBe(false); - // Without the field the gateway sends no logs, and a build that changes the targets does not - // add the field back. await editGateway(root, (gateway) => { delete (gateway as { enableApplicationLogs?: boolean }).enableApplicationLogs; }); diff --git a/src/projectSchemas/gateway.test.ts b/src/projectSchemas/gateway.test.ts index 516a4481e..3695d44e2 100644 --- a/src/projectSchemas/gateway.test.ts +++ b/src/projectSchemas/gateway.test.ts @@ -462,13 +462,4 @@ describe("gateway application logs and traces", () => { expect("enableApplicationLogs" in written).toBe(false); expect("enableTraces" in written).toBe(false); }); - - it.each(["enableApplicationLogs", "enableTraces"])( - "rejects an %s that is not a boolean", - (field) => { - const parsed = AgentCoreGatewaySchema.safeParse({ ...gateway, [field]: "true" }); - - expect(parsed.error?.issues.map(({ path }) => path)).toEqual([[field]]); - }, - ); }); From 6a48a1819ca2ab09e47644e3f4edd5fd276c442f Mon Sep 17 00:00:00 2001 From: Sai Abhishek Date: Thu, 19 Nov 2026 18:24:08 -0800 Subject: [PATCH 6/9] feat(create): Tell the user that a new Box gateway sends its logs, and how to stop them `agentcore create` writes `enableApplicationLogs: true` in the Box gateway of a new Box project. Thus the gateway sends its `APPLICATION_LOGS` to CloudWatch Logs, and the logs can hold the request and response bodies of its calls. CloudWatch Logs keeps them for 90 days, and the log group has no KMS key. Before this change, `create` did not tell the user about this. After this change, `create` gives a warning for each Box gateway with `enableApplicationLogs: true`. The warning says what the logs can hold, how long CloudWatch Logs keeps them, and that `"enableApplicationLogs": false` stops them. Tests: in `manager.boxNetwork.test.ts`, `create` of a Box project gives the warning. Without the warning, 1 test shows an error. --- src/core/project/manager.boxNetwork.test.ts | 12 +++++++++--- src/core/project/manager.tsx | 17 +++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/core/project/manager.boxNetwork.test.ts b/src/core/project/manager.boxNetwork.test.ts index 174eae155..847e90444 100644 --- a/src/core/project/manager.boxNetwork.test.ts +++ b/src/core/project/manager.boxNetwork.test.ts @@ -13,7 +13,7 @@ import type { DeployBackendInput, ProjectBackend } from "./backends/types"; import { boxShowOf, FakeBoxProfileResolver } from "./boxProfileResolver-test-support"; import type { ResolvedBoxProfile } from "./boxProfileResolver"; import { seedBoxCache } from "./backends/box-release-test-support"; -import { FsProjectManager } from "./manager"; +import { boxGatewayLogsNotice, FsProjectManager } from "./manager"; import { renderRuntimeBoxProfile } from "./templates/boxProfile"; /** The golden files of this suite; `RECORD=1 bun test ` rewrites them, with no AWS call. */ @@ -161,7 +161,7 @@ async function strandsProject( boxProfileResolver: box, ...(options.backends && { backends: options.backends }), }); - const { value: created } = await drain( + const { value: created, warnings: createWarnings } = await drain( manager.create({ name: "demo", scaffoldRuntimeInput: resolveRuntimeTemplateShortcut("agent-python-strands"), @@ -172,7 +172,7 @@ async function strandsProject( const root = created.rootPath; await mkdir(join(root, "agentcore", "cdk", "node_modules"), { recursive: true }); counter.specWrites = 0; - return { manager, root, counter, box }; + return { manager, root, counter, box, createWarnings }; } const path = (root: string, relative: string) => join(root, ...relative.split("/")); @@ -302,6 +302,12 @@ describe("build writes the Box network of the box profile", () => { expect(Object.keys(await boxGateway(root))).not.toContain("enableSemanticSearch"); }); + test("create says that the Box gateway sends its logs, and how to stop them", async () => { + const { createWarnings } = await strandsProject(); + + expect(createWarnings).toContain(boxGatewayLogsNotice(GATEWAY)); + }); + test("keeps the enableApplicationLogs of the Box gateway as the user wrote it", async () => { const { manager, root, box } = await strandsProject({ env: { GITHUB_TOKEN: "ghp_123" } }); await editProfile(root, { tables: GITHUB_ROUTE }); diff --git a/src/core/project/manager.tsx b/src/core/project/manager.tsx index 60097a5b6..3cebda7a2 100644 --- a/src/core/project/manager.tsx +++ b/src/core/project/manager.tsx @@ -614,6 +614,13 @@ export class FsProjectManager implements ProjectManager { `the project scaffolded at ${destination} could not be read back`, ); } + if (isBoxProject(project.spec)) { + for (const gateway of project.spec.agentCoreGateways) { + if (isBoundGateway(gateway) && gateway.enableApplicationLogs) { + yield { type: "warning", message: boxGatewayLogsNotice(gateway.name) }; + } + } + } return project; } @@ -2230,6 +2237,16 @@ function isInside(path: string, dir: string): boolean { ); } +/** What `create` tells the user about the `APPLICATION_LOGS` of a new Box gateway. */ +export function boxGatewayLogsNotice(gatewayName: string): string { + return ( + `the Box gateway '${gatewayName}' sends its APPLICATION_LOGS to CloudWatch Logs, which keeps ` + + "them for 90 days. They can hold the request and response bodies of its calls, prompts and " + + `completions included. To stop them, set "enableApplicationLogs": false on that gateway in ` + + "agentcore/agentcore.json" + ); +} + /** The strands-agents requirement from the rendered pyproject.toml, for EXPORT_NOTES.md. */ async function readStrandsVersion(agentDir: string): Promise { try { From aff8f148d0ba363b35a6474d6b65e77f3f558da9 Mon Sep 17 00:00:00 2001 From: Sai Abhishek Date: Thu, 19 Nov 2026 18:59:15 -0800 Subject: [PATCH 7/9] feat(add): Tell the user that the Box gateway of an added runtime sends its logs `add runtime` in a Box project writes a new Box gateway with `boxGatewaySpec`, thus with `enableApplicationLogs: true`. Before this change, only `create` told the user that the gateway sends its `APPLICATION_LOGS`, which can hold the request and response bodies of its calls. After this change, `boxGatewayLogsWarnings` gives the warning for each Box gateway with `enableApplicationLogs: true` in a list. `create` gives it for the Box gateways of the new project. `addBoxRuntime` gives it for the Box gateway that it writes. These are the two commands that write a new Box gateway. Tests: in `manager.box.test.ts`, `add runtime` gives the warning for its new gateway only. Each `create --template` test makes sure that a Box template gives the warning and that a different template does not. Without the warning of `add runtime`, 1 test shows an error. Without the warning of `create`, 3 tests show an error. With no warning from `boxGatewayLogsWarnings`, 4 tests show an error. --- src/core/project/manager.box.test.ts | 41 ++++++++++++++++++++++------ src/core/project/manager.tsx | 26 ++++++++++++------ 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/src/core/project/manager.box.test.ts b/src/core/project/manager.box.test.ts index d0b1205db..cadaca014 100644 --- a/src/core/project/manager.box.test.ts +++ b/src/core/project/manager.box.test.ts @@ -8,7 +8,7 @@ import type { AddResourceInput, Project } from "../../handlers/project/types"; import { resolveRuntimeTemplateShortcut } from "../../handlers/project/shortcuts"; import { createSilentLogger, TestIdentityClient } from "../../testing"; import { BOX_RELEASE } from "./backends/boxRelease"; -import { FsProjectManager } from "./manager"; +import { boxGatewayLogsNotice, FsProjectManager } from "./manager"; import { newProjectSpec } from "./templates/project"; import { boxGatewaySpec, ProjectSpecSchema } from "../../projectSchemas/project"; @@ -198,14 +198,18 @@ describe("agentcore create", () => { tempDirectories.push(directory); process.chdir(directory); - const project = await drain( - manager.create({ - name: "example", - skipInstall: true, - skipGit: true, - scaffoldRuntimeInput: resolveRuntimeTemplateShortcut(template, { runtimeName: "agent" }), - }), - ); + const warnings: string[] = []; + const generator = manager.create({ + name: "example", + skipInstall: true, + skipGit: true, + scaffoldRuntimeInput: resolveRuntimeTemplateShortcut(template, { runtimeName: "agent" }), + }); + let next = await generator.next(); + for (; !next.done; next = await generator.next()) { + if (next.value.type === "warning") warnings.push(next.value.message); + } + const project = next.value; // Only a box template runs its agent in a box, so only it makes a Box project. const spec = await specOnDisk(project); @@ -213,6 +217,7 @@ describe("agentcore create", () => { expect((spec.agentCoreGateways ?? []).map(({ name }) => name)).toEqual( projectType ? ["agent-box-egress"] : [], ); + expect(warnings.includes(boxGatewayLogsNotice("agent-box-egress"))).toBe(projectType === "box"); }); test('a Box template writes "projectType": "box" and a Box gateway for each runtime', () => { @@ -355,6 +360,24 @@ describe("gateway targets in a Box project", () => { ]); }); + test("add runtime says that the new Box gateway sends its logs, and how to stop them", async () => { + const manager = subject(); + const project = await createdProject(manager); + + const warnings: string[] = []; + const generator = manager.addResource(project, { + resourceType: "runtime", + resourceConfig: { name: "search", language: "Python", protocol: "HTTP" }, + } as never); + for (let next = await generator.next(); !next.done; next = await generator.next()) { + const event = next.value as { type: string; message?: string }; + if (event.type === "warning") warnings.push(event.message!); + } + + const notices = warnings.filter((warning) => warning.includes("APPLICATION_LOGS")); + expect(notices).toEqual([boxGatewayLogsNotice(boxGatewaySpec("search").name)]); + }); + test("add runtime refuses a Bedrock Agent import in a Box project, and changes nothing", async () => { const manager = subject(); const project = await createdProject(manager); diff --git a/src/core/project/manager.tsx b/src/core/project/manager.tsx index 4fe1dd29c..647e62493 100644 --- a/src/core/project/manager.tsx +++ b/src/core/project/manager.tsx @@ -628,13 +628,7 @@ export class FsProjectManager implements ProjectManager { `the project scaffolded at ${destination} could not be read back`, ); } - if (isBoxProject(project.spec)) { - for (const gateway of project.spec.agentCoreGateways) { - if (isBoundGateway(gateway) && gateway.enableApplicationLogs) { - yield { type: "warning", message: boxGatewayLogsNotice(gateway.name) }; - } - } - } + if (isBoxProject(project.spec)) yield* boxGatewayLogsWarnings(project.spec.agentCoreGateways); return project; } @@ -2128,7 +2122,8 @@ export class FsProjectManager implements ProjectManager { runtime.box = { version: BOX_RELEASE.version }; // start.py starts `box run` on AgentCore Runtime, and the profile runs the agent. runtime.entrypoint = BOX_CODEZIP_ENTRYPOINT; - projectSpec.agentCoreGateways.push(AgentCoreGatewaySchema.parse(boxGatewaySpec(name))); + const gateway = AgentCoreGatewaySchema.parse(boxGatewaySpec(name)); + projectSpec.agentCoreGateways.push(gateway); const appDir = join(projectRoot, ...runtime.codeLocation.split("/")); const startScript = join(appDir, BOX_CODEZIP_ENTRYPOINT); @@ -2151,6 +2146,7 @@ export class FsProjectManager implements ProjectManager { const boxFolder = join(projectRoot, ...boxAgentDir(name).split("/")); if (!existsSync(boxFolder)) scaffoldedPaths.push(boxFolder); yield* this.writeBoxProfile(projectRoot, projectSpec.name, boxInput, region); + yield* boxGatewayLogsWarnings([gateway]); } /** @@ -2369,7 +2365,7 @@ function isInside(path: string, dir: string): boolean { ); } -/** What `create` tells the user about the `APPLICATION_LOGS` of a new Box gateway. */ +/** What the CLI tells the user about the `APPLICATION_LOGS` of a Box gateway that it writes. */ export function boxGatewayLogsNotice(gatewayName: string): string { return ( `the Box gateway '${gatewayName}' sends its APPLICATION_LOGS to CloudWatch Logs, which keeps ` + @@ -2379,6 +2375,18 @@ export function boxGatewayLogsNotice(gatewayName: string): string { ); } +/** + * A warning for each gateway of `gateways` that is a Box gateway and sends its `APPLICATION_LOGS`. + * Each command that writes a new Box gateway gives these warnings: `create` and `add runtime`. + */ +function boxGatewayLogsWarnings( + gateways: readonly { name: string; boundRuntime?: string; enableApplicationLogs?: boolean }[], +): ProjectEvent[] { + return gateways + .filter((gateway) => isBoundGateway(gateway) && gateway.enableApplicationLogs) + .map((gateway) => ({ type: "warning", message: boxGatewayLogsNotice(gateway.name) })); +} + /** The strands-agents requirement from the rendered pyproject.toml, for EXPORT_NOTES.md. */ async function readStrandsVersion(agentDir: string): Promise { try { From fd93daaff078dde55d7b7cc4aaa7e95e1c3ef78a Mon Sep 17 00:00:00 2001 From: Sai Abhishek Date: Thu, 19 Nov 2026 18:59:16 -0800 Subject: [PATCH 8/9] test(status): Find the shared target of a gateway with an underscore in its name No target id test had a gateway name with an underscore. Thus no test examined the change from `_` to `-` in the export name `GatewayTarget-:-Id`. After this change, a test has the gateways `my_tools` and `other` with the target `search`. Without the change from `_` to `-` in `stackExportName`, 2 tests show an error. --- src/core/project/backends/cdk.test.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/project/backends/cdk.test.ts b/src/core/project/backends/cdk.test.ts index 85d93c22c..80b7278cd 100644 --- a/src/core/project/backends/cdk.test.ts +++ b/src/core/project/backends/cdk.test.ts @@ -1659,6 +1659,20 @@ describe("CdkBackend.resolveProjectResources", () => { ["a-b", [["c", "c-of-a-b"]]], ], }, + { + title: + "a shared target name of a gateway with an underscore gets the export name with a hyphen", + gateways: [ + ["my_tools", ["search"]], + ["other", ["search"]], + ], + deployed: ["my_tools", "other"], + exports: { "my-tools:search": "search-of-my-tools", "other:search": "search-of-other" }, + expected: [ + ["my_tools", [["search", "search-of-my-tools"]]], + ["other", [["search", "search-of-other"]]], + ], + }, { title: "a target name that two gateways share gives no id while the stack has only the export without the gateway", @@ -1710,7 +1724,7 @@ describe("CdkBackend.resolveProjectResources", () => { StackStatus: "CREATE_COMPLETE", Outputs: [ ...deployed.map((gateway) => - out(`${S}-Gateway-${gateway}-Arn`, `arn:gateway/${gateway}`), + out(`${S}-Gateway-${gateway.replace(/_/g, "-")}-Arn`, `arn:gateway/${gateway}`), ), ...Object.entries(exports).map(([name, id]) => out(`${S}-GatewayTarget-${name}-Id`, id)), ], From b05116c8b2b601791093a9622cc02ec4bc626526 Mon Sep 17 00:00:00 2001 From: Sai Abhishek Date: Fri, 20 Nov 2026 09:53:35 -0800 Subject: [PATCH 9/9] test(add): Give no Box gateway logs notice when the write of agentcore.json stops with an error A comment of Leo on this pull request (https://github.com/aws/agentcore-cli/pull/2860#discussion_r4638058352) tells that `add runtime` gave the logs `warning` of the new Box gateway before the write of agentcore.json. When that write stopped with an error, the user saw the `warning` for a gateway that agentcore.json did not have. `create` gives its `warning` only after the write. The merge before this commit moves the `warning` of `add runtime` to after the write. This commit adds a test for that sequence. The test gives `addResource` a JSON writer that refuses the write of agentcore.json, thus the test does not use file modes, and root gets the same result. `refusingSpecWrites` holds that writer. The test of the default log target from `box-integration` also uses it. Tests: in `manager.box.test.ts`, the new test makes sure that the add wrote the box profile of the runtime, and then gave no logs `warning`. It also makes sure that agentcore.json did not change. With the `warning` in `addBoxRuntime`, the new test and the test of the default log target show an error. With the `warning` in `addResource` immediately before the write, the two tests show an error. With no `warning` from `add runtime`, the test that `add runtime` gives the `warning` shows an error. --- src/core/project/manager.box.test.ts | 47 ++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 10 deletions(-) diff --git a/src/core/project/manager.box.test.ts b/src/core/project/manager.box.test.ts index d5f7046f7..9fe6b1320 100644 --- a/src/core/project/manager.box.test.ts +++ b/src/core/project/manager.box.test.ts @@ -44,6 +44,18 @@ function subject(json?: ReadWriteJson): FsProjectManager { }); } +/** A JSON reader and writer that refuses each write of `specFile`, for each user, root too. */ +function refusingSpecWrites(specFile: string): ReadWriteJson { + const files = new FsReadWriteJson({ logger: createSilentLogger() }); + return { + read: (path, schema) => files.read(path, schema), + write: async (path, data) => { + if (path === specFile) throw new Error(`the test refuses the write of ${path}`); + return files.write(path, data); + }, + }; +} + async function drain(generator: AsyncGenerator): Promise { while (true) { const next = await generator.next(); @@ -616,16 +628,7 @@ describe("gateway targets in a Box project", () => { test("a failed write of agentcore.json gives no notice of the default log target", async () => { const project = await createdProject(subject()); const specFile = join(project.rootPath, "agentcore", "agentcore.json"); - // The write of agentcore.json fails for each user, root too; each other file is written. - const files = new FsReadWriteJson({ logger: createSilentLogger() }); - const json: ReadWriteJson = { - read: (path, schema) => files.read(path, schema), - write: async (path, data) => { - if (path === specFile) throw new Error(`the test refuses the write of ${path}`); - return files.write(path, data); - }, - }; - const generator = subject(json).addResource(project, { + const generator = subject(refusingSpecWrites(specFile)).addResource(project, { resourceType: "runtime", resourceConfig: { name: "search", language: "Python", protocol: "HTTP" }, } as never); @@ -641,6 +644,30 @@ describe("gateway targets in a Box project", () => { expect(events.some((event) => (event as { type?: string }).type === "warning")).toBe(false); }); + test("a failed write of agentcore.json gives no notice that the new Box gateway sends its logs", async () => { + const project = await createdProject(subject()); + const specFile = join(project.rootPath, "agentcore", "agentcore.json"); + const before = await specText(project); + const generator = subject(refusingSpecWrites(specFile)).addResource(project, { + resourceType: "runtime", + resourceConfig: { name: "search", language: "Python", protocol: "HTTP" }, + } as never); + const messages: (string | undefined)[] = []; + + await expect( + (async () => { + for (let next = await generator.next(); !next.done; next = await generator.next()) { + messages.push((next.value as { message?: string }).message); + } + })(), + ).rejects.toThrow(`the test refuses the write of ${specFile}`); + // The add wrote the box profile of the new runtime, and then the write of agentcore.json failed. + const profile = join(project.rootPath, ".box", "search", "local", "profile.toml"); + expect(messages).toContain(`writing box profile ${profile}`); + expect(messages).not.toContain(boxGatewayLogsNotice(boxGatewaySpec("search").name)); + expect(await specText(project)).toBe(before); + }); + test("add runtime warns when the kept box profile is for another protocol", async () => { const manager = subject(); let project = await createdProject(manager, ["agent", "search"]);