@aws/agentcore 1.0.0-preview.2 → 1.0.0-preview.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +193 -33
- package/dist/agent-inspector/index.css +1 -1
- package/dist/agent-inspector/index.js +99 -84
- package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +3132 -366
- package/dist/assets/__tests__/__snapshots__/dockerfile-render.test.ts.snap +6 -2
- package/dist/assets/__tests__/assets.snapshot.test.ts +10 -24
- package/dist/assets/__tests__/googleadk-session-eviction.test.ts +87 -0
- package/dist/assets/__tests__/summarization-namespace.test.ts +43 -0
- package/dist/assets/agents/AGENTS.md +87 -11
- package/dist/assets/cdk/bin/cdk.ts +87 -26
- package/dist/assets/cdk/lib/cdk-stack.ts +185 -55
- package/dist/assets/cdk/package.json +1 -1
- package/dist/assets/cdk/test/cdk.test.ts +4 -0
- package/dist/assets/container/python/Dockerfile +7 -1
- package/dist/assets/container/typescript/Dockerfile +25 -0
- package/dist/assets/container/typescript/dockerignore.template +24 -0
- package/dist/assets/datasets/predefined-v1.jsonl +3 -0
- package/dist/assets/datasets/simulated-v1.jsonl +3 -0
- package/dist/assets/python/a2a/googleadk/base/main.py +24 -16
- package/dist/assets/python/a2a/googleadk/base/pyproject.toml +3 -3
- package/dist/assets/python/a2a/langchain_langgraph/base/main.py +24 -16
- package/dist/assets/python/a2a/langchain_langgraph/base/pyproject.toml +3 -2
- package/dist/assets/python/a2a/strands/base/main.py +23 -17
- package/dist/assets/python/a2a/strands/base/pyproject.toml +2 -2
- package/dist/assets/python/a2a/strands/capabilities/memory/session.py +10 -2
- package/dist/assets/python/agui/googleadk/base/main.py +62 -2
- package/dist/assets/python/agui/googleadk/base/pyproject.toml +3 -3
- package/dist/assets/python/agui/langchain_langgraph/base/main.py +56 -0
- package/dist/assets/python/agui/langchain_langgraph/base/pyproject.toml +2 -1
- package/dist/assets/python/agui/strands/base/main.py +63 -1
- package/dist/assets/python/agui/strands/base/pyproject.toml +1 -1
- package/dist/assets/python/agui/strands/capabilities/memory/session.py +10 -2
- package/dist/assets/python/http/autogen/base/main.py +60 -29
- package/dist/assets/python/http/autogen/base/pyproject.toml +1 -1
- package/dist/assets/python/http/googleadk/base/main.py +69 -24
- package/dist/assets/python/http/googleadk/base/mcp_client/client.py +7 -7
- package/dist/assets/python/http/googleadk/base/pyproject.toml +2 -1
- package/dist/assets/python/http/langchain_langgraph/base/main.py +115 -24
- package/dist/assets/python/http/langchain_langgraph/base/mcp_client/client.py +10 -8
- package/dist/assets/python/http/langchain_langgraph/base/pyproject.toml +3 -2
- package/dist/assets/python/http/openaiagents/base/main.py +61 -32
- package/dist/assets/python/http/openaiagents/base/mcp_client/client.py +4 -4
- package/dist/assets/python/http/openaiagents/base/pyproject.toml +2 -2
- package/dist/assets/python/http/strands/base/main.py +571 -47
- package/dist/assets/python/http/strands/base/mcp_client/client.py +49 -6
- package/dist/assets/python/http/strands/base/model/load.py +119 -3
- package/dist/assets/python/http/strands/base/model/mantle_compat.py +21 -0
- package/dist/assets/python/http/strands/base/pyproject.toml +9 -3
- package/dist/assets/python/http/strands/base/skills/fetcher.py +279 -0
- package/dist/assets/python/http/strands/capabilities/execution-limits/hooks/execution_limits.py +54 -0
- package/dist/assets/python/http/strands/capabilities/memory/session.py +10 -2
- package/dist/assets/python/http/strands/capabilities/payments/__init__.py +4 -0
- package/dist/assets/python/http/strands/capabilities/payments/payments.py +142 -0
- package/dist/assets/python/mcp/standalone/base/main.py +58 -0
- package/dist/assets/typescript/http/strands/base/README.md +37 -0
- package/dist/assets/typescript/http/strands/base/gitignore.template +22 -0
- package/dist/assets/typescript/http/strands/base/main.ts +144 -0
- package/dist/assets/typescript/http/strands/base/mcp_client/client.ts +11 -0
- package/dist/assets/typescript/http/strands/base/model/load.ts +102 -0
- package/dist/assets/typescript/http/strands/base/package.json +38 -0
- package/dist/assets/typescript/http/strands/base/tsconfig.json +19 -0
- package/dist/assets/typescript/http/strands/capabilities/memory/memory.ts +52 -0
- package/dist/assets/typescript/http/vercelai/base/README.md +37 -0
- package/dist/assets/typescript/http/vercelai/base/gitignore.template +22 -0
- package/dist/assets/typescript/http/vercelai/base/main.ts +64 -0
- package/dist/assets/typescript/http/vercelai/base/model/load.ts +121 -0
- package/dist/assets/typescript/http/vercelai/base/package.json +35 -0
- package/dist/assets/typescript/http/vercelai/base/tsconfig.json +19 -0
- package/dist/cli/index.mjs +1443 -569
- package/dist/lib/constants.d.ts +8 -4
- package/dist/lib/constants.d.ts.map +1 -1
- package/dist/lib/constants.js +13 -7
- package/dist/lib/constants.js.map +1 -1
- package/dist/lib/errors/index.d.ts +1 -1
- package/dist/lib/errors/index.d.ts.map +1 -1
- package/dist/lib/errors/index.js +1 -1
- package/dist/lib/errors/index.js.map +1 -1
- package/dist/lib/errors/types.d.ts +259 -0
- package/dist/lib/errors/types.d.ts.map +1 -0
- package/dist/lib/errors/types.js +402 -0
- package/dist/lib/errors/types.js.map +1 -0
- package/dist/lib/errors/zod.d.ts +8 -0
- package/dist/lib/errors/zod.d.ts.map +1 -0
- package/dist/lib/errors/{config.js → zod.js} +8 -81
- package/dist/lib/errors/zod.js.map +1 -0
- package/dist/lib/index.d.ts +3 -0
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +4 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/packaging/build-args.d.ts +6 -0
- package/dist/lib/packaging/build-args.d.ts.map +1 -1
- package/dist/lib/packaging/build-args.js +11 -2
- package/dist/lib/packaging/build-args.js.map +1 -1
- package/dist/lib/packaging/build-context-dockerignore.d.ts +23 -0
- package/dist/lib/packaging/build-context-dockerignore.d.ts.map +1 -0
- package/dist/lib/packaging/build-context-dockerignore.js +63 -0
- package/dist/lib/packaging/build-context-dockerignore.js.map +1 -0
- package/dist/lib/packaging/build-context.d.ts +21 -0
- package/dist/lib/packaging/build-context.d.ts.map +1 -0
- package/dist/lib/packaging/build-context.js +21 -0
- package/dist/lib/packaging/build-context.js.map +1 -0
- package/dist/lib/packaging/container.d.ts.map +1 -1
- package/dist/lib/packaging/container.js +20 -9
- package/dist/lib/packaging/container.js.map +1 -1
- package/dist/lib/packaging/helpers.d.ts +16 -0
- package/dist/lib/packaging/helpers.d.ts.map +1 -1
- package/dist/lib/packaging/helpers.js +127 -29
- package/dist/lib/packaging/helpers.js.map +1 -1
- package/dist/lib/packaging/index.d.ts +2 -1
- package/dist/lib/packaging/index.d.ts.map +1 -1
- package/dist/lib/packaging/index.js +9 -20
- package/dist/lib/packaging/index.js.map +1 -1
- package/dist/lib/packaging/node.d.ts +2 -2
- package/dist/lib/packaging/node.d.ts.map +1 -1
- package/dist/lib/packaging/node.js +83 -38
- package/dist/lib/packaging/node.js.map +1 -1
- package/dist/lib/packaging/python.js +12 -12
- package/dist/lib/packaging/python.js.map +1 -1
- package/dist/lib/result.d.ts +50 -0
- package/dist/lib/result.d.ts.map +1 -0
- package/dist/lib/result.js +49 -0
- package/dist/lib/result.js.map +1 -0
- package/dist/lib/schemas/io/config-io.d.ts +8 -0
- package/dist/lib/schemas/io/config-io.d.ts.map +1 -1
- package/dist/lib/schemas/io/config-io.js +21 -3
- package/dist/lib/schemas/io/config-io.js.map +1 -1
- package/dist/lib/schemas/io/global-config.d.ts +40 -0
- package/dist/lib/schemas/io/global-config.d.ts.map +1 -0
- package/dist/lib/schemas/io/global-config.js +118 -0
- package/dist/lib/schemas/io/global-config.js.map +1 -0
- package/dist/lib/schemas/io/index.d.ts +1 -2
- package/dist/lib/schemas/io/index.d.ts.map +1 -1
- package/dist/lib/schemas/io/index.js +1 -4
- package/dist/lib/schemas/io/index.js.map +1 -1
- package/dist/lib/schemas/io/path-resolver.d.ts +0 -6
- package/dist/lib/schemas/io/path-resolver.d.ts.map +1 -1
- package/dist/lib/schemas/io/path-resolver.js +3 -13
- package/dist/lib/schemas/io/path-resolver.js.map +1 -1
- package/dist/lib/secrets/cipher.d.ts +12 -0
- package/dist/lib/secrets/cipher.d.ts.map +1 -0
- package/dist/lib/secrets/cipher.js +54 -0
- package/dist/lib/secrets/cipher.js.map +1 -0
- package/dist/lib/secrets/index.d.ts +4 -0
- package/dist/lib/secrets/index.d.ts.map +1 -0
- package/dist/lib/secrets/index.js +15 -0
- package/dist/lib/secrets/index.js.map +1 -0
- package/dist/lib/secrets/key-provider.d.ts +16 -0
- package/dist/lib/secrets/key-provider.d.ts.map +1 -0
- package/dist/lib/secrets/key-provider.js +191 -0
- package/dist/lib/secrets/key-provider.js.map +1 -0
- package/dist/lib/secrets/sensitive-keys.d.ts +21 -0
- package/dist/lib/secrets/sensitive-keys.d.ts.map +1 -0
- package/dist/lib/secrets/sensitive-keys.js +67 -0
- package/dist/lib/secrets/sensitive-keys.js.map +1 -0
- package/dist/lib/time-constants.d.ts +5 -0
- package/dist/lib/time-constants.d.ts.map +1 -0
- package/dist/lib/time-constants.js +8 -0
- package/dist/lib/time-constants.js.map +1 -0
- package/dist/lib/utils/env.d.ts +8 -2
- package/dist/lib/utils/env.d.ts.map +1 -1
- package/dist/lib/utils/env.js +65 -17
- package/dist/lib/utils/env.js.map +1 -1
- package/dist/lib/utils/index.d.ts +3 -2
- package/dist/lib/utils/index.d.ts.map +1 -1
- package/dist/lib/utils/index.js +6 -1
- package/dist/lib/utils/index.js.map +1 -1
- package/dist/lib/utils/polling.d.ts +31 -0
- package/dist/lib/utils/polling.d.ts.map +1 -0
- package/dist/lib/utils/polling.js +61 -0
- package/dist/lib/utils/polling.js.map +1 -0
- package/dist/lib/utils/zod.d.ts +16 -0
- package/dist/lib/utils/zod.d.ts.map +1 -1
- package/dist/lib/utils/zod.js +45 -0
- package/dist/lib/utils/zod.js.map +1 -1
- package/dist/schema/constants.d.ts +56 -2
- package/dist/schema/constants.d.ts.map +1 -1
- package/dist/schema/constants.js +82 -7
- package/dist/schema/constants.js.map +1 -1
- package/dist/schema/schemas/agent-env.d.ts +178 -6
- package/dist/schema/schemas/agent-env.d.ts.map +1 -1
- package/dist/schema/schemas/agent-env.js +302 -27
- package/dist/schema/schemas/agent-env.js.map +1 -1
- package/dist/schema/schemas/agentcore-project.d.ts +450 -11
- package/dist/schema/schemas/agentcore-project.d.ts.map +1 -1
- package/dist/schema/schemas/agentcore-project.js +283 -18
- package/dist/schema/schemas/agentcore-project.js.map +1 -1
- package/dist/schema/schemas/auth.d.ts +174 -0
- package/dist/schema/schemas/auth.d.ts.map +1 -1
- package/dist/schema/schemas/auth.js +127 -3
- package/dist/schema/schemas/auth.js.map +1 -1
- package/dist/schema/schemas/aws-targets.d.ts +12 -0
- package/dist/schema/schemas/aws-targets.d.ts.map +1 -1
- package/dist/schema/schemas/aws-targets.js +4 -0
- package/dist/schema/schemas/aws-targets.js.map +1 -1
- package/dist/schema/schemas/connections.d.ts +185 -0
- package/dist/schema/schemas/connections.d.ts.map +1 -0
- package/dist/schema/schemas/connections.js +176 -0
- package/dist/schema/schemas/connections.js.map +1 -0
- package/dist/schema/schemas/deployed-state.d.ts +361 -5
- package/dist/schema/schemas/deployed-state.d.ts.map +1 -1
- package/dist/schema/schemas/deployed-state.js +105 -2
- package/dist/schema/schemas/deployed-state.js.map +1 -1
- package/dist/schema/schemas/index.d.ts +1 -0
- package/dist/schema/schemas/index.d.ts.map +1 -1
- package/dist/schema/schemas/index.js +1 -0
- package/dist/schema/schemas/index.js.map +1 -1
- package/dist/schema/schemas/mcp-defs.d.ts +2 -1
- package/dist/schema/schemas/mcp-defs.d.ts.map +1 -1
- package/dist/schema/schemas/mcp-defs.js +3 -2
- package/dist/schema/schemas/mcp-defs.js.map +1 -1
- package/dist/schema/schemas/mcp.d.ts +199 -0
- package/dist/schema/schemas/mcp.d.ts.map +1 -1
- package/dist/schema/schemas/mcp.js +343 -6
- package/dist/schema/schemas/mcp.js.map +1 -1
- package/dist/schema/schemas/primitives/ab-test.d.ts +135 -0
- package/dist/schema/schemas/primitives/ab-test.d.ts.map +1 -0
- package/dist/schema/schemas/primitives/ab-test.js +95 -0
- package/dist/schema/schemas/primitives/ab-test.js.map +1 -0
- package/dist/schema/schemas/primitives/config-bundle.d.ts +32 -0
- package/dist/schema/schemas/primitives/config-bundle.d.ts.map +1 -0
- package/dist/schema/schemas/primitives/config-bundle.js +41 -0
- package/dist/schema/schemas/primitives/config-bundle.js.map +1 -0
- package/dist/schema/schemas/primitives/dataset.d.ts +48 -0
- package/dist/schema/schemas/primitives/dataset.d.ts.map +1 -0
- package/dist/schema/schemas/primitives/dataset.js +58 -0
- package/dist/schema/schemas/primitives/dataset.js.map +1 -0
- package/dist/schema/schemas/primitives/evaluator.d.ts +8 -0
- package/dist/schema/schemas/primitives/evaluator.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/evaluator.js +17 -1
- package/dist/schema/schemas/primitives/evaluator.js.map +1 -1
- package/dist/schema/schemas/primitives/harness.d.ts +377 -19
- package/dist/schema/schemas/primitives/harness.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/harness.js +379 -24
- package/dist/schema/schemas/primitives/harness.js.map +1 -1
- package/dist/schema/schemas/primitives/index.d.ts +13 -7
- package/dist/schema/schemas/primitives/index.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/index.js +37 -1
- package/dist/schema/schemas/primitives/index.js.map +1 -1
- package/dist/schema/schemas/primitives/knowledge-base.d.ts +104 -0
- package/dist/schema/schemas/primitives/knowledge-base.d.ts.map +1 -0
- package/dist/schema/schemas/primitives/knowledge-base.js +99 -0
- package/dist/schema/schemas/primitives/knowledge-base.js.map +1 -0
- package/dist/schema/schemas/primitives/memory.d.ts +22 -4
- package/dist/schema/schemas/primitives/memory.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/memory.js +57 -16
- package/dist/schema/schemas/primitives/memory.js.map +1 -1
- package/dist/schema/schemas/primitives/online-eval-config.d.ts +21 -2
- package/dist/schema/schemas/primitives/online-eval-config.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/online-eval-config.js +45 -5
- package/dist/schema/schemas/primitives/online-eval-config.js.map +1 -1
- package/dist/schema/schemas/primitives/payment.d.ts +54 -0
- package/dist/schema/schemas/primitives/payment.d.ts.map +1 -0
- package/dist/schema/schemas/primitives/payment.js +79 -0
- package/dist/schema/schemas/primitives/payment.js.map +1 -0
- package/dist/schema/schemas/primitives/policy.d.ts +26 -0
- package/dist/schema/schemas/primitives/policy.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/policy.js +5 -1
- package/dist/schema/schemas/primitives/policy.js.map +1 -1
- package/npm-shrinkwrap.json +17013 -0
- package/package.json +43 -21
- package/scripts/bump-version.ts +4 -4
- package/scripts/bundle.mjs +70 -41
- package/scripts/extract-cli-model.mjs +228 -0
- package/scripts/render_adoc.py +274 -0
- package/scripts/run-e2e-dev.sh +56 -0
- package/scripts/run-e2e-local.sh +145 -0
- package/dist/lib/errors/config.d.ts +0 -49
- package/dist/lib/errors/config.d.ts.map +0 -1
- package/dist/lib/errors/config.js.map +0 -1
- package/dist/lib/packaging/errors.d.ts +0 -16
- package/dist/lib/packaging/errors.d.ts.map +0 -1
- package/dist/lib/packaging/errors.js +0 -36
- package/dist/lib/packaging/errors.js.map +0 -1
- package/dist/lib/schemas/io/cli-config.d.ts +0 -12
- package/dist/lib/schemas/io/cli-config.d.ts.map +0 -1
- package/dist/lib/schemas/io/cli-config.js +0 -35
- package/dist/lib/schemas/io/cli-config.js.map +0 -1
|
@@ -5,7 +5,7 @@ from model.load import load_model
|
|
|
5
5
|
{{#if hasMemory}}
|
|
6
6
|
from memory.session import get_memory_session_manager
|
|
7
7
|
{{/if}}
|
|
8
|
-
{{#if
|
|
8
|
+
{{#if needsOs}}
|
|
9
9
|
import os
|
|
10
10
|
{{/if}}
|
|
11
11
|
|
|
@@ -18,19 +18,22 @@ def add_numbers(a: int, b: int) -> int:
|
|
|
18
18
|
|
|
19
19
|
tools = [add_numbers]
|
|
20
20
|
|
|
21
|
-
{{#if
|
|
22
|
-
|
|
21
|
+
{{#if needsOs}}
|
|
22
|
+
_MOUNT_PATHS = [
|
|
23
|
+
{{#if sessionStorageMountPath}}"{{sessionStorageMountPath}}",{{/if}}
|
|
24
|
+
{{#each efsMounts}}"{{mountPath}}",{{/each}}
|
|
25
|
+
{{#each s3Mounts}}"{{mountPath}}",{{/each}}
|
|
26
|
+
]
|
|
23
27
|
|
|
24
28
|
def _safe_resolve(path: str) -> str:
|
|
25
|
-
|
|
26
|
-
resolved
|
|
27
|
-
|
|
28
|
-
raise ValueError(f"Path '{path}' is outside the storage boundary")
|
|
29
|
+
resolved = os.path.realpath(path)
|
|
30
|
+
if not any(resolved == os.path.realpath(m) or resolved.startswith(os.path.realpath(m) + os.sep) for m in _MOUNT_PATHS):
|
|
31
|
+
raise ValueError(f"Path '{path}' is not within any configured mount ({', '.join(_MOUNT_PATHS)})")
|
|
29
32
|
return resolved
|
|
30
33
|
|
|
31
34
|
@tool
|
|
32
35
|
def file_read(path: str) -> str:
|
|
33
|
-
"""Read a file from
|
|
36
|
+
"""Read a file from a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
34
37
|
try:
|
|
35
38
|
full_path = _safe_resolve(path)
|
|
36
39
|
with open(full_path) as f:
|
|
@@ -42,7 +45,7 @@ def file_read(path: str) -> str:
|
|
|
42
45
|
|
|
43
46
|
@tool
|
|
44
47
|
def file_write(path: str, content: str) -> str:
|
|
45
|
-
"""Write
|
|
48
|
+
"""Write a file to a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
46
49
|
try:
|
|
47
50
|
full_path = _safe_resolve(path)
|
|
48
51
|
parent = os.path.dirname(full_path)
|
|
@@ -57,25 +60,28 @@ def file_write(path: str, content: str) -> str:
|
|
|
57
60
|
return f"Error writing '{path}': {e.strerror}"
|
|
58
61
|
|
|
59
62
|
@tool
|
|
60
|
-
def list_files(
|
|
61
|
-
"""List files in
|
|
63
|
+
def list_files(path: str) -> str:
|
|
64
|
+
"""List files in a mounted filesystem directory. Use the absolute path (e.g. /mnt/tools)."""
|
|
62
65
|
try:
|
|
63
|
-
|
|
64
|
-
entries = os.listdir(
|
|
66
|
+
full_path = _safe_resolve(path)
|
|
67
|
+
entries = os.listdir(full_path)
|
|
65
68
|
return "\n".join(entries) if entries else "(empty directory)"
|
|
66
69
|
except ValueError as e:
|
|
67
70
|
return str(e)
|
|
68
71
|
except OSError as e:
|
|
69
|
-
return f"Error listing '{
|
|
72
|
+
return f"Error listing '{path}': {e.strerror}"
|
|
70
73
|
|
|
71
74
|
tools.extend([file_read, file_write, list_files])
|
|
72
75
|
{{/if}}
|
|
73
76
|
|
|
74
77
|
SYSTEM_PROMPT = """
|
|
75
78
|
You are a helpful assistant. Use tools when appropriate.
|
|
76
|
-
{{#if
|
|
77
|
-
You have
|
|
78
|
-
{{
|
|
79
|
+
{{#if needsOs}}
|
|
80
|
+
You have access to the following mounted filesystems. Use file_read, file_write, and list_files with full absolute paths:
|
|
81
|
+
{{#if sessionStorageMountPath}}- {{sessionStorageMountPath}}: ephemeral session storage (lost when session ends)
|
|
82
|
+
{{/if}}{{#each efsMounts}}- {{mountPath}}: EFS persistent storage (persists across sessions and agent restarts)
|
|
83
|
+
{{/each}}{{#each s3Mounts}}- {{mountPath}}: S3 Files persistent storage (durable, backed by S3)
|
|
84
|
+
{{/each}}{{/if}}
|
|
79
85
|
"""
|
|
80
86
|
|
|
81
87
|
{{#if hasMemory}}
|
|
@@ -10,9 +10,9 @@ readme = "README.md"
|
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
11
|
dependencies = [
|
|
12
12
|
{{#if (eq modelProvider "Anthropic")}}"anthropic >= 0.30.0",
|
|
13
|
-
{{/if}}"a2a-sdk[all] >= 0.2.0",
|
|
13
|
+
{{/if}}"a2a-sdk[all] >= 0.2.0, < 1.0.0",
|
|
14
14
|
"aws-opentelemetry-distro",
|
|
15
|
-
"bedrock-agentcore[a2a] >= 1.
|
|
15
|
+
"bedrock-agentcore[a2a] >= 1.9.1",
|
|
16
16
|
"botocore[crt] >= 1.35.0",
|
|
17
17
|
{{#if (eq modelProvider "Gemini")}}"google-genai >= 1.0.0",
|
|
18
18
|
{{/if}}{{#if (eq modelProvider "OpenAI")}}"openai >= 1.0.0",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import uuid
|
|
2
3
|
from typing import Optional
|
|
3
4
|
|
|
4
5
|
from bedrock_agentcore.memory.integrations.strands.config import AgentCoreMemoryConfig{{#if memoryProviders.[0].strategies.length}}, RetrievalConfig{{/if}}
|
|
@@ -7,10 +8,14 @@ from bedrock_agentcore.memory.integrations.strands.session_manager import AgentC
|
|
|
7
8
|
MEMORY_ID = os.getenv("{{memoryProviders.[0].envVarName}}")
|
|
8
9
|
REGION = os.getenv("AWS_REGION")
|
|
9
10
|
|
|
10
|
-
def get_memory_session_manager(session_id: str, actor_id: str) -> Optional[AgentCoreMemorySessionManager]:
|
|
11
|
+
def get_memory_session_manager(session_id: Optional[str], actor_id: str) -> Optional[AgentCoreMemorySessionManager]:
|
|
11
12
|
if not MEMORY_ID:
|
|
12
13
|
return None
|
|
13
14
|
|
|
15
|
+
# AgentCoreMemoryConfig rejects None; OAuth/CUSTOM_JWT callers can reach us
|
|
16
|
+
# without a runtime session header, so synthesize one when absent.
|
|
17
|
+
session_id = session_id or uuid.uuid4().hex
|
|
18
|
+
|
|
14
19
|
{{#if memoryProviders.[0].strategies.length}}
|
|
15
20
|
retrieval_config = {
|
|
16
21
|
{{#if (includes memoryProviders.[0].strategies "SEMANTIC")}}
|
|
@@ -19,8 +24,11 @@ def get_memory_session_manager(session_id: str, actor_id: str) -> Optional[Agent
|
|
|
19
24
|
{{#if (includes memoryProviders.[0].strategies "USER_PREFERENCE")}}
|
|
20
25
|
f"/users/{actor_id}/preferences": RetrievalConfig(top_k=3, relevance_score=0.5),
|
|
21
26
|
{{/if}}
|
|
27
|
+
{{#if (includes memoryProviders.[0].strategies "EPISODIC")}}
|
|
28
|
+
f"/episodes/{actor_id}/{session_id}": RetrievalConfig(top_k=5, relevance_score=0.5),
|
|
29
|
+
{{/if}}
|
|
22
30
|
{{#if (includes memoryProviders.[0].strategies "SUMMARIZATION")}}
|
|
23
|
-
f"/summaries/{actor_id}
|
|
31
|
+
f"/summaries/{actor_id}": RetrievalConfig(top_k=3, relevance_score=0.5),
|
|
24
32
|
{{/if}}
|
|
25
33
|
}
|
|
26
34
|
{{/if}}
|
|
@@ -1,16 +1,76 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import uvicorn
|
|
3
3
|
from google.adk.agents import LlmAgent
|
|
4
|
+
from google.adk.tools import FunctionTool
|
|
4
5
|
from ag_ui_adk import ADKAgent, AGUIToolset, create_adk_app
|
|
5
6
|
from model.load import load_model
|
|
6
7
|
|
|
7
8
|
load_model()
|
|
8
9
|
|
|
10
|
+
{{#if needsOs}}
|
|
11
|
+
_MOUNT_PATHS = [
|
|
12
|
+
{{#if sessionStorageMountPath}}"{{sessionStorageMountPath}}",{{/if}}
|
|
13
|
+
{{#each efsMounts}}"{{mountPath}}",{{/each}}
|
|
14
|
+
{{#each s3Mounts}}"{{mountPath}}",{{/each}}
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
def _safe_resolve(path: str) -> str:
|
|
18
|
+
resolved = os.path.realpath(path)
|
|
19
|
+
if not any(resolved == os.path.realpath(m) or resolved.startswith(os.path.realpath(m) + os.sep) for m in _MOUNT_PATHS):
|
|
20
|
+
raise ValueError(f"Path '{path}' is not within any configured mount ({', '.join(_MOUNT_PATHS)})")
|
|
21
|
+
return resolved
|
|
22
|
+
|
|
23
|
+
def file_read(path: str) -> str:
|
|
24
|
+
"""Read a file from a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
25
|
+
try:
|
|
26
|
+
full_path = _safe_resolve(path)
|
|
27
|
+
with open(full_path) as f:
|
|
28
|
+
return f.read()
|
|
29
|
+
except ValueError as e:
|
|
30
|
+
return str(e)
|
|
31
|
+
except OSError as e:
|
|
32
|
+
return f"Error reading '{path}': {e.strerror}"
|
|
33
|
+
|
|
34
|
+
def file_write(path: str, content: str) -> str:
|
|
35
|
+
"""Write a file to a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
36
|
+
try:
|
|
37
|
+
full_path = _safe_resolve(path)
|
|
38
|
+
parent = os.path.dirname(full_path)
|
|
39
|
+
if parent:
|
|
40
|
+
os.makedirs(parent, exist_ok=True)
|
|
41
|
+
with open(full_path, "w") as f:
|
|
42
|
+
f.write(content)
|
|
43
|
+
return f"Written to {path}"
|
|
44
|
+
except ValueError as e:
|
|
45
|
+
return str(e)
|
|
46
|
+
except OSError as e:
|
|
47
|
+
return f"Error writing '{path}': {e.strerror}"
|
|
48
|
+
|
|
49
|
+
def list_files(path: str) -> str:
|
|
50
|
+
"""List files in a mounted filesystem directory. Use the absolute path (e.g. /mnt/tools)."""
|
|
51
|
+
try:
|
|
52
|
+
full_path = _safe_resolve(path)
|
|
53
|
+
entries = os.listdir(full_path)
|
|
54
|
+
return "\n".join(entries) if entries else "(empty directory)"
|
|
55
|
+
except ValueError as e:
|
|
56
|
+
return str(e)
|
|
57
|
+
except OSError as e:
|
|
58
|
+
return f"Error listing '{path}': {e.strerror}"
|
|
59
|
+
|
|
60
|
+
_fs_tools = [FunctionTool(file_read), FunctionTool(file_write), FunctionTool(list_files)]
|
|
61
|
+
{{/if}}
|
|
62
|
+
|
|
9
63
|
agent = LlmAgent(
|
|
10
64
|
name="{{ name }}",
|
|
11
65
|
model="gemini-2.5-flash",
|
|
12
|
-
instruction="You are a helpful assistant.
|
|
13
|
-
|
|
66
|
+
instruction="""You are a helpful assistant.
|
|
67
|
+
{{#if needsOs}}
|
|
68
|
+
You have access to the following mounted filesystems. Use file_read, file_write, and list_files with full absolute paths:
|
|
69
|
+
{{#if sessionStorageMountPath}}- {{sessionStorageMountPath}}: ephemeral session storage (lost when session ends)
|
|
70
|
+
{{/if}}{{#each efsMounts}}- {{mountPath}}: EFS persistent storage (persists across sessions and agent restarts)
|
|
71
|
+
{{/each}}{{#each s3Mounts}}- {{mountPath}}: S3 Files persistent storage (durable, backed by S3)
|
|
72
|
+
{{/each}}{{/if}}""",
|
|
73
|
+
tools=[AGUIToolset(), {{#if needsOs}}*_fs_tools{{/if}}],
|
|
14
74
|
)
|
|
15
75
|
|
|
16
76
|
adk_agent = ADKAgent(
|
|
@@ -11,10 +11,10 @@ requires-python = ">=3.10"
|
|
|
11
11
|
dependencies = [
|
|
12
12
|
"ag-ui-adk >= 0.6.0",
|
|
13
13
|
"ag-ui-protocol >= 0.1.10",
|
|
14
|
-
"bedrock-agentcore >= 1.0
|
|
14
|
+
"bedrock-agentcore >= 1.8.0",
|
|
15
15
|
"fastapi >= 0.115.12",
|
|
16
|
-
"google-adk >= 1.16.0",
|
|
17
|
-
"google-genai >= 1.0.0",
|
|
16
|
+
"google-adk >= 1.16.0, < 2.0.0",
|
|
17
|
+
"google-genai >= 1.0.0, < 2.0.0",
|
|
18
18
|
"opentelemetry-distro",
|
|
19
19
|
"opentelemetry-exporter-otlp",
|
|
20
20
|
"uvicorn >= 0.34.3",
|
|
@@ -25,6 +25,62 @@ def add_numbers(a: int, b: int) -> int:
|
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
backend_tools = [add_numbers]
|
|
28
|
+
|
|
29
|
+
{{#if needsOs}}
|
|
30
|
+
_MOUNT_PATHS = [
|
|
31
|
+
{{#if sessionStorageMountPath}}"{{sessionStorageMountPath}}",{{/if}}
|
|
32
|
+
{{#each efsMounts}}"{{mountPath}}",{{/each}}
|
|
33
|
+
{{#each s3Mounts}}"{{mountPath}}",{{/each}}
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
def _safe_resolve(path: str) -> str:
|
|
37
|
+
resolved = os.path.realpath(path)
|
|
38
|
+
if not any(resolved == os.path.realpath(m) or resolved.startswith(os.path.realpath(m) + os.sep) for m in _MOUNT_PATHS):
|
|
39
|
+
raise ValueError(f"Path '{path}' is not within any configured mount ({', '.join(_MOUNT_PATHS)})")
|
|
40
|
+
return resolved
|
|
41
|
+
|
|
42
|
+
@tool
|
|
43
|
+
def file_read(path: str) -> str:
|
|
44
|
+
"""Read a file from a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
45
|
+
try:
|
|
46
|
+
full_path = _safe_resolve(path)
|
|
47
|
+
with open(full_path) as f:
|
|
48
|
+
return f.read()
|
|
49
|
+
except ValueError as e:
|
|
50
|
+
return str(e)
|
|
51
|
+
except OSError as e:
|
|
52
|
+
return f"Error reading '{path}': {e.strerror}"
|
|
53
|
+
|
|
54
|
+
@tool
|
|
55
|
+
def file_write(path: str, content: str) -> str:
|
|
56
|
+
"""Write a file to a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
57
|
+
try:
|
|
58
|
+
full_path = _safe_resolve(path)
|
|
59
|
+
parent = os.path.dirname(full_path)
|
|
60
|
+
if parent:
|
|
61
|
+
os.makedirs(parent, exist_ok=True)
|
|
62
|
+
with open(full_path, "w") as f:
|
|
63
|
+
f.write(content)
|
|
64
|
+
return f"Written to {path}"
|
|
65
|
+
except ValueError as e:
|
|
66
|
+
return str(e)
|
|
67
|
+
except OSError as e:
|
|
68
|
+
return f"Error writing '{path}': {e.strerror}"
|
|
69
|
+
|
|
70
|
+
@tool
|
|
71
|
+
def list_files(path: str) -> str:
|
|
72
|
+
"""List files in a mounted filesystem directory. Use the absolute path (e.g. /mnt/tools)."""
|
|
73
|
+
try:
|
|
74
|
+
full_path = _safe_resolve(path)
|
|
75
|
+
entries = os.listdir(full_path)
|
|
76
|
+
return "\n".join(entries) if entries else "(empty directory)"
|
|
77
|
+
except ValueError as e:
|
|
78
|
+
return str(e)
|
|
79
|
+
except OSError as e:
|
|
80
|
+
return f"Error listing '{path}': {e.strerror}"
|
|
81
|
+
|
|
82
|
+
backend_tools.extend([file_read, file_write, list_files])
|
|
83
|
+
{{/if}}
|
|
28
84
|
model = load_model()
|
|
29
85
|
|
|
30
86
|
|
|
@@ -14,10 +14,11 @@ dependencies = [
|
|
|
14
14
|
{{#if (eq modelProvider "Anthropic")}}"langchain-anthropic >= 0.3.0",
|
|
15
15
|
{{/if}}{{#if (eq modelProvider "Bedrock")}}"langchain-aws >= 0.2.0",
|
|
16
16
|
{{/if}}{{#if (eq modelProvider "Gemini")}}"langchain-google-genai >= 2.0.0",
|
|
17
|
+
"google-genai >= 1.0.0, < 2.0.0",
|
|
17
18
|
{{/if}}{{#if (eq modelProvider "OpenAI")}}"langchain-openai >= 0.2.0",
|
|
18
19
|
{{/if}}"aws-opentelemetry-distro",
|
|
19
20
|
"opentelemetry-instrumentation-langchain >= 0.59.0",
|
|
20
|
-
"bedrock-agentcore >= 1.0
|
|
21
|
+
"bedrock-agentcore >= 1.8.0",
|
|
21
22
|
"botocore[crt] >= 1.35.0",
|
|
22
23
|
"langgraph >= 0.3.25",
|
|
23
24
|
"langchain >= 0.3.0",
|
|
@@ -21,9 +21,71 @@ def add_numbers(a: int, b: int) -> int:
|
|
|
21
21
|
|
|
22
22
|
tools = [add_numbers]
|
|
23
23
|
|
|
24
|
+
{{#if needsOs}}
|
|
25
|
+
_MOUNT_PATHS = [
|
|
26
|
+
{{#if sessionStorageMountPath}}"{{sessionStorageMountPath}}",{{/if}}
|
|
27
|
+
{{#each efsMounts}}"{{mountPath}}",{{/each}}
|
|
28
|
+
{{#each s3Mounts}}"{{mountPath}}",{{/each}}
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
def _safe_resolve(path: str) -> str:
|
|
32
|
+
resolved = os.path.realpath(path)
|
|
33
|
+
if not any(resolved == os.path.realpath(m) or resolved.startswith(os.path.realpath(m) + os.sep) for m in _MOUNT_PATHS):
|
|
34
|
+
raise ValueError(f"Path '{path}' is not within any configured mount ({', '.join(_MOUNT_PATHS)})")
|
|
35
|
+
return resolved
|
|
36
|
+
|
|
37
|
+
@tool
|
|
38
|
+
def file_read(path: str) -> str:
|
|
39
|
+
"""Read a file from a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
40
|
+
try:
|
|
41
|
+
full_path = _safe_resolve(path)
|
|
42
|
+
with open(full_path) as f:
|
|
43
|
+
return f.read()
|
|
44
|
+
except ValueError as e:
|
|
45
|
+
return str(e)
|
|
46
|
+
except OSError as e:
|
|
47
|
+
return f"Error reading '{path}': {e.strerror}"
|
|
48
|
+
|
|
49
|
+
@tool
|
|
50
|
+
def file_write(path: str, content: str) -> str:
|
|
51
|
+
"""Write a file to a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
52
|
+
try:
|
|
53
|
+
full_path = _safe_resolve(path)
|
|
54
|
+
parent = os.path.dirname(full_path)
|
|
55
|
+
if parent:
|
|
56
|
+
os.makedirs(parent, exist_ok=True)
|
|
57
|
+
with open(full_path, "w") as f:
|
|
58
|
+
f.write(content)
|
|
59
|
+
return f"Written to {path}"
|
|
60
|
+
except ValueError as e:
|
|
61
|
+
return str(e)
|
|
62
|
+
except OSError as e:
|
|
63
|
+
return f"Error writing '{path}': {e.strerror}"
|
|
64
|
+
|
|
65
|
+
@tool
|
|
66
|
+
def list_files(path: str) -> str:
|
|
67
|
+
"""List files in a mounted filesystem directory. Use the absolute path (e.g. /mnt/tools)."""
|
|
68
|
+
try:
|
|
69
|
+
full_path = _safe_resolve(path)
|
|
70
|
+
entries = os.listdir(full_path)
|
|
71
|
+
return "\n".join(entries) if entries else "(empty directory)"
|
|
72
|
+
except ValueError as e:
|
|
73
|
+
return str(e)
|
|
74
|
+
except OSError as e:
|
|
75
|
+
return f"Error listing '{path}': {e.strerror}"
|
|
76
|
+
|
|
77
|
+
tools.extend([file_read, file_write, list_files])
|
|
78
|
+
{{/if}}
|
|
79
|
+
|
|
24
80
|
agent = Agent(
|
|
25
81
|
model=load_model(),
|
|
26
|
-
system_prompt="You are a helpful assistant. Use tools when appropriate.
|
|
82
|
+
system_prompt="""You are a helpful assistant. Use tools when appropriate.
|
|
83
|
+
{{#if needsOs}}
|
|
84
|
+
You have access to the following mounted filesystems. Use file_read, file_write, and list_files with full absolute paths:
|
|
85
|
+
{{#if sessionStorageMountPath}}- {{sessionStorageMountPath}}: ephemeral session storage (lost when session ends)
|
|
86
|
+
{{/if}}{{#each efsMounts}}- {{mountPath}}: EFS persistent storage (persists across sessions and agent restarts)
|
|
87
|
+
{{/each}}{{#each s3Mounts}}- {{mountPath}}: S3 Files persistent storage (durable, backed by S3)
|
|
88
|
+
{{/each}}{{/if}}""",
|
|
27
89
|
tools=tools,
|
|
28
90
|
)
|
|
29
91
|
|
|
@@ -13,7 +13,7 @@ dependencies = [
|
|
|
13
13
|
{{/if}}"ag-ui-strands >= 0.1.7",
|
|
14
14
|
"ag-ui-protocol >= 0.1.10",
|
|
15
15
|
"aws-opentelemetry-distro",
|
|
16
|
-
"bedrock-agentcore >= 1.
|
|
16
|
+
"bedrock-agentcore >= 1.9.1",
|
|
17
17
|
"botocore[crt] >= 1.35.0",
|
|
18
18
|
"fastapi >= 0.115.12",
|
|
19
19
|
{{#if (eq modelProvider "Gemini")}}"google-genai >= 1.0.0",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import os
|
|
2
|
+
import uuid
|
|
2
3
|
from typing import Optional
|
|
3
4
|
|
|
4
5
|
from bedrock_agentcore.memory.integrations.strands.config import AgentCoreMemoryConfig{{#if memoryProviders.[0].strategies.length}}, RetrievalConfig{{/if}}
|
|
@@ -7,10 +8,14 @@ from bedrock_agentcore.memory.integrations.strands.session_manager import AgentC
|
|
|
7
8
|
MEMORY_ID = os.getenv("{{memoryProviders.[0].envVarName}}")
|
|
8
9
|
REGION = os.getenv("AWS_REGION")
|
|
9
10
|
|
|
10
|
-
def get_memory_session_manager(session_id: str, actor_id: str) -> Optional[AgentCoreMemorySessionManager]:
|
|
11
|
+
def get_memory_session_manager(session_id: Optional[str], actor_id: str) -> Optional[AgentCoreMemorySessionManager]:
|
|
11
12
|
if not MEMORY_ID:
|
|
12
13
|
return None
|
|
13
14
|
|
|
15
|
+
# AgentCoreMemoryConfig rejects None; OAuth/CUSTOM_JWT callers can reach us
|
|
16
|
+
# without a runtime session header, so synthesize one when absent.
|
|
17
|
+
session_id = session_id or uuid.uuid4().hex
|
|
18
|
+
|
|
14
19
|
{{#if memoryProviders.[0].strategies.length}}
|
|
15
20
|
retrieval_config = {
|
|
16
21
|
{{#if (includes memoryProviders.[0].strategies "SEMANTIC")}}
|
|
@@ -19,8 +24,11 @@ def get_memory_session_manager(session_id: str, actor_id: str) -> Optional[Agent
|
|
|
19
24
|
{{#if (includes memoryProviders.[0].strategies "USER_PREFERENCE")}}
|
|
20
25
|
f"/users/{actor_id}/preferences": RetrievalConfig(top_k=3, relevance_score=0.5),
|
|
21
26
|
{{/if}}
|
|
27
|
+
{{#if (includes memoryProviders.[0].strategies "EPISODIC")}}
|
|
28
|
+
f"/episodes/{actor_id}/{session_id}": RetrievalConfig(top_k=5, relevance_score=0.5),
|
|
29
|
+
{{/if}}
|
|
22
30
|
{{#if (includes memoryProviders.[0].strategies "SUMMARIZATION")}}
|
|
23
|
-
f"/summaries/{actor_id}
|
|
31
|
+
f"/summaries/{actor_id}": RetrievalConfig(top_k=3, relevance_score=0.5),
|
|
24
32
|
{{/if}}
|
|
25
33
|
}
|
|
26
34
|
{{/if}}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
{{#if needsOs}}
|
|
1
2
|
import os
|
|
3
|
+
{{/if}}
|
|
4
|
+
from collections import OrderedDict
|
|
2
5
|
from autogen_agentchat.agents import AssistantAgent
|
|
3
6
|
from autogen_core.tools import FunctionTool
|
|
4
7
|
from bedrock_agentcore.runtime import BedrockAgentCoreApp
|
|
@@ -22,18 +25,21 @@ add_numbers_tool = FunctionTool(
|
|
|
22
25
|
# Define a collection of tools used by the model
|
|
23
26
|
tools = [add_numbers_tool]
|
|
24
27
|
|
|
25
|
-
{{#if
|
|
26
|
-
|
|
28
|
+
{{#if needsOs}}
|
|
29
|
+
_MOUNT_PATHS = [
|
|
30
|
+
{{#if sessionStorageMountPath}}"{{sessionStorageMountPath}}",{{/if}}
|
|
31
|
+
{{#each efsMounts}}"{{mountPath}}",{{/each}}
|
|
32
|
+
{{#each s3Mounts}}"{{mountPath}}",{{/each}}
|
|
33
|
+
]
|
|
27
34
|
|
|
28
35
|
def _safe_resolve(path: str) -> str:
|
|
29
|
-
|
|
30
|
-
resolved
|
|
31
|
-
|
|
32
|
-
raise ValueError(f"Path '{path}' is outside the storage boundary")
|
|
36
|
+
resolved = os.path.realpath(path)
|
|
37
|
+
if not any(resolved == os.path.realpath(m) or resolved.startswith(os.path.realpath(m) + os.sep) for m in _MOUNT_PATHS):
|
|
38
|
+
raise ValueError(f"Path '{path}' is not within any configured mount ({', '.join(_MOUNT_PATHS)})")
|
|
33
39
|
return resolved
|
|
34
40
|
|
|
35
41
|
def file_read(path: str) -> str:
|
|
36
|
-
"""Read a file from
|
|
42
|
+
"""Read a file from a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
37
43
|
try:
|
|
38
44
|
full_path = _safe_resolve(path)
|
|
39
45
|
with open(full_path) as f:
|
|
@@ -44,7 +50,7 @@ def file_read(path: str) -> str:
|
|
|
44
50
|
return f"Error reading '{path}': {e.strerror}"
|
|
45
51
|
|
|
46
52
|
def file_write(path: str, content: str) -> str:
|
|
47
|
-
"""Write
|
|
53
|
+
"""Write a file to a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."""
|
|
48
54
|
try:
|
|
49
55
|
full_path = _safe_resolve(path)
|
|
50
56
|
parent = os.path.dirname(full_path)
|
|
@@ -58,48 +64,73 @@ def file_write(path: str, content: str) -> str:
|
|
|
58
64
|
except OSError as e:
|
|
59
65
|
return f"Error writing '{path}': {e.strerror}"
|
|
60
66
|
|
|
61
|
-
def list_files(
|
|
62
|
-
"""List files in
|
|
67
|
+
def list_files(path: str) -> str:
|
|
68
|
+
"""List files in a mounted filesystem directory. Use the absolute path (e.g. /mnt/tools)."""
|
|
63
69
|
try:
|
|
64
|
-
|
|
65
|
-
entries = os.listdir(
|
|
70
|
+
full_path = _safe_resolve(path)
|
|
71
|
+
entries = os.listdir(full_path)
|
|
66
72
|
return "\n".join(entries) if entries else "(empty directory)"
|
|
67
73
|
except ValueError as e:
|
|
68
74
|
return str(e)
|
|
69
75
|
except OSError as e:
|
|
70
|
-
return f"Error listing '{
|
|
76
|
+
return f"Error listing '{path}': {e.strerror}"
|
|
71
77
|
|
|
72
78
|
tools.extend([
|
|
73
|
-
FunctionTool(file_read, description="Read a file from
|
|
74
|
-
FunctionTool(file_write, description="Write
|
|
75
|
-
FunctionTool(list_files, description="List files in
|
|
79
|
+
FunctionTool(file_read, description="Read a file from a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."),
|
|
80
|
+
FunctionTool(file_write, description="Write a file to a mounted filesystem. Use the absolute path (e.g. /mnt/tools/data.txt)."),
|
|
81
|
+
FunctionTool(list_files, description="List files in a mounted filesystem directory. Use the absolute path (e.g. /mnt/tools)."),
|
|
76
82
|
])
|
|
77
83
|
{{/if}}
|
|
78
84
|
|
|
79
85
|
SYSTEM_MESSAGE = """
|
|
80
86
|
You are a helpful assistant. Use tools when appropriate.
|
|
81
|
-
{{#if
|
|
82
|
-
You have
|
|
83
|
-
{{
|
|
87
|
+
{{#if needsOs}}
|
|
88
|
+
You have access to the following mounted filesystems. Use file_read, file_write, and list_files with full absolute paths:
|
|
89
|
+
{{#if sessionStorageMountPath}}- {{sessionStorageMountPath}}: ephemeral session storage (lost when session ends)
|
|
90
|
+
{{/if}}{{#each efsMounts}}- {{mountPath}}: EFS persistent storage (persists across sessions and agent restarts)
|
|
91
|
+
{{/each}}{{#each s3Mounts}}- {{mountPath}}: S3 Files persistent storage (durable, backed by S3)
|
|
92
|
+
{{/each}}{{/if}}
|
|
84
93
|
"""
|
|
85
94
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
95
|
+
# Reuses one AssistantAgent per session_id so each session keeps its own
|
|
96
|
+
# in-process conversation history (best-effort; resets on cold start). Caches up
|
|
97
|
+
# to 128 active sessions with LRU eviction (least-recently-used is dropped and
|
|
98
|
+
# its history reset).
|
|
99
|
+
_agents = OrderedDict()
|
|
89
100
|
|
|
101
|
+
|
|
102
|
+
async def get_or_create_agent(session_id):
|
|
103
|
+
if session_id in _agents:
|
|
104
|
+
_agents.move_to_end(session_id)
|
|
105
|
+
return _agents[session_id]
|
|
106
|
+
if len(_agents) >= 128:
|
|
107
|
+
_agents.popitem(last=False)
|
|
90
108
|
# Get MCP Tools
|
|
91
109
|
mcp_tools = await get_streamable_http_mcp_tools()
|
|
110
|
+
# Re-check after the await: a concurrent first-invocation for the same
|
|
111
|
+
# session_id may have built and stored the agent while we were awaiting.
|
|
112
|
+
# Don't overwrite it (that would orphan the agent the other request is using).
|
|
113
|
+
if session_id not in _agents:
|
|
114
|
+
_agents[session_id] = AssistantAgent(
|
|
115
|
+
name="{{ name }}",
|
|
116
|
+
model_client=load_model(),
|
|
117
|
+
tools=tools + mcp_tools,
|
|
118
|
+
system_message=SYSTEM_MESSAGE,
|
|
119
|
+
)
|
|
120
|
+
_agents.move_to_end(session_id)
|
|
121
|
+
return _agents[session_id]
|
|
122
|
+
|
|
92
123
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
model_client=load_model(),
|
|
97
|
-
tools=tools + mcp_tools,
|
|
98
|
-
system_message=SYSTEM_MESSAGE,
|
|
99
|
-
)
|
|
124
|
+
@app.entrypoint
|
|
125
|
+
async def invoke(payload, context):
|
|
126
|
+
log.info("Invoking Agent.....")
|
|
100
127
|
|
|
101
128
|
# Process the user prompt
|
|
102
129
|
prompt = payload.get("prompt", "What can you help me with?")
|
|
130
|
+
session_id = getattr(context, "session_id", "default-session")
|
|
131
|
+
|
|
132
|
+
# Reuse the per-session agent (preserves conversation history)
|
|
133
|
+
agent = await get_or_create_agent(session_id)
|
|
103
134
|
|
|
104
135
|
# Run the agent
|
|
105
136
|
result = await agent.run(task=prompt)
|
|
@@ -13,7 +13,7 @@ dependencies = [
|
|
|
13
13
|
"autogen-ext[mcp] >= 0.7.5",
|
|
14
14
|
"opentelemetry-distro",
|
|
15
15
|
"opentelemetry-exporter-otlp",
|
|
16
|
-
"bedrock-agentcore >= 1.0
|
|
16
|
+
"bedrock-agentcore >= 1.8.0",
|
|
17
17
|
"botocore[crt] >= 1.35.0",
|
|
18
18
|
"tiktoken",
|
|
19
19
|
{{#if (eq modelProvider "Bedrock")}}
|