Skip to content

[WIP] X Tool #303

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
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
30 changes: 28 additions & 2 deletions agentstack/_tools/__init__.py
Original file line number Diff line number Diff line change
@@ -24,6 +24,32 @@ def _get_builtin_tool_path(name: str) -> Path:
return TOOLS_DIR / name / TOOLS_CONFIG_FILENAME


class Callback(pydantic.BaseModel):
"""A callback to be called after a tool is run."""

script: Optional[str] = None # call a script (this is the current implementation)
method: Optional[str] = None # call a python method
url: Optional[str] = None # call a URL

@pydantic.validator('script', 'method', 'url', mode='after')
def check_callback(cls, v, values, field):
if not any([values.get('script'), values.get('method'), values.get('url')]):
raise ValueError('At least one of script, method, or url must be set')
return v

@property
def SCRIPT(self) -> bool:
return self.script is not None

@property
def METHOD(self) -> bool:
return self.method is not None

@property
def URL(self) -> bool:
return self.url is not None


class ToolConfig(pydantic.BaseModel):
"""
This represents the configuration data for a tool.
@@ -38,8 +64,8 @@ class ToolConfig(pydantic.BaseModel):
cta: Optional[str] = None
env: Optional[dict] = None
dependencies: Optional[list[str]] = None
post_install: Optional[str] = None
post_remove: Optional[str] = None
post_install: Optional[Callback] = None
post_remove: Optional[Callback] = None

@classmethod
def from_tool_name(cls, name: str) -> 'ToolConfig':
Loading