Amazon Bedrock Deep Dive · lab exercise

Exercise 5: your first Strands agent, and its call

Part of Amazon Bedrock Deep Dive (BDR-101), with lesson 5-2. You do this in your own AWS account; Gazeek gives no AWS access.

Cost: two short calls to Amazon Nova Micro, about a thousand tokens, a small fraction of a cent. Nothing is created, so there is nothing to clean up.

Before you start

  • AWS credentials on your machine that can call bedrock:InvokeModel and bedrock:InvokeModelWithResponseStream in us-east-1 (Strands streams, so it needs both).
  • Python 3.10 or later.

Steps

  1. A folder, a virtual environment, and the Strands Agents SDK:

    python3 -m venv .venv && source .venv/bin/activate
    pip install "strands-agents==1.67.0"
    

    Don't install strands-agents-tools: it is deprecated and no longer imports. Write your own tools with @tool.

  2. Save tool_agent.py. Three parts:

    • A tool: an ordinary Python function with @tool. Its docstring is how the model learns what it does.
    • A model: BedrockModel, with the model ID named (Strands' default model changes between versions) and max_tokens set (the default is the model's maximum, which Bedrock reserves against your quota on every call).
    • An agent: the model, the tools and a system prompt. Calling agent("…") is the agent call.
  3. Run it:

    python -u tool_agent.py
    

What you should see

Gazeek's test run, 27 Nov 2026:

<thinking> To find out the number of words in the given text, I can use the word_count tool. … </thinking>

Tool #1: word_count
The text "the quick brown fox jumps over the lazy dog" contains 9 words.
stop reason: end_turn
cycles: 2 | tokens: {'inputTokens': 967, 'outputTokens': 92, 'totalTokens': 1059}

That is the agent loop. Cycle 1: the model reads the question and the tool's description, and asks for word_count. Strands runs your function and sends the result back. Cycle 2: the model answers with it. Nova models show their reasoning in <thinking> tags; other models don't.

Try this

  • Remove tools=[word_count] and ask again: the model guesses, and may get it wrong.
  • Add a second tool (say, char_count) and ask a question that needs both.
  • Swap the model ID for another model that supports tool use (check its model card); nothing else changes.

Clean up

Nothing to clean up: the agent runs on your machine and only calls Bedrock.

What you learned

An agent is a model, tools and a loop. With Strands you write the tools; the model decides when to call them; the SDK runs the loop. Lesson 6-2 runs this same agent on Amazon Bedrock AgentCore Runtime.

tool_agent.py

"""Exercise 5: your first Strands agent, and its call (Amazon Bedrock Deep Dive, BDR-101).

Run:  python -u tool_agent.py
Needs: Python 3.10+, strands-agents (checked with 1.67.0), AWS credentials that can call Bedrock in us-east-1.
Cost: two short calls to Amazon Nova Micro, a small fraction of a cent.
"""
from strands import Agent, tool
from strands.models import BedrockModel


@tool
def word_count(text: str) -> int:
    """Count the words in a piece of text.

    Args:
        text: The text to count words in.
    """
    return len(text.split())


model = BedrockModel(
    model_id="amazon.nova-micro-v1:0",  # always name the model: Strands' default model changes between versions
    region_name="us-east-1",
    max_tokens=1024,                    # set it: the default is the model's maximum, which Bedrock reserves against your quota
)

agent = Agent(
    model=model,
    tools=[word_count],
    system_prompt="Use your tools for anything you could get wrong by guessing.",
)

result = agent('How many words are in "the quick brown fox jumps over the lazy dog"?')
print("\nstop reason:", result.stop_reason)
print("cycles:", result.metrics.cycle_count, "| tokens:", result.metrics.accumulated_usage)

← Back to Amazon Bedrock Deep Dive