Skip to content

Tool permissions #277

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3064aeb
Thoughts on tool permissions.
tcdent Feb 5, 2025
b5eeba8
More thoughts on tool permissions.
tcdent Feb 6, 2025
15a4a1a
More think.
tcdent Feb 6, 2025
36609cc
Implement tool permissions on file_read tool. Start user yaml file fo…
tcdent Feb 7, 2025
f0a52a7
User tool configs now merge with tool integrator configs to present a…
tcdent Feb 7, 2025
10f714b
Merge branch 'main' into tool-permissions
tcdent Feb 7, 2025
eb599e3
Finalize tool config inheritance.
tcdent Feb 7, 2025
70991d6
Update configs for all tools.
tcdent Feb 7, 2025
666a214
Tests pass.
tcdent Feb 8, 2025
ef7b87b
Preserve comments in tools.yaml. Bugfixes.
tcdent Feb 8, 2025
4100bed
100% coverage for _tools/__init__.py
tcdent Feb 8, 2025
6af2c30
Cleanup extra file.
tcdent Feb 8, 2025
5125865
Apply agentstack tool permissions to stripe tool.
tcdent Feb 11, 2025
f02f845
Merge branch 'main' into tool-permissions
tcdent Feb 14, 2025
64d5ed1
Update docs.
tcdent Feb 14, 2025
56ee072
Fix vision tool.
tcdent Feb 14, 2025
46bb249
Better docs.
tcdent Feb 14, 2025
5c36a2d
Update llms.txt
actions-user Feb 14, 2025
2891c62
Merge branch 'main' into tool-permissions
tcdent Feb 14, 2025
572b752
Add metaclass to `agentstack.tools` public method to allow type aliases.
tcdent Feb 14, 2025
e6329e3
Add `DELETE` permission.
tcdent Feb 14, 2025
1923312
Add permisioons to sql tool.
tcdent Feb 14, 2025
d95a1ac
Fix ToolPermission serialization
tcdent Feb 14, 2025
0bd8aed
Adapt create_tool to accept permissions.
tcdent Feb 14, 2025
8a6c464
Cleanup imports.
tcdent Feb 14, 2025
50c3ab1
Merge branch 'AgentOps-AI:main' into main
tcdent Feb 14, 2025
0bec814
Merge branch 'main' into tool-permissions
tcdent Feb 14, 2025
87c5931
Add permission checks to firecrawl.
tcdent Feb 14, 2025
c41f872
Type checking.
tcdent Feb 14, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 48 additions & 18 deletions agentstack/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,56 @@
end user inside their project.
"""

from typing import Callable
from typing import Callable, TypeAlias
from pathlib import Path
from agentstack import conf
from agentstack.utils import get_framework
from agentstack.agents import get_agent, get_all_agents, get_all_agent_names
from agentstack.tasks import get_task, get_all_tasks, get_all_task_names
from agentstack.inputs import get_inputs
from agentstack import _tools
from agentstack._tools import get_tool
from agentstack import frameworks

___all___ = [
"conf",
"agent",
"task",
"tools",
"get_tags",
"get_framework",
"get_agent",
"conf",
"agent",
"task",
"tools",
"get_tags",
"get_framework",
"get_tool",
"get_agent",
"get_all_agents",
"get_all_agent_names",
"get_task",
"get_task",
"get_all_tasks",
"get_all_task_names",
"get_inputs",
"get_inputs",
]


def agent(func):
"""
The `agent` decorator is used to mark a method that implements an Agent.
The `agent` decorator is used to mark a method that implements an Agent.
"""

def wrap(*args, **kwargs):
"""Does not alter the function's behavior; this is just a marker."""
return func(*args, **kwargs)

return wrap


def task(func):
"""
The `task` decorator is used to mark a method that implements a Task.
"""

def wrap(*args, **kwargs):
"""Does not alter the function's behavior; this is just a marker."""
return func(*args, **kwargs)

return wrap


Expand All @@ -57,16 +65,38 @@
return ['agentstack', get_framework(), *conf.get_installed_tools()]


class ToolLoader:
class ToolsMetaclass(type):
"""
Provides the public interface for accessing tools, wrapped in the
framework-specific callable format.
Metaclass for the public tools interface.

Get a tool's callables by name with `agentstack.tools[tool_name]`
Include them in your agent's tool list with `tools = [*agentstack.tools[tool_name], ]`
Define methods here to expose in the public API. Using a metaclass let's us
use methods traditionally only available to instances on the class itself.
"""

def __getitem__(self, tool_name: str) -> list[Callable]:
def __getitem__(cls, tool_name: str) -> list[Callable]:
"""
Get a tool's callables by name with `agentstack.tools[tool_name]`
Include them in your agent's tool list with `tools = [*agentstack.tools[tool_name], ]`
"""
return frameworks.get_tool_callables(tool_name)

tools = ToolLoader()
def get_permissions(cls, func: Callable) -> _tools.ToolPermission:
"""
Get the permissions for a tool function.
"""
return _tools.get_permissions(func)

Check warning on line 87 in agentstack/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/__init__.py#L87

Added line #L87 was not covered by tests


class tools(metaclass=ToolsMetaclass):
"""
Provides the public interface for accessing `agentstack._tools` methods and
types that we explicitly expose.

Access wrapped tools with `agentstack.tools[tool_name]`

Access tool permissions with `agentstack.tools.get_permissions(func)`

Access the tool Action type with `agentstack.tools.Action`
"""

Action: TypeAlias = _tools.Action
Loading