Back to Blog
Tutorials

Teaching Your LLM to Tell Time: A Practical Guide to LLM Tool Integration

Learn LLM tool integration with OpenAI in JavaScript. Build real-time functions for your AI with this step-by-step tutorial on tool calling and function execution.

Teaching Your LLM to Tell Time: A Practical Guide to LLM Tool Integration

Last Tuesday, I watched my LLM confidently tell a user it was 3 PM. The problem? It was 9 AM. The knowledge cutoff strikes again.

This happens because LLMs live in a frozen moment. They trained on data from months ago. They don't know what time it is right now. They don't know the weather. They don't know your calendar. They exist in a bubble.

LLM tool integration changes this. You give your LLM access to real functions. Functions that check the time. Functions that read databases. Functions that call APIs. Your LLM becomes connected to the real world.

Let me show you how to build this.

What Are LLM Tools?

Tools are functions your LLM calls when it needs information it doesn't have. Think of them as APIs for your AI.

Here's how it works:

  1. You define functions your LLM knows about
  2. Your LLM decides when to call these functions
  3. You execute the function on your server
  4. You send the result back to your LLM
  5. Your LLM uses this fresh data to respond

The LLM doesn't execute code. You do. The LLM makes the decision to call your function. You control what gets executed.

This keeps things safe. This keeps things flexible.

Why You Need LLM Tool Integration

Your LLM needs tools for three reasons:

First, real-time data. Stock prices change. Weather changes. User databases update. Your LLM needs current information.

Second, external systems. You want your LLM to book meetings. Send emails. Update CRM records. Create tickets. Tools make this happen.

Third, computation. Need to process a CSV with 10,000 rows? Run complex calculations? Query a database? Tools handle the heavy lifting.

At artiforge.ai, we build dozens of tool integrations for clients. The pattern stays the same. Define the function. Let the LLM call it. Return the result.

Building Your First Tool: The Time Reader

We'll build a simple tool. A function that returns the current time. Your LLM will call this function when users ask about time.

Step 1: Set Up Your Project

Create a new directory and install the OpenAI SDK:

bash

Create a file called timebot.js.

Step 2: Define Your Tool

Tools in OpenAI follow a specific format. You describe the function. You tell the LLM when to use it.

javascript

The description matters. Write clear descriptions. The LLM uses this to decide when to call your function.

Step 3: Implement the Function

Now write the function your tool calls:

javascript

This uses the Intl API. Native JavaScript. No dependencies. Returns a formatted string.

Step 4: Build the Chat Loop

Now connect everything. Send messages to OpenAI. Handle tool calls. Return results.

javascript

Step 5: Test Your Tool

Add this to test your bot:

javascript

Run it:

bash

Your LLM now knows the current time. It calls your function. It uses real data.

Adding More Tools

You don't stop at one tool. Build multiple tools. Each tool does one thing well.

Here are tools worth building:

Weather Tool: Fetch weather from an API. Users ask "Will it rain today?" Your LLM calls your weather function.

Database Query Tool: Read from your database. Users ask "How many orders this week?" Your LLM queries your data.

Calculator Tool: Handle complex math. LLMs struggle with precise calculations. Tools handle this perfectly.

File Reader Tool: Read uploaded files. Parse CSVs. Extract data. Return structured information.

Calendar Tool: Check availability. Book meetings. Your LLM becomes a scheduling assistant.

Each tool follows the same pattern. Define it. Implement it. Let your LLM call it.

Best Practices for LLM Tool Integration

Write clear descriptions. The LLM relies on your description to decide when to call your function. Vague descriptions lead to wrong tool calls.

Validate function arguments. The LLM generates arguments based on user input. Users say strange things. Validate before executing.

Handle errors gracefully. APIs fail. Networks timeout. Databases lock. Return error messages the LLM understands.

Keep functions focused. One function does one thing. Don't build a function that does five different tasks.

Return structured data. JSON works well. Clear key names. Consistent format. Your LLM parses this better.

Test edge cases. What happens when timezones are invalid? When databases are empty? When APIs are down? Test these scenarios.

When Tool Integration Gets Complex

Simple tools are straightforward. Complex integrations need more thought.

You might need authentication. OAuth flows. API keys. Session management. Store credentials securely. Pass them to your tools.

You might need rate limiting. APIs have limits. Track calls. Implement backoff. Queue requests.

You might need chaining. One tool calls another. Weather data needs location first. Location needs address parsing. Chain these calls.

You might need state. Remember previous tool calls. Build context. Make your LLM smarter over time.

At artiforge.ai, we handle these complexities daily. Tool integration becomes your architecture. Design it well from the start.

The Real Power of LLM Tools

Tools transform your LLM from a text generator into an agent. An agent that acts on your behalf. An agent that connects systems. An agent that solves real problems.

I've seen LLMs with tools:

  • Process customer support tickets automatically
  • Generate reports from live database queries
  • Book meetings across three calendars
  • Monitor systems and alert teams
  • Analyze financial data and explain trends

Each started with simple tool integration. Each grew into something valuable.

Your time tool is step one. Build it. Test it. Then build another. Then another.

Your LLM becomes more useful with each tool you add.


Ready to start building? Give your LLM the tools it needs. Watch it solve problems you didn't program it to solve.

The code is simple. The possibilities are endless.