FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sdk-python/tests_integ/test_function_tools.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_function_tools.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
55 lines (41 loc) · 1.5 KB
Breadcrumbs
sdk-python
/
tests_integ
/
test_function_tools.py
Copy path
File metadata and controls
55 lines (41 loc) · 1.5 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
#!/usr/bin/env python3
"""
Test script for function-based tools
"""
import
logging
from
typing
import
Optional
from
strands
import
Agent
,
tool
logging
.
getLogger
(
"strands"
).
setLevel
(
logging
.
DEBUG
)
logging
.
basicConfig
(
format
=
"%(levelname)s | %(name)s | %(message)s"
,
handlers
=
[
logging
.
StreamHandler
()])
@
tool
def
word_counter
(
text
:
str
)
->
str
:
"""
Count words in text.
Args:
text: Text to analyze
"""
count
=
len
(
text
.
split
())
return
f"Word count:
{
count
}
"
@
tool
(
name
=
"count_chars"
,
description
=
"Count characters in text"
)
def
count_chars
(
text
:
str
,
include_spaces
:
Optional
[
bool
]
=
True
)
->
str
:
"""
Count characters in text.
Args:
text: Text to analyze
include_spaces: Whether to include spaces in the count
"""
if
not
include_spaces
:
text
=
text
.
replace
(
" "
,
""
)
return
f"Character count:
{
len
(
text
)
}
"
# Initialize agent with function tools
agent
=
Agent
(
tools
=
[
word_counter
,
count_chars
])
print
(
"
\n
===== Testing Direct Tool Access ====="
)
# Use the tools directly
word_result
=
agent
.
tool
.
word_counter
(
text
=
"Hello world, this is a test"
)
print
(
f"
\n
Word counter result:
{
word_result
}
"
)
char_result
=
agent
.
tool
.
count_chars
(
text
=
"Hello world!"
,
include_spaces
=
False
)
print
(
f"
\n
Character counter result:
{
char_result
}
"
)
print
(
"
\n
===== Testing Natural Language Access ====="
)
# Use through natural language
nl_result
=
agent
(
"Count the words in this sentence: 'The quick brown fox jumps over the lazy dog'"
)
print
(
f"
\n
NL Result:
{
nl_result
}
"
)
Back
|
FazBrowse Home
|
New Git URL