Skip to content

Commit c2f2e8b

Browse files
committed
Use Nova Lite in AgentCore Strands sample
1 parent 03e6bfc commit c2f2e8b

4 files changed

Lines changed: 28 additions & 12 deletions

File tree

bedrock_agentcore/strands_agent/README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ workflows kick off.
3131
- AWS permissions for the AgentCore CLI (S3, IAM, CloudFormation): see [Use the
3232
AgentCore
3333
CLI](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/runtime-permissions.html#runtime-permissions-cli)
34-
- Access to an [Amazon
35-
Bedrock](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access-modify.html)
36-
foundation model in your region -- the agent uses the plugin's default
37-
`BedrockModel()`
34+
- Access to the Amazon Nova Lite model in your target Region. The sample uses
35+
the model ID `amazon.nova-lite-v1:0`.
3836

3937

4038
Docker is not needed. With the CodeZip build there is no image: the CLI uploads a
@@ -75,8 +73,8 @@ This sample opts to utilize the new AgentCore CLI for creating and updating both
7573
### 1. Choose the AWS account and region
7674

7775
Edit `agentcore/aws-targets.json` with the account ID and region to deploy into. AgentCore is only available in
78-
[certain regions](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/agentcore-regions.html), and the region
79-
needs the Bedrock model enabled.
76+
[certain regions](https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/agentcore-regions.html), and the Region
77+
must support Amazon Nova Lite.
8078

8179
### 2. Configure the Temporal connection
8280

bedrock_agentcore/strands_agent/agentcore_worker.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from datetime import timedelta
2424

2525
from bedrock_agentcore.runtime import BedrockAgentCoreApp
26+
from strands.models import BedrockModel
2627
from temporalio.client import Client
2728
from temporalio.common import VersioningBehavior
2829
from temporalio.contrib.strands import StrandsPlugin
@@ -111,7 +112,15 @@ async def run_worker() -> None:
111112
namespace=os.environ.get("TEMPORAL_NAMESPACE", "default"),
112113
api_key=api_key,
113114
tls=bool(api_key),
114-
plugins=[StrandsPlugin()],
115+
plugins=[
116+
StrandsPlugin(
117+
models={
118+
workflows.MODEL_NAME: lambda: BedrockModel(
119+
model_id=workflows.MODEL_ID
120+
)
121+
}
122+
)
123+
],
115124
)
116125

117126
tracker = ActivityTracker()

bedrock_agentcore/strands_agent/starter.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import asyncio
22
import sys
33

4+
from strands.models import BedrockModel
45
from temporalio.client import Client
56
from temporalio.contrib.strands import StrandsPlugin
67
from temporalio.envconfig import ClientConfig
78

8-
from workflows import TASK_QUEUE, StrandsAgentWorkflow
9+
from workflows import MODEL_ID, MODEL_NAME, TASK_QUEUE, StrandsAgentWorkflow
910

1011
DEFAULT_PROMPT = (
1112
"What is the 30th Fibonacci number, and is it divisible by 7? "
@@ -21,7 +22,12 @@ async def main() -> None:
2122
# automatically alongside an API key.
2223
config = ClientConfig.load_client_connect_config()
2324
config.setdefault("target_host", "localhost:7233")
24-
client = await Client.connect(**config, plugins=[StrandsPlugin()])
25+
client = await Client.connect(
26+
**config,
27+
plugins=[
28+
StrandsPlugin(models={MODEL_NAME: lambda: BedrockModel(model_id=MODEL_ID)})
29+
],
30+
)
2531
print("Connected to Temporal Service")
2632

2733
result = await client.execute_workflow(

bedrock_agentcore/strands_agent/workflows.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
DEPLOYMENT_NAME = "agentcore-strands-agent-python"
99
BUILD_ID = "1.0.0"
1010

11+
# @@@SNIPSTART python-agentcore-strands-workflow
12+
MODEL_NAME = "nova-lite"
13+
MODEL_ID = "amazon.nova-lite-v1:0"
14+
1115
with workflow.unsafe.imports_passed_through():
1216
from activities import execute_code
1317

@@ -18,13 +22,12 @@
1822
the code you ran and its output."""
1923

2024

21-
# @@@SNIPSTART python-agentcore-strands-workflow
2225
@workflow.defn
2326
class StrandsAgentWorkflow:
2427
def __init__(self) -> None:
25-
# Configure with the plugin's default BedrockModel(), custom system
26-
# prompt and code interpreter tool.
28+
# Configure the model, custom system prompt and code interpreter tool.
2729
self.agent = TemporalAgent(
30+
model=MODEL_NAME,
2831
start_to_close_timeout=timedelta(seconds=60),
2932
system_prompt=SYSTEM_PROMPT,
3033
tools=[

0 commit comments

Comments
 (0)