Skip to content
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

ToolDef class for dynamically creating tool definitions #719

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

jjallaire-aisi
Copy link
Collaborator

This PR introduces a ToolDef class for creating tools dynamically.

Previously, tools could only defined using @tool decorators and documentation comments. It's now possible to create a tool dynamically from any function by creating a ToolDef. For example:

from inspect_ai.solver import use_tools
from inspect_ai.tool import ToolDef

async def addition(x: int, y: int):
    return x + y

add_tool = ToolDef(
    tool=addition,
    name="add",
    description="A tool to add numbers", 
    parameters={
        "x": "the x argument",
        "y": "the y argument"
    })
)

use_tools([add_tool])

This is effectively what happens under the hood when you use the @tool decorator. There is one critical requirement for functions that are bound to tools using ToolDef: type annotations must be provided in the function signature (e.g. x: int, y: int).

ToolDef can generally be used anywhere that Tool can be used (use_tools(), setting state.tools, etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants