-
Notifications
You must be signed in to change notification settings - Fork 215
Expand file tree
/
Copy path__init__.py
More file actions
102 lines (78 loc) · 2.69 KB
/
__init__.py
File metadata and controls
102 lines (78 loc) · 2.69 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
"""
This it the beginning of the agentstack public API.
Methods that have been imported into this file are expected to be used by the
end user inside their project.
"""
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_tool",
"get_agent",
"get_all_agents",
"get_all_agent_names",
"get_task",
"get_all_tasks",
"get_all_task_names",
"get_inputs",
]
def agent(func):
"""
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
def get_tags() -> list[str]:
"""
Get a list of tags relevant to the user's project.
"""
return ['agentstack', get_framework(), *conf.get_installed_tools()]
class ToolsMetaclass(type):
"""
Metaclass for the public tools interface.
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__(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)
def get_permissions(cls, func: Callable) -> _tools.ToolPermission:
"""
Get the permissions for a tool function.
"""
return _tools.get_permissions(func)
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