mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-13 13:17:40 +02:00
[Haik]: ckpt, added toolkit nesting, also reorganized folder structure
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Toolkit import Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Tool import Tool
|
||||
|
||||
from backend.apps.agents.HaikFix.tools.BUILTIN_TOOLKIT.components.AGENTS_TOOLKIT import AGENTS_TOOLKIT
|
||||
from backend.apps.agents.HaikFix.tools.BUILTIN_TOOLKIT.components.FILESYSTEM_TOOLKIT import FILESYSTEM_TOOLKIT
|
||||
from backend.apps.agents.HaikFix.tools.BUILTIN_TOOLKIT.components.INTERACTION_TOOLKIT import INTERACTION_TOOLKIT
|
||||
from backend.apps.agents.HaikFix.tools.BUILTIN_TOOLKIT.components.PLANNING_TOOLKIT import PLANNING_TOOLKIT
|
||||
from backend.apps.agents.HaikFix.tools.BUILTIN_TOOLKIT.components.SCHEDULING_TOOLKIT import SCHEDULING_TOOLKIT
|
||||
from backend.apps.agents.HaikFix.tools.BUILTIN_TOOLKIT.components.SEARCH_TOOLKIT import SEARCH_TOOLKIT
|
||||
from backend.apps.agents.HaikFix.tools.BUILTIN_TOOLKIT.components.SYSTEM_TOOLKIT import SYSTEM_TOOLKIT
|
||||
|
||||
BUILTIN_TOOLKIT = Toolkit(
|
||||
name="builtin",
|
||||
description="Builtin tools",
|
||||
nested_toolkits=[
|
||||
AGENTS_TOOLKIT,
|
||||
FILESYSTEM_TOOLKIT,
|
||||
INTERACTION_TOOLKIT,
|
||||
PLANNING_TOOLKIT,
|
||||
SCHEDULING_TOOLKIT,
|
||||
SEARCH_TOOLKIT,
|
||||
SYSTEM_TOOLKIT,
|
||||
]
|
||||
)
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
from backend.apps.agents.HaikFix.tools.Tool import Tool, Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Toolkit import Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Tool import Tool
|
||||
|
||||
AGENTS_TOOLKIT = Toolkit(
|
||||
name="agents",
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
from backend.apps.agents.HaikFix.tools.Tool import Tool, Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Toolkit import Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Tool import Tool
|
||||
|
||||
FILESYSTEM_TOOLKIT = Toolkit(
|
||||
name="filesystem",
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
from backend.apps.agents.HaikFix.tools.Tool import Tool, Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Toolkit import Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Tool import Tool
|
||||
|
||||
INTERACTION_TOOLKIT = Toolkit(
|
||||
name="interaction",
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
from backend.apps.agents.HaikFix.tools.Tool import Tool, Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Toolkit import Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Tool import Tool
|
||||
|
||||
PLANNING_TOOLKIT = Toolkit(
|
||||
name="planning",
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
from backend.apps.agents.HaikFix.tools.Tool import Tool, Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Toolkit import Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Tool import Tool
|
||||
|
||||
SCHEDULING_TOOLKIT = Toolkit(
|
||||
name="scheduling",
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
from backend.apps.agents.HaikFix.tools.Tool import Tool, Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Toolkit import Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Tool import Tool
|
||||
|
||||
SEARCH_TOOLKIT = Toolkit(
|
||||
name="search",
|
||||
+2
-1
@@ -1,4 +1,5 @@
|
||||
from backend.apps.agents.HaikFix.tools.Tool import Tool, Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Toolkit import Toolkit
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Tool import Tool
|
||||
|
||||
SYSTEM_TOOLKIT = Toolkit(
|
||||
name="system",
|
||||
@@ -1,18 +0,0 @@
|
||||
from ast import List
|
||||
from typing import Literal, Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
TOOL_PERMISSIONS = Literal["allow", "ask", "deny"]
|
||||
|
||||
class Tool(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
deferred: bool
|
||||
permission: TOOL_PERMISSIONS
|
||||
|
||||
class Toolkit(BaseModel):
|
||||
name: str
|
||||
description: str
|
||||
tools: List[Tool]
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
from typing import Literal
|
||||
TOOL_PERMISSIONS = Literal["allow", "ask", "deny"]
|
||||
@@ -0,0 +1,9 @@
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.TOOL_PERMISSIONS import TOOL_PERMISSIONS
|
||||
|
||||
class Tool(BaseModel):
|
||||
name: str
|
||||
description: Optional[str] = None
|
||||
deferred: bool
|
||||
permission: TOOL_PERMISSIONS
|
||||
@@ -0,0 +1,42 @@
|
||||
from typing import Optional, List
|
||||
from pydantic import BaseModel
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.Tool import Tool
|
||||
from backend.apps.agents.HaikFix.tools.shared_structs.TOOL_PERMISSIONS import TOOL_PERMISSIONS
|
||||
from typeguard import typechecked
|
||||
|
||||
class Toolkit(BaseModel):
|
||||
name: str
|
||||
description: str
|
||||
tools: Optional[List[Tool]] = None
|
||||
nested_toolkits: Optional[List["Toolkit"]] = None
|
||||
|
||||
@typechecked
|
||||
def __init__(
|
||||
self,
|
||||
name: str,
|
||||
description: str,
|
||||
tools: Optional[List[Tool]] = None,
|
||||
nested_toolkits: Optional[List["Toolkit"]] = None
|
||||
) -> None:
|
||||
super().__init__(
|
||||
name=name,
|
||||
description=description,
|
||||
tools=tools,
|
||||
nested_toolkits=nested_toolkits
|
||||
)
|
||||
self.validate_structure(tools, nested_toolkits)
|
||||
|
||||
@typechecked
|
||||
def validate_structure(self) -> None:
|
||||
assert not ( (self.tools is None) and (self.nested_toolkits is None) ), "Either tools or nested_toolkits must be provided"
|
||||
assert (self.tools is None) or (self.nested_toolkits is None), "Only one of tools or nested_toolkits can be provided"
|
||||
|
||||
@typechecked
|
||||
def set_permission(self, permission: TOOL_PERMISSIONS) -> None:
|
||||
self.validate_structure()
|
||||
if self.tools is not None:
|
||||
for tool in self.tools:
|
||||
tool.permission = permission
|
||||
if self.nested_toolkits is not None:
|
||||
for toolkit in self.nested_toolkits:
|
||||
toolkit.set_permission(permission)
|
||||
Reference in New Issue
Block a user