-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
37 lines (29 loc) · 1.1 KB
/
agent.py
File metadata and controls
37 lines (29 loc) · 1.1 KB
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
from strands import Agent, tool
from strands_tools import calculator, current_time
# Define a custom tool as a Python function using the @tool decorator
@tool
def letter_counter(word: str, letter: str) -> int:
"""
Count occurrences of a specific letter in a word.
Args:
word (str): The input word to search in
letter (str): The specific letter to count
Returns:
int: The number of occurrences of the letter in the word
"""
if not isinstance(word, str) or not isinstance(letter, str):
return 0
if len(letter) != 1:
raise ValueError("The 'letter' parameter must be a single character")
return word.lower().count(letter.lower())
# Create an agent with tools from the community-driven strands-tools package
# as well as our custom letter_counter tool
agent = Agent(tools=[calculator, current_time, letter_counter])
# Ask the agent a question that uses the available tools
message = """
I have 4 requests:
1. What is the time right now?
2. Calculate 3111696 / 74088
3. Tell me how many letter R's are in the word "strawberry" 🍓
"""
agent(message)