Member-only story
Smallest AI Agent
Building one using Hono, Google Gen AI
Hello and welcome to the new blog, originally published on iHateReading.
In today’s story, we will be building the smallest AI agent to learn the concept of an LLM app.
I’ll be using hono, getting started with hono, because hono is now supported in vercel 😁
For LLM API, one can prefer OpenAI, I’ll be using @google/genai, the main reason is it’s cheaper than OpenAI API, and one can also use langchain to use local LLM using Ollama.
You need a Google Gemini API key or an OpenAI API key, or for FREE use a local LLM model with Ollama and langchain.
Our AI agent will take a user prompt and perform some operations by understanding the user prompt requirements. For example, read the file content, update the file or list the directory, and perform some BASH operations.
npm init
npm i hono, @google/genai, dotenvOnce installed, create a Google instance provided by the API key, add the API method to generate the endpoint.
import { Hono } from "hono";
import { serve } from "@hono/node-server";
import fs from "fs";
import dotenv from "dotenv";
import { Type, GoogleGenAI } from "@google/genai";
// Load environment variables
dotenv.config();
const genai = new GoogleGenAI({
apiKey…