Skip to main content
Imagine that you’d like to extend the capabilities of your AI Agent with some new abilities. For example, out of the box, an LLM doesn’t know what time it is. If you ask it anyway, you’re not going to get a very good answer. If you want to teach the LLM to tell the time, you need to give it a tool.

Basic Example

You can define a tool with a name, description, and input schema. The input schema is used to parse the input from the LLM to the tool’s input type. The tool’s input type is used to parse the output from the tool to the LLM’s output type. The onCall function is called when the tool is invoked.
Tools are passed to the agent constructor and are available to the agent for the duration of the conversation. It’s not shown here, but it’s best practice for you to also list the tools and their metadata in the agent’s system message. See System Messages for more information.

Tools Without Parameters

For tools that don’t take any input, simply omit the inputSchema:
The tool will use a default empty object schema.

Multiple Tools

You can pass multiple tools to the agent constructor.

Streaming Tool Calls

Error Handling

If you throw an error in a tool, it will be caught and returned to the LLM as an error message so it can handle it gracefully (ideally).

Automatic Schema Generation

Use json_serializable for type-safe tools:

Examples

Next Steps