@aws/agentcore 0.9.1 → 1.0.0-preview.2

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.
Files changed (89) hide show
  1. package/dist/agent-inspector/index.css +1 -1
  2. package/dist/agent-inspector/index.js +90 -72
  3. package/dist/assets/README.md +56 -31
  4. package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +1781 -259
  5. package/dist/assets/__tests__/__snapshots__/dockerfile-render.test.ts.snap +77 -0
  6. package/dist/assets/__tests__/dockerfile-render.test.ts +24 -0
  7. package/dist/assets/agents/AGENTS.md +84 -55
  8. package/dist/assets/cdk/bin/cdk.ts +40 -0
  9. package/dist/assets/cdk/cdk.json +1 -1
  10. package/dist/assets/cdk/lib/cdk-stack.ts +59 -2
  11. package/dist/assets/container/python/Dockerfile +4 -0
  12. package/dist/assets/evaluators/python-lambda/execution-role-policy.json +1 -1
  13. package/dist/assets/harness/invoke.py.template +74 -0
  14. package/dist/assets/python/a2a/googleadk/base/main.py +65 -3
  15. package/dist/assets/python/a2a/langchain_langgraph/base/main.py +64 -1
  16. package/dist/assets/python/a2a/strands/base/main.py +65 -2
  17. package/dist/assets/python/agui/googleadk/base/README.md +30 -0
  18. package/dist/assets/python/agui/googleadk/base/gitignore.template +41 -0
  19. package/dist/assets/python/agui/googleadk/base/main.py +31 -0
  20. package/dist/assets/python/agui/googleadk/base/model/__init__.py +1 -0
  21. package/dist/assets/python/agui/googleadk/base/model/load.py +41 -0
  22. package/dist/assets/python/agui/googleadk/base/pyproject.toml +24 -0
  23. package/dist/assets/python/agui/langchain_langgraph/base/README.md +22 -0
  24. package/dist/assets/python/agui/langchain_langgraph/base/gitignore.template +41 -0
  25. package/dist/assets/python/agui/langchain_langgraph/base/main.py +74 -0
  26. package/dist/assets/python/agui/langchain_langgraph/base/model/__init__.py +1 -0
  27. package/dist/assets/python/agui/langchain_langgraph/base/model/load.py +123 -0
  28. package/dist/assets/python/agui/langchain_langgraph/base/pyproject.toml +30 -0
  29. package/dist/assets/python/agui/strands/base/README.md +22 -0
  30. package/dist/assets/python/agui/strands/base/gitignore.template +41 -0
  31. package/dist/assets/python/agui/strands/base/main.py +43 -0
  32. package/dist/assets/python/agui/strands/base/model/__init__.py +1 -0
  33. package/dist/assets/python/agui/strands/base/model/load.py +123 -0
  34. package/dist/assets/python/agui/strands/base/pyproject.toml +27 -0
  35. package/dist/assets/python/agui/strands/capabilities/memory/__init__.py +1 -0
  36. package/dist/assets/python/agui/strands/capabilities/memory/session.py +38 -0
  37. package/dist/assets/python/http/autogen/base/main.py +61 -1
  38. package/dist/assets/python/http/googleadk/base/main.py +62 -2
  39. package/dist/assets/python/http/langchain_langgraph/base/main.py +61 -1
  40. package/dist/assets/python/http/openaiagents/base/main.py +70 -4
  41. package/dist/assets/python/http/strands/base/main.py +64 -6
  42. package/dist/cli/index.mjs +415 -377
  43. package/dist/lib/constants.d.ts +1 -0
  44. package/dist/lib/constants.d.ts.map +1 -1
  45. package/dist/lib/constants.js +3 -1
  46. package/dist/lib/constants.js.map +1 -1
  47. package/dist/lib/errors/config.d.ts.map +1 -1
  48. package/dist/lib/errors/config.js +5 -2
  49. package/dist/lib/errors/config.js.map +1 -1
  50. package/dist/lib/schemas/io/config-io.d.ts +9 -1
  51. package/dist/lib/schemas/io/config-io.d.ts.map +1 -1
  52. package/dist/lib/schemas/io/config-io.js +14 -0
  53. package/dist/lib/schemas/io/config-io.js.map +1 -1
  54. package/dist/lib/schemas/io/path-resolver.d.ts +12 -0
  55. package/dist/lib/schemas/io/path-resolver.d.ts.map +1 -1
  56. package/dist/lib/schemas/io/path-resolver.js +18 -0
  57. package/dist/lib/schemas/io/path-resolver.js.map +1 -1
  58. package/dist/schema/constants.d.ts +1 -0
  59. package/dist/schema/constants.d.ts.map +1 -1
  60. package/dist/schema/constants.js +8 -1
  61. package/dist/schema/constants.js.map +1 -1
  62. package/dist/schema/schemas/agent-env.d.ts +20 -0
  63. package/dist/schema/schemas/agent-env.d.ts.map +1 -1
  64. package/dist/schema/schemas/agent-env.js +17 -2
  65. package/dist/schema/schemas/agent-env.js.map +1 -1
  66. package/dist/schema/schemas/agentcore-project.d.ts +17 -0
  67. package/dist/schema/schemas/agentcore-project.d.ts.map +1 -1
  68. package/dist/schema/schemas/agentcore-project.js +18 -1
  69. package/dist/schema/schemas/agentcore-project.js.map +1 -1
  70. package/dist/schema/schemas/aws-targets.d.ts +3 -0
  71. package/dist/schema/schemas/aws-targets.d.ts.map +1 -1
  72. package/dist/schema/schemas/aws-targets.js +1 -0
  73. package/dist/schema/schemas/aws-targets.js.map +1 -1
  74. package/dist/schema/schemas/deployed-state.d.ts +50 -0
  75. package/dist/schema/schemas/deployed-state.d.ts.map +1 -1
  76. package/dist/schema/schemas/deployed-state.js +15 -1
  77. package/dist/schema/schemas/deployed-state.js.map +1 -1
  78. package/dist/schema/schemas/primitives/harness.d.ts +287 -0
  79. package/dist/schema/schemas/primitives/harness.d.ts.map +1 -0
  80. package/dist/schema/schemas/primitives/harness.js +237 -0
  81. package/dist/schema/schemas/primitives/harness.js.map +1 -0
  82. package/dist/schema/schemas/primitives/index.d.ts +2 -0
  83. package/dist/schema/schemas/primitives/index.d.ts.map +1 -1
  84. package/dist/schema/schemas/primitives/index.js +14 -1
  85. package/dist/schema/schemas/primitives/index.js.map +1 -1
  86. package/package.json +2 -2
  87. package/scripts/bump-version.ts +7 -80
  88. package/scripts/bundle.mjs +57 -3
  89. package/dist/agent-inspector/index.js.map +0 -1
@@ -1,3 +1,4 @@
1
+ import os
1
2
  from langchain_core.tools import tool
2
3
  from langgraph.prebuilt import create_react_agent
3
4
  from opentelemetry.instrumentation.langchain import LangchainInstrumentor
@@ -18,8 +19,70 @@ def add_numbers(a: int, b: int) -> int:
18
19
  return a + b
19
20
 
20
21
 
22
+ tools = [add_numbers]
23
+
24
+ {{#if sessionStorageMountPath}}
25
+ SESSION_STORAGE_PATH = "{{sessionStorageMountPath}}"
26
+
27
+ def _safe_resolve(path: str) -> str:
28
+ """Resolve path safely within the storage boundary."""
29
+ resolved = os.path.realpath(os.path.join(SESSION_STORAGE_PATH, path.lstrip("/")))
30
+ if not resolved.startswith(os.path.realpath(SESSION_STORAGE_PATH)):
31
+ raise ValueError(f"Path '{path}' is outside the storage boundary")
32
+ return resolved
33
+
34
+ @tool
35
+ def file_read(path: str) -> str:
36
+ """Read a file from persistent storage. The path is relative to the storage root."""
37
+ try:
38
+ full_path = _safe_resolve(path)
39
+ with open(full_path) as f:
40
+ return f.read()
41
+ except ValueError as e:
42
+ return str(e)
43
+ except OSError as e:
44
+ return f"Error reading '{path}': {e.strerror}"
45
+
46
+ @tool
47
+ def file_write(path: str, content: str) -> str:
48
+ """Write content to a file in persistent storage. The path is relative to the storage root."""
49
+ try:
50
+ full_path = _safe_resolve(path)
51
+ parent = os.path.dirname(full_path)
52
+ if parent:
53
+ os.makedirs(parent, exist_ok=True)
54
+ with open(full_path, "w") as f:
55
+ f.write(content)
56
+ return f"Written to {path}"
57
+ except ValueError as e:
58
+ return str(e)
59
+ except OSError as e:
60
+ return f"Error writing '{path}': {e.strerror}"
61
+
62
+ @tool
63
+ def list_files(directory: str = "") -> str:
64
+ """List files in persistent storage. The directory is relative to the storage root."""
65
+ try:
66
+ target = _safe_resolve(directory)
67
+ entries = os.listdir(target)
68
+ return "\n".join(entries) if entries else "(empty directory)"
69
+ except ValueError as e:
70
+ return str(e)
71
+ except OSError as e:
72
+ return f"Error listing '{directory}': {e.strerror}"
73
+
74
+ tools.extend([file_read, file_write, list_files])
75
+ {{/if}}
76
+
77
+ SYSTEM_PROMPT = """
78
+ You are a helpful assistant. Use tools when appropriate.
79
+ {{#if sessionStorageMountPath}}
80
+ You have persistent storage at {{sessionStorageMountPath}}. Use file tools to read and write files. Data persists across sessions.
81
+ {{/if}}
82
+ """
83
+
21
84
  model = load_model()
22
- graph = create_react_agent(model, tools=[add_numbers])
85
+ graph = create_react_agent(model, tools=tools, prompt=SYSTEM_PROMPT)
23
86
 
24
87
 
25
88
  class LangGraphA2AExecutor(AgentExecutor):
@@ -5,6 +5,9 @@ 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 sessionStorageMountPath}}
9
+ import os
10
+ {{/if}}
8
11
 
9
12
 
10
13
  @tool
@@ -15,6 +18,66 @@ def add_numbers(a: int, b: int) -> int:
15
18
 
16
19
  tools = [add_numbers]
17
20
 
21
+ {{#if sessionStorageMountPath}}
22
+ SESSION_STORAGE_PATH = "{{sessionStorageMountPath}}"
23
+
24
+ def _safe_resolve(path: str) -> str:
25
+ """Resolve path safely within the storage boundary."""
26
+ resolved = os.path.realpath(os.path.join(SESSION_STORAGE_PATH, path.lstrip("/")))
27
+ if not resolved.startswith(os.path.realpath(SESSION_STORAGE_PATH)):
28
+ raise ValueError(f"Path '{path}' is outside the storage boundary")
29
+ return resolved
30
+
31
+ @tool
32
+ def file_read(path: str) -> str:
33
+ """Read a file from persistent storage. The path is relative to the storage root."""
34
+ try:
35
+ full_path = _safe_resolve(path)
36
+ with open(full_path) as f:
37
+ return f.read()
38
+ except ValueError as e:
39
+ return str(e)
40
+ except OSError as e:
41
+ return f"Error reading '{path}': {e.strerror}"
42
+
43
+ @tool
44
+ def file_write(path: str, content: str) -> str:
45
+ """Write content to a file in persistent storage. The path is relative to the storage root."""
46
+ try:
47
+ full_path = _safe_resolve(path)
48
+ parent = os.path.dirname(full_path)
49
+ if parent:
50
+ os.makedirs(parent, exist_ok=True)
51
+ with open(full_path, "w") as f:
52
+ f.write(content)
53
+ return f"Written to {path}"
54
+ except ValueError as e:
55
+ return str(e)
56
+ except OSError as e:
57
+ return f"Error writing '{path}': {e.strerror}"
58
+
59
+ @tool
60
+ def list_files(directory: str = "") -> str:
61
+ """List files in persistent storage. The directory is relative to the storage root."""
62
+ try:
63
+ target = _safe_resolve(directory)
64
+ entries = os.listdir(target)
65
+ return "\n".join(entries) if entries else "(empty directory)"
66
+ except ValueError as e:
67
+ return str(e)
68
+ except OSError as e:
69
+ return f"Error listing '{directory}': {e.strerror}"
70
+
71
+ tools.extend([file_read, file_write, list_files])
72
+ {{/if}}
73
+
74
+ SYSTEM_PROMPT = """
75
+ You are a helpful assistant. Use tools when appropriate.
76
+ {{#if sessionStorageMountPath}}
77
+ You have persistent storage at {{sessionStorageMountPath}}. Use file tools to read and write files. Data persists across sessions.
78
+ {{/if}}
79
+ """
80
+
18
81
  {{#if hasMemory}}
19
82
  def agent_factory():
20
83
  cache = {}
@@ -24,7 +87,7 @@ def agent_factory():
24
87
  cache[key] = Agent(
25
88
  model=load_model(),
26
89
  session_manager=get_memory_session_manager(session_id, user_id),
27
- system_prompt="You are a helpful assistant. Use tools when appropriate.",
90
+ system_prompt=SYSTEM_PROMPT,
28
91
  tools=tools,
29
92
  )
30
93
  return cache[key]
@@ -35,7 +98,7 @@ agent = get_or_create_agent("default-session", "default-user")
35
98
  {{else}}
36
99
  agent = Agent(
37
100
  model=load_model(),
38
- system_prompt="You are a helpful assistant. Use tools when appropriate.",
101
+ system_prompt=SYSTEM_PROMPT,
39
102
  tools=tools,
40
103
  )
41
104
  {{/if}}
@@ -0,0 +1,30 @@
1
+ # {{ name }}
2
+
3
+ An AG-UI agent deployed on Amazon Bedrock AgentCore using Google ADK.
4
+
5
+ ## Overview
6
+
7
+ This agent implements the AG-UI protocol using Google's Agent Development Kit, enabling rich agent-user interaction via the AG-UI event stream.
8
+
9
+ ## Local Development
10
+
11
+ ```bash
12
+ uv sync
13
+ uv run python main.py
14
+ ```
15
+
16
+ The agent starts on port 8080 and serves requests at `/invocations`.
17
+
18
+ ## Health Check
19
+
20
+ ```
21
+ GET /ping
22
+ ```
23
+
24
+ Returns `{"status": "healthy"}`.
25
+
26
+ ## Deploy
27
+
28
+ ```bash
29
+ agentcore deploy
30
+ ```
@@ -0,0 +1,41 @@
1
+ # Environment variables
2
+ .env
3
+
4
+ # Python
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+ *.so
9
+ .Python
10
+ build/
11
+ develop-eggs/
12
+ dist/
13
+ downloads/
14
+ eggs/
15
+ .eggs/
16
+ lib/
17
+ lib64/
18
+ parts/
19
+ sdist/
20
+ var/
21
+ wheels/
22
+ *.egg-info/
23
+ .installed.cfg
24
+ *.egg
25
+
26
+ # Virtual environments
27
+ .venv/
28
+ venv/
29
+ ENV/
30
+ env/
31
+
32
+ # IDE
33
+ .vscode/
34
+ .idea/
35
+ *.swp
36
+ *.swo
37
+ *~
38
+
39
+ # OS
40
+ .DS_Store
41
+ Thumbs.db
@@ -0,0 +1,31 @@
1
+ import os
2
+ import uvicorn
3
+ from google.adk.agents import LlmAgent
4
+ from ag_ui_adk import ADKAgent, AGUIToolset, create_adk_app
5
+ from model.load import load_model
6
+
7
+ load_model()
8
+
9
+ agent = LlmAgent(
10
+ name="{{ name }}",
11
+ model="gemini-2.5-flash",
12
+ instruction="You are a helpful assistant.",
13
+ tools=[AGUIToolset()],
14
+ )
15
+
16
+ adk_agent = ADKAgent(
17
+ adk_agent=agent,
18
+ app_name="{{ name }}",
19
+ use_in_memory_services=True,
20
+ )
21
+
22
+ app = create_adk_app(adk_agent, path="/invocations")
23
+
24
+
25
+ @app.get("/ping")
26
+ async def ping():
27
+ return {"status": "healthy"}
28
+
29
+
30
+ if __name__ == "__main__":
31
+ uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", "8080")))
@@ -0,0 +1 @@
1
+ # Package marker
@@ -0,0 +1,41 @@
1
+ import os
2
+ from bedrock_agentcore.identity.auth import requires_api_key
3
+
4
+ IDENTITY_PROVIDER_NAME = "{{identityProviders.[0].name}}"
5
+ IDENTITY_ENV_VAR = "{{identityProviders.[0].envVarName}}"
6
+
7
+
8
+ @requires_api_key(provider_name=IDENTITY_PROVIDER_NAME)
9
+ def _agentcore_identity_api_key_provider(api_key: str) -> str:
10
+ """Fetch API key from AgentCore Identity."""
11
+ return api_key
12
+
13
+
14
+ def _get_api_key() -> str:
15
+ """
16
+ Uses AgentCore Identity for API key management in deployed environments.
17
+ For local development, run via 'agentcore dev' which loads agentcore/.env.
18
+ """
19
+ if os.getenv("LOCAL_DEV") == "1":
20
+ api_key = os.getenv(IDENTITY_ENV_VAR)
21
+ if not api_key:
22
+ raise RuntimeError(
23
+ f"{IDENTITY_ENV_VAR} not found. Add {IDENTITY_ENV_VAR}=your-key to .env.local"
24
+ )
25
+ return api_key
26
+ return _agentcore_identity_api_key_provider()
27
+
28
+
29
+ def load_model() -> None:
30
+ """
31
+ Set up Gemini API key authentication.
32
+ Uses AgentCore Identity for API key management in deployed environments,
33
+ and falls back to .env file for local development.
34
+ Sets the GOOGLE_API_KEY environment variable for the Google ADK.
35
+ """
36
+ api_key = _get_api_key()
37
+ # Use Google AI Studios API Key Authentication.
38
+ # https://google.github.io/adk-docs/agents/models/#google-ai-studio
39
+ os.environ["GOOGLE_API_KEY"] = api_key
40
+ # Set to TRUE is using Google Vertex AI, Set to FALSE for Google AI Studio
41
+ os.environ["GOOGLE_GENAI_USE_VERTEXAI"] = "FALSE"
@@ -0,0 +1,24 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "{{ name }}"
7
+ version = "0.1.0"
8
+ description = "AgentCore AG-UI Agent using Google ADK"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ dependencies = [
12
+ "ag-ui-adk >= 0.6.0",
13
+ "ag-ui-protocol >= 0.1.10",
14
+ "bedrock-agentcore >= 1.0.3",
15
+ "fastapi >= 0.115.12",
16
+ "google-adk >= 1.16.0",
17
+ "google-genai >= 1.0.0",
18
+ "opentelemetry-distro",
19
+ "opentelemetry-exporter-otlp",
20
+ "uvicorn >= 0.34.3",
21
+ ]
22
+
23
+ [tool.hatch.build.targets.wheel]
24
+ packages = ["."]
@@ -0,0 +1,22 @@
1
+ # {{ name }}
2
+
3
+ An AG-UI agent deployed on Amazon Bedrock AgentCore using LangChain + LangGraph.
4
+
5
+ ## Overview
6
+
7
+ This agent implements the AG-UI protocol using LangGraph, enabling seamless frontend-to-agent communication with support for streaming, tool calls, and frontend-injected tools.
8
+
9
+ ## Local Development
10
+
11
+ ```bash
12
+ uv sync
13
+ uv run python main.py
14
+ ```
15
+
16
+ The agent starts on port 8080.
17
+
18
+ ## Deploy
19
+
20
+ ```bash
21
+ agentcore deploy
22
+ ```
@@ -0,0 +1,41 @@
1
+ # Environment variables
2
+ .env
3
+
4
+ # Python
5
+ __pycache__/
6
+ *.py[cod]
7
+ *$py.class
8
+ *.so
9
+ .Python
10
+ build/
11
+ develop-eggs/
12
+ dist/
13
+ downloads/
14
+ eggs/
15
+ .eggs/
16
+ lib/
17
+ lib64/
18
+ parts/
19
+ sdist/
20
+ var/
21
+ wheels/
22
+ *.egg-info/
23
+ .installed.cfg
24
+ *.egg
25
+
26
+ # Virtual environments
27
+ .venv/
28
+ venv/
29
+ ENV/
30
+ env/
31
+
32
+ # IDE
33
+ .vscode/
34
+ .idea/
35
+ *.swp
36
+ *.swo
37
+ *~
38
+
39
+ # OS
40
+ .DS_Store
41
+ Thumbs.db
@@ -0,0 +1,74 @@
1
+ import os
2
+
3
+ os.environ["LANGGRAPH_FAST_API"] = "true"
4
+
5
+ import uvicorn
6
+ from typing import Any, List
7
+ from fastapi import FastAPI
8
+ from fastapi.middleware.cors import CORSMiddleware
9
+ from langgraph.graph import StateGraph, START
10
+ from langgraph.graph.message import MessagesState
11
+ from langgraph.checkpoint.memory import MemorySaver
12
+ from langgraph.prebuilt import ToolNode, tools_condition
13
+ from langchain_core.tools import tool
14
+ from opentelemetry.instrumentation.langchain import LangchainInstrumentor
15
+ from ag_ui_langgraph import LangGraphAgent, add_langgraph_fastapi_endpoint
16
+ from model.load import load_model
17
+
18
+ LangchainInstrumentor().instrument()
19
+
20
+
21
+ @tool
22
+ def add_numbers(a: int, b: int) -> int:
23
+ """Return the sum of two numbers."""
24
+ return a + b
25
+
26
+
27
+ backend_tools = [add_numbers]
28
+ model = load_model()
29
+
30
+
31
+ class AgentState(MessagesState):
32
+ tools: List[Any]
33
+
34
+
35
+ def chat_node(state: AgentState):
36
+ bound_model = model.bind_tools(
37
+ [*state.get("tools", []), *backend_tools],
38
+ )
39
+ response = bound_model.invoke(state["messages"])
40
+ return {"messages": [response]}
41
+
42
+
43
+ builder = StateGraph(AgentState)
44
+ builder.add_node("chat", chat_node)
45
+ builder.add_node("tools", ToolNode(tools=backend_tools))
46
+ builder.add_edge(START, "chat")
47
+ builder.add_conditional_edges("chat", tools_condition)
48
+ builder.add_edge("tools", "chat")
49
+ graph = builder.compile(checkpointer=MemorySaver())
50
+
51
+ agent = LangGraphAgent(
52
+ name="{{ name }}",
53
+ graph=graph,
54
+ description="A helpful assistant",
55
+ )
56
+
57
+ app = FastAPI()
58
+ app.add_middleware(
59
+ CORSMiddleware,
60
+ allow_origins=["*"],
61
+ allow_methods=["*"],
62
+ allow_headers=["*"],
63
+ )
64
+
65
+ add_langgraph_fastapi_endpoint(app=app, agent=agent, path="/invocations")
66
+
67
+
68
+ @app.get("/ping")
69
+ async def ping():
70
+ return {"status": "healthy"}
71
+
72
+
73
+ if __name__ == "__main__":
74
+ uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", "8080")))
@@ -0,0 +1,123 @@
1
+ {{#if (eq modelProvider "Bedrock")}}
2
+ from langchain_aws import ChatBedrock
3
+
4
+ # Uses global inference profile for Claude Sonnet 4.5
5
+ # https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles-support.html
6
+ MODEL_ID = "global.anthropic.claude-sonnet-4-5-20250929-v1:0"
7
+
8
+
9
+ def load_model() -> ChatBedrock:
10
+ """Get Bedrock model client using IAM credentials."""
11
+ return ChatBedrock(model_id=MODEL_ID)
12
+ {{/if}}
13
+ {{#if (eq modelProvider "Anthropic")}}
14
+ import os
15
+ from langchain_anthropic import ChatAnthropic
16
+ from bedrock_agentcore.identity.auth import requires_api_key
17
+
18
+ IDENTITY_PROVIDER_NAME = "{{identityProviders.[0].name}}"
19
+ IDENTITY_ENV_VAR = "{{identityProviders.[0].envVarName}}"
20
+
21
+
22
+ @requires_api_key(provider_name=IDENTITY_PROVIDER_NAME)
23
+ def _agentcore_identity_api_key_provider(api_key: str) -> str:
24
+ """Fetch API key from AgentCore Identity."""
25
+ return api_key
26
+
27
+
28
+ def _get_api_key() -> str:
29
+ """
30
+ Uses AgentCore Identity for API key management in deployed environments.
31
+ For local development, run via 'agentcore dev' which loads agentcore/.env.
32
+ """
33
+ if os.getenv("LOCAL_DEV") == "1":
34
+ api_key = os.getenv(IDENTITY_ENV_VAR)
35
+ if not api_key:
36
+ raise RuntimeError(
37
+ f"{IDENTITY_ENV_VAR} not found. Add {IDENTITY_ENV_VAR}=your-key to .env.local"
38
+ )
39
+ return api_key
40
+ return _agentcore_identity_api_key_provider()
41
+
42
+
43
+ def load_model() -> ChatAnthropic:
44
+ """Get authenticated Anthropic model client."""
45
+ return ChatAnthropic(
46
+ model="claude-sonnet-4-5-20250929",
47
+ api_key=_get_api_key()
48
+ )
49
+ {{/if}}
50
+ {{#if (eq modelProvider "OpenAI")}}
51
+ import os
52
+ from langchain_openai import ChatOpenAI
53
+ from bedrock_agentcore.identity.auth import requires_api_key
54
+
55
+ IDENTITY_PROVIDER_NAME = "{{identityProviders.[0].name}}"
56
+ IDENTITY_ENV_VAR = "{{identityProviders.[0].envVarName}}"
57
+
58
+
59
+ @requires_api_key(provider_name=IDENTITY_PROVIDER_NAME)
60
+ def _agentcore_identity_api_key_provider(api_key: str) -> str:
61
+ """Fetch API key from AgentCore Identity."""
62
+ return api_key
63
+
64
+
65
+ def _get_api_key() -> str:
66
+ """
67
+ Uses AgentCore Identity for API key management in deployed environments.
68
+ For local development, run via 'agentcore dev' which loads agentcore/.env.
69
+ """
70
+ if os.getenv("LOCAL_DEV") == "1":
71
+ api_key = os.getenv(IDENTITY_ENV_VAR)
72
+ if not api_key:
73
+ raise RuntimeError(
74
+ f"{IDENTITY_ENV_VAR} not found. Add {IDENTITY_ENV_VAR}=your-key to .env.local"
75
+ )
76
+ return api_key
77
+ return _agentcore_identity_api_key_provider()
78
+
79
+
80
+ def load_model() -> ChatOpenAI:
81
+ """Get authenticated OpenAI model client."""
82
+ return ChatOpenAI(
83
+ model="gpt-4.1",
84
+ api_key=_get_api_key()
85
+ )
86
+ {{/if}}
87
+ {{#if (eq modelProvider "Gemini")}}
88
+ import os
89
+ from langchain_google_genai import ChatGoogleGenerativeAI
90
+ from bedrock_agentcore.identity.auth import requires_api_key
91
+
92
+ IDENTITY_PROVIDER_NAME = "{{identityProviders.[0].name}}"
93
+ IDENTITY_ENV_VAR = "{{identityProviders.[0].envVarName}}"
94
+
95
+
96
+ @requires_api_key(provider_name=IDENTITY_PROVIDER_NAME)
97
+ def _agentcore_identity_api_key_provider(api_key: str) -> str:
98
+ """Fetch API key from AgentCore Identity."""
99
+ return api_key
100
+
101
+
102
+ def _get_api_key() -> str:
103
+ """
104
+ Uses AgentCore Identity for API key management in deployed environments.
105
+ For local development, run via 'agentcore dev' which loads agentcore/.env.
106
+ """
107
+ if os.getenv("LOCAL_DEV") == "1":
108
+ api_key = os.getenv(IDENTITY_ENV_VAR)
109
+ if not api_key:
110
+ raise RuntimeError(
111
+ f"{IDENTITY_ENV_VAR} not found. Add {IDENTITY_ENV_VAR}=your-key to .env.local"
112
+ )
113
+ return api_key
114
+ return _agentcore_identity_api_key_provider()
115
+
116
+
117
+ def load_model() -> ChatGoogleGenerativeAI:
118
+ """Get authenticated Gemini model client."""
119
+ return ChatGoogleGenerativeAI(
120
+ model="gemini-2.5-flash",
121
+ api_key=_get_api_key()
122
+ )
123
+ {{/if}}
@@ -0,0 +1,30 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "{{ name }}"
7
+ version = "0.1.0"
8
+ description = "AgentCore AG-UI Agent using LangChain + LangGraph"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ dependencies = [
12
+ "ag-ui-langgraph >= 0.0.31",
13
+ "ag-ui-protocol >= 0.1.10",
14
+ {{#if (eq modelProvider "Anthropic")}}"langchain-anthropic >= 0.3.0",
15
+ {{/if}}{{#if (eq modelProvider "Bedrock")}}"langchain-aws >= 0.2.0",
16
+ {{/if}}{{#if (eq modelProvider "Gemini")}}"langchain-google-genai >= 2.0.0",
17
+ {{/if}}{{#if (eq modelProvider "OpenAI")}}"langchain-openai >= 0.2.0",
18
+ {{/if}}"aws-opentelemetry-distro",
19
+ "opentelemetry-instrumentation-langchain >= 0.59.0",
20
+ "bedrock-agentcore >= 1.0.3",
21
+ "botocore[crt] >= 1.35.0",
22
+ "langgraph >= 0.3.25",
23
+ "langchain >= 0.3.0",
24
+ "langchain-core >= 0.3.0",
25
+ "fastapi >= 0.115.12",
26
+ "uvicorn >= 0.34.3",
27
+ ]
28
+
29
+ [tool.hatch.build.targets.wheel]
30
+ packages = ["."]
@@ -0,0 +1,22 @@
1
+ # {{ name }}
2
+
3
+ An AG-UI agent deployed on Amazon Bedrock AgentCore using Strands SDK.
4
+
5
+ ## Overview
6
+
7
+ This agent implements the AG-UI protocol, enabling streaming agent-to-UI communication. The agent exposes an `/invocations` endpoint that accepts AG-UI protocol requests and streams responses back to the client.
8
+
9
+ ## Local Development
10
+
11
+ ```bash
12
+ uv sync
13
+ uv run python main.py
14
+ ```
15
+
16
+ The agent starts on port 8080.
17
+
18
+ ## Deploy
19
+
20
+ ```bash
21
+ agentcore deploy
22
+ ```