@aws/agentcore 0.8.2 → 0.10.0
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/dist/agent-inspector/favicon.svg +60 -0
- package/dist/agent-inspector/index.css +1 -0
- package/dist/agent-inspector/index.html +14 -0
- package/dist/agent-inspector/index.js +274 -0
- package/dist/assets/README.md +56 -31
- package/dist/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap +1669 -245
- package/dist/assets/__tests__/__snapshots__/dockerfile-render.test.ts.snap +77 -0
- package/dist/assets/__tests__/dockerfile-render.test.ts +24 -0
- package/dist/assets/agents/AGENTS.md +84 -55
- package/dist/assets/cdk/cdk.json +1 -1
- package/dist/assets/cdk/package.json +1 -1
- package/dist/assets/container/python/Dockerfile +4 -0
- package/dist/assets/evaluators/python-lambda/execution-role-policy.json +1 -1
- package/dist/assets/python/a2a/googleadk/base/main.py +65 -3
- package/dist/assets/python/a2a/langchain_langgraph/base/main.py +64 -1
- package/dist/assets/python/a2a/strands/base/main.py +65 -2
- package/dist/assets/python/agui/googleadk/base/README.md +30 -0
- package/dist/assets/python/agui/googleadk/base/gitignore.template +41 -0
- package/dist/assets/python/agui/googleadk/base/main.py +31 -0
- package/dist/assets/python/agui/googleadk/base/model/__init__.py +1 -0
- package/dist/assets/python/agui/googleadk/base/model/load.py +41 -0
- package/dist/assets/python/agui/googleadk/base/pyproject.toml +24 -0
- package/dist/assets/python/agui/langchain_langgraph/base/README.md +22 -0
- package/dist/assets/python/agui/langchain_langgraph/base/gitignore.template +41 -0
- package/dist/assets/python/agui/langchain_langgraph/base/main.py +74 -0
- package/dist/assets/python/agui/langchain_langgraph/base/model/__init__.py +1 -0
- package/dist/assets/python/agui/langchain_langgraph/base/model/load.py +123 -0
- package/dist/assets/python/agui/langchain_langgraph/base/pyproject.toml +30 -0
- package/dist/assets/python/agui/strands/base/README.md +22 -0
- package/dist/assets/python/agui/strands/base/gitignore.template +41 -0
- package/dist/assets/python/agui/strands/base/main.py +43 -0
- package/dist/assets/python/agui/strands/base/model/__init__.py +1 -0
- package/dist/assets/python/agui/strands/base/model/load.py +123 -0
- package/dist/assets/python/agui/strands/base/pyproject.toml +27 -0
- package/dist/assets/python/agui/strands/capabilities/memory/__init__.py +1 -0
- package/dist/assets/python/agui/strands/capabilities/memory/session.py +38 -0
- package/dist/assets/python/http/autogen/base/main.py +61 -1
- package/dist/assets/python/http/googleadk/base/main.py +62 -2
- package/dist/assets/python/http/langchain_langgraph/base/main.py +61 -1
- package/dist/assets/python/http/openaiagents/base/main.py +70 -4
- package/dist/assets/python/http/strands/base/main.py +64 -6
- package/dist/cli/index.mjs +480 -457
- package/dist/lib/errors/config.d.ts.map +1 -1
- package/dist/lib/errors/config.js +5 -2
- package/dist/lib/errors/config.js.map +1 -1
- package/dist/schema/constants.d.ts +1 -0
- package/dist/schema/constants.d.ts.map +1 -1
- package/dist/schema/constants.js +8 -1
- package/dist/schema/constants.js.map +1 -1
- package/dist/schema/schemas/agent-env.d.ts +20 -0
- package/dist/schema/schemas/agent-env.d.ts.map +1 -1
- package/dist/schema/schemas/agent-env.js +17 -2
- package/dist/schema/schemas/agent-env.js.map +1 -1
- package/dist/schema/schemas/agentcore-project.d.ts +6 -0
- package/dist/schema/schemas/agentcore-project.d.ts.map +1 -1
- package/dist/schema/schemas/aws-targets.d.ts +3 -0
- package/dist/schema/schemas/aws-targets.d.ts.map +1 -1
- package/dist/schema/schemas/aws-targets.js +1 -0
- package/dist/schema/schemas/aws-targets.js.map +1 -1
- package/dist/schema/schemas/primitives/evaluator.d.ts.map +1 -1
- package/dist/schema/schemas/primitives/evaluator.js +0 -1
- package/dist/schema/schemas/primitives/evaluator.js.map +1 -1
- package/package.json +4 -1
- package/scripts/bump-version.ts +7 -80
- package/scripts/copy-assets.mjs +14 -0
|
@@ -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 @@
|
|
|
1
|
+
# Package marker
|
|
@@ -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
|
+
```
|
|
@@ -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,43 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
# Suppress OpenTelemetry warnings during local development; remove for production
|
|
4
|
+
if os.getenv("LOCAL_DEV") == "1":
|
|
5
|
+
os.environ["OTEL_SDK_DISABLED"] = "true"
|
|
6
|
+
|
|
7
|
+
import uvicorn
|
|
8
|
+
from strands import Agent, tool
|
|
9
|
+
from ag_ui_strands import StrandsAgent, StrandsAgentConfig, create_strands_app
|
|
10
|
+
from model.load import load_model
|
|
11
|
+
{{#if hasMemory}}
|
|
12
|
+
from memory.session import get_memory_session_manager
|
|
13
|
+
{{/if}}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@tool
|
|
17
|
+
def add_numbers(a: int, b: int) -> int:
|
|
18
|
+
"""Return the sum of two numbers."""
|
|
19
|
+
return a + b
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
tools = [add_numbers]
|
|
23
|
+
|
|
24
|
+
agent = Agent(
|
|
25
|
+
model=load_model(),
|
|
26
|
+
system_prompt="You are a helpful assistant. Use tools when appropriate.",
|
|
27
|
+
tools=tools,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
{{#if hasMemory}}
|
|
31
|
+
def session_manager_provider(input_data):
|
|
32
|
+
return get_memory_session_manager(input_data.thread_id, "default-user")
|
|
33
|
+
|
|
34
|
+
config = StrandsAgentConfig(session_manager_provider=session_manager_provider)
|
|
35
|
+
{{else}}
|
|
36
|
+
config = StrandsAgentConfig()
|
|
37
|
+
{{/if}}
|
|
38
|
+
|
|
39
|
+
agui_agent = StrandsAgent(agent=agent, name="{{ name }}", description="A helpful assistant", config=config)
|
|
40
|
+
app = create_strands_app(agui_agent, path="/invocations", ping_path="/ping")
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__":
|
|
43
|
+
uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", "8080")))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Package marker
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
{{#if (eq modelProvider "Bedrock")}}
|
|
2
|
+
from strands.models.bedrock import BedrockModel
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def load_model() -> BedrockModel:
|
|
6
|
+
"""Get Bedrock model client using IAM credentials."""
|
|
7
|
+
return BedrockModel(model_id="global.anthropic.claude-sonnet-4-5-20250929-v1:0")
|
|
8
|
+
{{/if}}
|
|
9
|
+
{{#if (eq modelProvider "Anthropic")}}
|
|
10
|
+
import os
|
|
11
|
+
|
|
12
|
+
from strands.models.anthropic import AnthropicModel
|
|
13
|
+
from bedrock_agentcore.identity.auth import requires_api_key
|
|
14
|
+
|
|
15
|
+
IDENTITY_PROVIDER_NAME = "{{identityProviders.[0].name}}"
|
|
16
|
+
IDENTITY_ENV_VAR = "{{identityProviders.[0].envVarName}}"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@requires_api_key(provider_name=IDENTITY_PROVIDER_NAME)
|
|
20
|
+
def _agentcore_identity_api_key_provider(api_key: str) -> str:
|
|
21
|
+
"""Fetch API key from AgentCore Identity."""
|
|
22
|
+
return api_key
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _get_api_key() -> str:
|
|
26
|
+
"""
|
|
27
|
+
Uses AgentCore Identity for API key management in deployed environments.
|
|
28
|
+
For local development, run via 'agentcore dev' which loads agentcore/.env.
|
|
29
|
+
"""
|
|
30
|
+
if os.getenv("LOCAL_DEV") == "1":
|
|
31
|
+
api_key = os.getenv(IDENTITY_ENV_VAR)
|
|
32
|
+
if not api_key:
|
|
33
|
+
raise RuntimeError(
|
|
34
|
+
f"{IDENTITY_ENV_VAR} not found. Add {IDENTITY_ENV_VAR}=your-key to .env.local"
|
|
35
|
+
)
|
|
36
|
+
return api_key
|
|
37
|
+
return _agentcore_identity_api_key_provider()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def load_model() -> AnthropicModel:
|
|
41
|
+
"""Get authenticated Anthropic model client."""
|
|
42
|
+
return AnthropicModel(
|
|
43
|
+
client_args={"api_key": _get_api_key()},
|
|
44
|
+
model_id="claude-sonnet-4-5-20250929",
|
|
45
|
+
max_tokens=5000,
|
|
46
|
+
)
|
|
47
|
+
{{/if}}
|
|
48
|
+
{{#if (eq modelProvider "OpenAI")}}
|
|
49
|
+
import os
|
|
50
|
+
|
|
51
|
+
from strands.models.openai import OpenAIModel
|
|
52
|
+
from bedrock_agentcore.identity.auth import requires_api_key
|
|
53
|
+
|
|
54
|
+
IDENTITY_PROVIDER_NAME = "{{identityProviders.[0].name}}"
|
|
55
|
+
IDENTITY_ENV_VAR = "{{identityProviders.[0].envVarName}}"
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@requires_api_key(provider_name=IDENTITY_PROVIDER_NAME)
|
|
59
|
+
def _agentcore_identity_api_key_provider(api_key: str) -> str:
|
|
60
|
+
"""Fetch API key from AgentCore Identity."""
|
|
61
|
+
return api_key
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _get_api_key() -> str:
|
|
65
|
+
"""
|
|
66
|
+
Uses AgentCore Identity for API key management in deployed environments.
|
|
67
|
+
For local development, run via 'agentcore dev' which loads agentcore/.env.
|
|
68
|
+
"""
|
|
69
|
+
if os.getenv("LOCAL_DEV") == "1":
|
|
70
|
+
api_key = os.getenv(IDENTITY_ENV_VAR)
|
|
71
|
+
if not api_key:
|
|
72
|
+
raise RuntimeError(
|
|
73
|
+
f"{IDENTITY_ENV_VAR} not found. Add {IDENTITY_ENV_VAR}=your-key to .env.local"
|
|
74
|
+
)
|
|
75
|
+
return api_key
|
|
76
|
+
return _agentcore_identity_api_key_provider()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def load_model() -> OpenAIModel:
|
|
80
|
+
"""Get authenticated OpenAI model client."""
|
|
81
|
+
return OpenAIModel(
|
|
82
|
+
client_args={"api_key": _get_api_key()},
|
|
83
|
+
model_id="gpt-4.1",
|
|
84
|
+
)
|
|
85
|
+
{{/if}}
|
|
86
|
+
{{#if (eq modelProvider "Gemini")}}
|
|
87
|
+
import os
|
|
88
|
+
|
|
89
|
+
from strands.models.gemini import GeminiModel
|
|
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() -> GeminiModel:
|
|
118
|
+
"""Get authenticated Gemini model client."""
|
|
119
|
+
return GeminiModel(
|
|
120
|
+
client_args={"api_key": _get_api_key()},
|
|
121
|
+
model_id="gemini-2.5-flash",
|
|
122
|
+
)
|
|
123
|
+
{{/if}}
|
|
@@ -0,0 +1,27 @@
|
|
|
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 Strands SDK"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.12"
|
|
11
|
+
dependencies = [
|
|
12
|
+
{{#if (eq modelProvider "Anthropic")}}"anthropic >= 0.30.0",
|
|
13
|
+
{{/if}}"ag-ui-strands >= 0.1.7",
|
|
14
|
+
"ag-ui-protocol >= 0.1.10",
|
|
15
|
+
"aws-opentelemetry-distro",
|
|
16
|
+
"bedrock-agentcore >= 1.0.3",
|
|
17
|
+
"botocore[crt] >= 1.35.0",
|
|
18
|
+
"fastapi >= 0.115.12",
|
|
19
|
+
{{#if (eq modelProvider "Gemini")}}"google-genai >= 1.0.0",
|
|
20
|
+
{{/if}}{{#if (eq modelProvider "OpenAI")}}"openai >= 1.0.0",
|
|
21
|
+
{{/if}}"strands-agents >= 1.15.0",
|
|
22
|
+
"strands-agents-tools >= 0.2.14",
|
|
23
|
+
"uvicorn >= 0.34.3",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[tool.hatch.build.targets.wheel]
|
|
27
|
+
packages = ["."]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Package marker
|