-
Notifications
You must be signed in to change notification settings - Fork 3
Structured Types in @tool Arguments
David-Andrew Samson edited this page Aug 26, 2024
·
5 revisions
In addition to the basic primitive types supported in Archytas tools (dict, list, int, float, bool, str None), more structured data types are supported in limited form. Currently supported structured types include:
dataclass-
BaseModelfrompydantic
For example:
from archytas.tool_utils import tool
from dataclasses import dataclass, field
@dataclass
class A:
val1: int
val2: str = 'hello'
@dataclass
class B:
val3: list[int]
val4: dict[str, int] = field(default_factory=dict)
@dataclass
class C:
b: B
val5: bool
@tool
def some_tool(a: A, c: C) -> str:
"""
description of some tool
Args:
a (A): description of what `a` is for.
c (C): description of what `c` is for.
Returns:
(str): ...
"""
# implementation of tool ...Or with pydantic models
from archytas.tool_utils import tool
from pydantic import BaseModel, Field
class A(BaseModel):
val1: int = Field(..., description="what is val1 for")
val2: str = Field(default='hello', description="what is val2 for")
class B(BaseModel):
val3: list[int] = Field(..., description="what is val3 for")
val4: dict[str, int] = Field(default_factory=dict, description="what is val4 for")
class C(BaseModel):
b: B = Field(..., description="what is b for")
val5: bool = Field(..., description="what is val5 for")
@tool
def some_tool(a: A, c: C) -> str:
"""
description of some tool
Args:
a (A): description of what `a` is for.
c (C): description of what `c` is for.
Returns:
(str): ...
"""
# implementation of tool ...