Skip to main content
The @function_tool decorator is the quickest path from a plain Python function to a QitOS tool. It inspects your function’s signature, type hints, and docstring, then builds a complete FunctionTool instance with an enriched ToolSpec — no subclassing required.

Step 1: Basic decorator usage

Apply the decorator without arguments. The function name becomes the tool name and the docstring becomes the description:
You can also use it with parentheses when you need to pass parameters (covered in the next step):
Both forms return a FunctionTool instance with a populated spec that includes the parameter schema, required fields, and description.

Step 2: Decorator parameters

Pass keyword arguments to the decorator to override defaults and control execution policy:
The available parameters are:

Step 3: Type hints become ToolSpec parameters

The decorator inspects your function’s type hints and converts them into JSON Schema entries inside ToolSpec.parameters. Supported types include:
Parameters without defaults are marked as required. Parameter descriptions are extracted from the Google-style Args: section of the docstring.

Step 4: Registering function tools in ToolRegistry

Once you have a FunctionTool, register it with a ToolRegistry so agents can discover and call it:
You can also register multiple tools at once and override names:

Step 5: Comparing @function_tool with class-based BaseTool

QitOS offers two ways to define tools. Use the one that fits your needs: @function_tool — best for simple, stateless operations:
BaseTool subclass — best for stateful tools or complex initialization:
When to choose which: Most tools are simple functions. Start with @function_tool and reach for BaseTool only when you need constructor state or custom execution behavior.

What’s next

MCP Integration

Bridge external MCP server tools into QitOS using the same FunctionTool interface.

Build your first agent

Use your tools inside an AgentModule with a real LLM loop.