Skip to content

Commit 666a214

Browse files
committed
Tests pass.
1 parent 70991d6 commit 666a214

File tree

6 files changed

+35
-19
lines changed

6 files changed

+35
-19
lines changed

agentstack/_tools/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ def filter_tools(cls, data: dict) -> dict:
185185
try:
186186
user_config = UserToolConfig(tool_name)
187187
except FileNotFoundError:
188-
return data # if the user has no config, allow all tools.
188+
log.debug(f"User has no tools.yaml file; allowing all tools.")
189+
return data
189190

190191
log.debug(
191192
f"Excluding tools from {tool_name} based on project permissions: "
@@ -195,6 +196,7 @@ def filter_tools(cls, data: dict) -> dict:
195196

196197
filtered_perms = {}
197198
for func_name in user_config.tools:
199+
# TODO what about orphaned tools in the user config
198200
base_perms: dict = tool_data.get(func_name, {})
199201
assert base_perms, f"Tool config.json for '{tool_name}' does not include '{func_name}'."
200202

@@ -205,12 +207,8 @@ def filter_tools(cls, data: dict) -> dict:
205207
user_perms = _user_perms.model_dump()
206208
assert user_perms is not None, f"User tool permission got unexpected type {type(_user_perms)}."
207209

208-
filtered_perms[func_name] = ToolPermission(
209-
**{
210-
**base_perms,
211-
**user_perms,
212-
}
213-
)
210+
all_perms = {**base_perms, **user_perms}
211+
filtered_perms[func_name] = ToolPermission(**all_perms)
214212

215213
data['tools'] = filtered_perms
216214
return data
@@ -393,6 +391,7 @@ def _initialize_user_tool_config() -> None:
393391
all of the tools available to the user. This is used to bring an existing
394392
project up to date with a UserToolConfig.
395393
"""
394+
# TODO actually use this
396395
# TODO there is documentation in the example project file for this, which we
397396
# should include in old projects, too.
398397

agentstack/_tools/composio/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def execute_action(
3636
"""
3737
permissions = tools.get_permissions(execute_action)
3838
if not permissions.EXECUTE:
39-
return "User has not granted execute permission."
39+
return {'error': "User has not granted execute permission."}
4040

4141
toolset = ComposioToolSet()
4242
action = Action(action_name)
@@ -55,7 +55,7 @@ def get_action_schema(action_name: str) -> Dict[str, Any]:
5555
"""Get the schema for a composio action."""
5656
permissions = tools.get_permissions(get_action_schema)
5757
if not permissions.READ:
58-
return "User has not granted read permission."
58+
return {'error': "User has not granted read permission."}
5959

6060
toolset = ComposioToolSet()
6161
action = Action(action_name)
@@ -70,7 +70,7 @@ def find_actions_by_use_case(
7070
"""Find actions by use case."""
7171
permissions = tools.get_permissions(find_actions_by_use_case)
7272
if not permissions.READ:
73-
return "User has not granted read permission."
73+
return [{'error': "User has not granted read permission."}]
7474

7575
toolset = ComposioToolSet()
7676
actions = toolset.find_actions_by_use_case(*apps, use_case=use_case)
@@ -84,7 +84,7 @@ def find_actions_by_tags(
8484
"""Find actions by tags."""
8585
permissions = tools.get_permissions(find_actions_by_tags)
8686
if not permissions.READ:
87-
return "User has not granted read permission."
87+
return [{'error': "User has not granted read permission."}]
8888

8989
toolset = ComposioToolSet()
9090
actions = toolset.find_actions_by_tags(*apps, tags=tags)

tests/fixtures/tool_config_max.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"name": "tool_name",
33
"category": "category",
4-
"tools": ["tool1", "tool2"],
54
"url": "https://example.com",
65
"cta": "Click me!",
76
"env": {
@@ -13,5 +12,14 @@
1312
"dependency2>=2.0.0"
1413
],
1514
"post_install": "install.sh",
16-
"post_remove": "remove.sh"
15+
"post_remove": "remove.sh",
16+
"tools": {
17+
"tool1": {
18+
"actions": ["read", "write"],
19+
"additional_property": "value"
20+
},
21+
"tool2": {
22+
"actions": ["read"]
23+
}
24+
}
1725
}
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
{
22
"name": "tool_name",
33
"category": "category",
4-
"tools": ["tool1", "tool2"]
4+
"tools": {
5+
"tool1": {
6+
"actions": ["read", "write"]
7+
},
8+
"tool2": {
9+
"actions": ["read"]
10+
}
11+
}
512
}

tests/test_frameworks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from agentstack.conf import ConfigFile, set_path
99
from agentstack.exceptions import ValidationError
1010
from agentstack import frameworks
11-
from agentstack._tools import ToolConfig, get_all_tools
11+
from agentstack._tools import ToolConfig, ToolPermission, get_all_tools
1212
from agentstack.agents import AGENTS_FILENAME, AgentConfig
1313
from agentstack.tasks import TASKS_FILENAME, TaskConfig
1414
from agentstack import graph
@@ -61,10 +61,10 @@ def _get_test_task_alternate(self) -> TaskConfig:
6161
return TaskConfig('task_name_two')
6262

6363
def _get_test_tool(self) -> ToolConfig:
64-
return ToolConfig(name='test_tool', category='test', tools=['test_tool'])
64+
return ToolConfig(name='test_tool', category='test', tools={'test_tool': {'actions': ['read']}})
6565

6666
def _get_test_tool_alternate(self) -> ToolConfig:
67-
return ToolConfig(name='test_tool_alt', category='test', tools=['test_tool_alt'])
67+
return ToolConfig(name='test_tool_alt', category='test', tools={'test_tool_alt': {'actions': ['write']}})
6868

6969
def test_get_framework_module(self):
7070
module = frameworks.get_framework_module(self.framework)

tests/test_tool_config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ def test_minimal_json(self):
1111
config = ToolConfig.from_json(BASE_PATH / "fixtures/tool_config_min.json")
1212
assert config.name == "tool_name"
1313
assert config.category == "category"
14-
assert config.tools == ["tool1", "tool2"]
14+
assert config.tool_names == ["tool1", "tool2"]
15+
# TODO test config.tools
1516
assert config.url is None
1617
assert config.cta is None
1718
assert config.env is None
@@ -22,7 +23,8 @@ def test_maximal_json(self):
2223
config = ToolConfig.from_json(BASE_PATH / "fixtures/tool_config_max.json")
2324
assert config.name == "tool_name"
2425
assert config.category == "category"
25-
assert config.tools == ["tool1", "tool2"]
26+
assert config.tool_names == ["tool1", "tool2"]
27+
# TODO test config.tools
2628
assert config.url == "https://example.com"
2729
assert config.cta == "Click me!"
2830
assert config.env == {"ENV_VAR1": "value1", "ENV_VAR2": "value2"}

0 commit comments

Comments
 (0)