FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sdk-python/tests_integ/test_bedrock_cache_point.py at main · polytech-dev/sdk-python · GitHub
polytech-dev
/
sdk-python
Public
forked from
strands-agents/harness-sdk
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sdk-python
/
tests_integ
/
test_bedrock_cache_point.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
60 lines (50 loc) · 2.3 KB
Breadcrumbs
sdk-python
/
tests_integ
/
test_bedrock_cache_point.py
Copy path
File metadata and controls
60 lines (50 loc) · 2.3 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from
strands
import
Agent
from
strands
.
models
import
BedrockModel
from
strands
.
types
.
content
import
Messages
def
test_bedrock_cache_point
():
messages
:
Messages
=
[
{
"role"
:
"user"
,
"content"
: [
{
"text"
:
"Some really long text!"
*
1000
# Minimum token count for cachePoint is 1024 tokens
},
{
"cachePoint"
: {
"type"
:
"default"
}},
],
},
{
"role"
:
"assistant"
,
"content"
: [{
"text"
:
"Blue!"
}]},
]
cache_point_usage
=
0
def
cache_point_callback_handler
(
**
kwargs
):
nonlocal
cache_point_usage
if
"event"
in
kwargs
and
kwargs
[
"event"
]
and
"metadata"
in
kwargs
[
"event"
]
and
kwargs
[
"event"
][
"metadata"
]:
metadata
=
kwargs
[
"event"
][
"metadata"
]
if
"usage"
in
metadata
and
metadata
[
"usage"
]:
if
"cacheReadInputTokens"
in
metadata
[
"usage"
]
or
"cacheWriteInputTokens"
in
metadata
[
"usage"
]:
cache_point_usage
+=
1
agent
=
Agent
(
messages
=
messages
,
callback_handler
=
cache_point_callback_handler
,
load_tools_from_directory
=
False
)
agent
(
"What is favorite color?"
)
assert
cache_point_usage
>
0
def
test_bedrock_multi_prompt_and_duplicate_cache_point
():
"""Test multi-prompt system with cache point."""
system_prompt_content
=
[
{
"text"
:
"You are a helpful assistant."
*
500
},
# Long text for cache
{
"cachePoint"
: {
"type"
:
"default"
}},
{
"text"
:
"Always respond with enthusiasm!"
},
]
cache_point_usage
=
0
def
cache_point_callback_handler
(
**
kwargs
):
nonlocal
cache_point_usage
if
"event"
in
kwargs
and
kwargs
[
"event"
]
and
"metadata"
in
kwargs
[
"event"
]
and
kwargs
[
"event"
][
"metadata"
]:
metadata
=
kwargs
[
"event"
][
"metadata"
]
if
"usage"
in
metadata
and
metadata
[
"usage"
]:
if
"cacheReadInputTokens"
in
metadata
[
"usage"
]
or
"cacheWriteInputTokens"
in
metadata
[
"usage"
]:
cache_point_usage
+=
1
agent
=
Agent
(
model
=
BedrockModel
(
model_id
=
"us.anthropic.claude-sonnet-4-20250514-v1:0"
,
cache_prompt
=
"default"
),
system_prompt
=
system_prompt_content
,
callback_handler
=
cache_point_callback_handler
,
load_tools_from_directory
=
False
,
)
agent
(
"Hello!"
)
assert
cache_point_usage
>
0
Back
|
FazBrowse Home
|
New Git URL