AMAZON BEDROCK / SERVICE DETAIL S01 HARNESS
HARNESS, THE STRANDS PATHPRACTICAL 1 / 2
CHAPTER 05 / 36
TOPIC build and run the loop yourself
REV 2026.07
New to these words? Sheet 01-A "Key terms" defines agent, tool, the loop, model, and session.
IN PLAIN WORDS
You will install the Strands library, write a tiny agent in one file, and run it on your own machine to watch the loop work. Terms used here: pip = the Python package installer; @tool = a small tag that turns a normal function into something the agent can call; model provider = where the AI model runs (here Amazon Bedrock, which hosts Claude).
[ 1 ] INSTALL AND SET UP
$ pip install strands-agents strands-agents-tools
$ aws configure # set credentials and region
$ aws sts get-caller-identity # confirm credentials work
[x] Python 3.10+
[x] AWS credentials configured
[x] Bedrock model access (Claude)
[x] Strands defaults to Amazon Bedrock
[ 2 ] WRITE THE AGENT (my_agent.py)
# my_agent.py
from strands import Agent, tool
@tool
def word_count(text: str) -> int:
"""Count the words in a piece of text.""" # the docstring
return len(text.split()) # tells the model
agent = Agent(tools=[word_count]) # default model: Bedrock (Claude)
result = agent("How many words are in: the quick brown fox")
print(result)
WHAT EACH PART DOES
@tool turns a plain function into a tool the model can choose. The docstring and the type hints are the contract the model reads.
Agent(...) binds a model and the tools. Add system_prompt= for instructions.
agent("...") sends the input and runs the whole loop until a final answer.
[ 3 ] RUN IT
$ python my_agent.py
There are 4 words in "the quick brown fox".
[ 4 ] THE LOOP, MAPPED TO THIS CODE (see theory chapter 04 for L01 to L06)
L01 INPUT. You call agent("How many words ...").
L02 MODEL REASONS. The model reads the prompt plus the word_count tool spec, and decides to use a tool.
L03 TOOL CALL. It requests word_count(text="the quick brown fox").
L04 EXECUTE. Your function runs and returns 4.
L05 RESULT. The value goes back to the model.
L06 FINAL. No more tools needed, so the model writes the answer. The loop ends.
[ 5 ] GROW IT
+ Add more @tool functions. The model picks the right one per turn.
+ Intercept tools with hooks: BeforeToolCallEvent, AfterToolCallEvent.
+ Swap model providers (Bedrock, Anthropic, others) without changing the agent code.
+ Connect tools from AgentCore Gateway and MCP servers over MCP.
When you are ready to run this in the cloud without managing the loop or infrastructure, use the managed Harness. See practical chapter 04.