Skip to content

Commit e7d8563

Browse files
committed
Add get_action_from_memory
1 parent 47cb74e commit e7d8563

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

agentaction/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
get_last_action,
77
get_available_actions,
88
get_formatted_actions,
9+
get_action_from_memory,
910
search_actions,
1011
use_action,
1112
add_action,
@@ -23,6 +24,7 @@
2324
"get_last_action",
2425
"get_available_actions",
2526
"get_formatted_actions",
27+
"get_action_from_memory",
2628
"search_actions",
2729
"use_action",
2830
"add_action",

agentaction/main.py

+15
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ def get_available_actions(search_text, n_results=5):
124124

125125
return available_actions
126126

127+
def get_action_from_memory(action_name):
128+
"""
129+
Retrieve an action from memory based on the action's name.
130+
131+
Args:
132+
action_name: The name of the action to retrieve.
133+
134+
Returns:
135+
A dictionary representing the action.
136+
"""
137+
action = get_memories("actions", filter_metadata={"name": action_name}, n_results=1)
138+
if len(action) == 0:
139+
return None
140+
return action[0]
141+
127142

128143
def search_actions(search_text, n_results=5):
129144
"""

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
setup(
1414
name="agentaction",
15-
version="0.1.2",
15+
version="0.1.3",
1616
description="Action chaining and history for agents",
1717
long_description=readme, # added this line
1818
long_description_content_type="text/markdown", # and this line

test.py

+9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
get_action_history,
77
get_last_action,
88
get_available_actions,
9+
get_action_from_memory,
910
search_actions,
1011
use_action,
1112
add_action,
@@ -112,6 +113,14 @@ def test_get_available_actions():
112113
assert len(available_actions) > 0 # Should be at least one action
113114
cleanup() # Cleanup after the test
114115

116+
def get_get_action_from_memory():
117+
cleanup() # Ensure clean state before test
118+
test_action = setup_test_action()
119+
add_action("test", test_action)
120+
121+
memory = get_action_from_memory("test")
122+
assert memory is not None
123+
cleanup() # Cleanup after the test
115124

116125
# Define a directory for testing import_actions
117126
TEST_DIR = "test_actions_dir"

0 commit comments

Comments
 (0)