To create a tool, add a Python file to the tools/ directory.
Requirements:
- Module Docstring: The file's docstring is used as the tool's description.
- Function Signature: Use type hints and
Annotated with pydantic.Field for parameter descriptions. Golf automatically infers the schema. - Output Schema: Use a Pydantic
BaseModel to define the return type. - Entry Point: You must assign your function to a variable named
export.
# tools/hello.py
"""Hello World tool {{project_name}}."""
from typing import Annotated
from pydantic import BaseModel, Field
class Output(BaseModel):
"""Response from the hello tool."""
message: str
async def hello(
name: Annotated[str, Field(description="The name of the person to greet")] = "World",
greeting: Annotated[str, Field(description="The greeting phrase to use")] = "Hello"
) -> Output:
"""Say hello to the given name.
This is a simple example tool that demonstrates the basic structure
of a tool implementation in Golf.
"""
print(f"{greeting} {name}...")
return Output(message=f"{greeting}, {name}!")
# Designate the entry point function
export = hello