DEV Community

Eesuola Opeyemi
Eesuola Opeyemi

Posted on

Booksy Agent — Your AI Reading Companion

Introduction

Reading is an incredible way to grow, but keeping track of what you’ve read, where you stopped, and what you learned can quickly get messy especially for avid readers. That’s the problem I wanted to solve with Booksy Agent.

Booksy Agent is an AI-powered reading companion that helps you manage your books, summarize chapters, track reading progress, and generate personalized recommendations, all through a conversational interface.

What problem I solved

Readers often lose track of progress, forget book insights, and have no structured way to manage reading goals. Booksy solves this by combining AI summarization, note-taking, and reading analytics into one smart assistant.

Why I chose this agent

I chose to build a reading focused agent because it’s relatable and practical. Everyone reads whether it’s for learning or leisure and this agent makes reading more intentional and intelligent. It also demonstrates how AI can enhance everyday habits using automation, structured data, and context-aware conversation.

The Tech Stack

  • Mastra Framework — the backbone for agent creation, orchestration, and routing.

  • Google Gemini AI — powers smart summaries, insights, and recommendations.

  • Open Library & Google Books APIs — fetch book metadata, cover images, and author info.

  • TypeScript — ensures type safety and maintainable, scalable code.

  • Telex.im Integration — connects the agent to Telex via the A2A (Agent-to-Agent) protocol.

Building the Agent

  1. Setting Up Mastra Mastra provides an elegant way to define agents, tools, and AI models. Here’s the core setup for the Booksy Agent: import { Agent } from "@mastra/core/agent"; import { bookManagementTool, bookSearchTool, bookSummaryTool } from "../tools/book-tools"; import { readingProgressTool, readingStreakTool, readingNotesTool } from "../tools/reading-tools"; import { Memory } from '@mastra/memory'; import { LibSQLStore } from '@mastra/libsql';

export const booksyAgent = new Agent({
name: "Booksy Reading Companion",
instructions: `
You're a helpful AI reading companion that helps users manage their reading journey.

**Your capabilities:**
- Track reading progress across multiple books
- Generate chapter summaries and key takeaways
- Maintain reading streaks and motivation
- Take and organize reading notes
- Provide personalized book recommendations
Enter fullscreen mode Exit fullscreen mode

model: "google/gemini-2.5-flash",
tools: {
bookManagementTool,
bookSearchTool,
bookSummaryTool,
readingProgressTool,
readingStreakTool,
readingNotesTool,
},
memory: new Memory({
storage: new LibSQLStore({
url: 'file:../mastra.db', // path is relative to the .mastra/output directory
}),
}),
});
This setup defines the agent’s identity and binds its tools — giving it the ability to handle book management and reading progress commands.

  1. Creating Tools

Tools are how the agent performs specific actions like adding books, tracking progress, or taking notes.
Example: A simple book management tool.
import { createTool } from "@mastra/core";
import { z } from "zod";
import { bookStorage } from "../utils/storage";
import { Book, BookStatus } from "../utils/definitions";

export const bookManagementTool = createTool({
id: "manage-book",
description: "Add, update, or retrieve books in the user's library",
inputSchema: z.object({
action: z.enum(["add", "update", "get", "list"]).describe("Action to perform"),
bookId: z.string().optional().describe("Book ID for update/get operations"),
title: z.string().optional().describe("Book title"),
author: z.string().optional().describe("Book author"),
totalChapters: z.number().optional().describe("Total number of chapters"),
currentChapter: z.number().optional().describe("Current chapter number"),
genre: z.string().optional().describe("Book genre"),
status: z.enum(["reading", "completed", "want-to-read"]).optional(),
}),
outputSchema: z.object({
success: z.boolean(),
message: z.string(),
book: z.any().optional(),
books: z.array(z.any()).optional(),
}),
Each tool is modular, easy to test, and can be reused or expanded.

  1. AI Integration

Booksy uses Google Gemini AI to automatically generate chapter summaries, key takeaways, and book recommendations.
Here’s a simplified example of AI summarization:
import { Agent } from "@mastra/core/agent";

export interface SummaryOptions {
bookTitle: string;
author: string;
chapter: number;
length: "short" | "medium" | "long";
userNotes?: string[];
context?: string;
}

export interface ChapterSummary {
summary: string;
keyTakeaways: string[];
actionableInsights: string[];
quotes?: string[];
relatedConcepts?: string[];
}

export class AISummaryService {
private summaryAgent: Agent;

constructor() {
// Create a specialized agent for summarization
this.summaryAgent = new Agent({
name: "Summary Generator",
instructions: `
You are an expert book summarization assistant. Your role is to create
insightful, actionable summaries of book chapters.

    **Guidelines:**
    - Focus on key concepts and main ideas
    - Extract actionable insights the reader can apply
    - Identify memorable quotes if provided
    - Connect ideas to broader themes
    - Be concise but comprehensive
    - Use clear, accessible language

    **Summary Lengths:**
    - SHORT: 2-minute read (150-200 words) - Just the essentials
    - MEDIUM: 5-minute read (400-500 words) - Balanced detail
    - LONG: 10-minute read (800-1000 words) - Comprehensive analysis

    Always structure your response as JSON with:
    {
      "summary": "Main summary text",
      "keyTakeaways": ["point 1", "point 2", "point 3"],
      "actionableInsights": ["action 1", "action 2"],
      "quotes": ["quote 1", "quote 2"],
      "relatedConcepts": ["concept 1", "concept 2"]
    }
  `,
  model: "google/gemini-2.5-flash", // Fast and cost-effective
});
Enter fullscreen mode Exit fullscreen mode

This gives users the ability to explore and add real books seamlessly.

  1. Telex.im Integration

To make Booksy usable within Telex, I implemented the A2A (Agent-to-Agent) protocol for communication between Booksy and other agents.
import { registerApiRoute } from "@mastra/core/server";
import { randomUUID } from "crypto";

export const a2aAgentRoute = registerApiRoute("/a2a/agent/:agentId", {
method: "POST",
handler: async (c) => {
try {
const mastra = c.get("mastra");
const agentId = c.req.param("agentId");

  // Parse JSON-RPC 2.0 request
  const body = await c.req.json();
  const { jsonrpc, id: requestId, method, params } = body;

  // Validate JSON-RPC 2.0 format
  if (jsonrpc !== "2.0" || !requestId) {
    return c.json(
      {
        jsonrpc: "2.0",
        id: requestId || null,
        error: {
          code: -32600,
          message:
            'Invalid Request: jsonrpc must be "2.0" and id is required',
        },
      },
      400
    );
  }
Enter fullscreen mode Exit fullscreen mode

This allows Booksy to respond to AI-driven messages inside the Telex.im ecosystem.

Challenges & Solutions
What worked well

Mastra’s structure made it simple to define and organize tools.

Gemini AI handled summarization and recommendations impressively.

The A2A integration connected smoothly with Telex.

What was difficult

Managing API rate limits from Google Books.

Maintaining state between reading sessions.

Fine-tuning AI summaries to stay accurate and concise.

How I solved problems

Implemented a caching layer for API results.

Used in-memory storage for temporary session tracking.

Adjusted prompt templates for better summarization balance.


Conclusion
What I learned

Building Booksy taught me how to combine AI reasoning, API integrations, and conversational interfaces into one coherent system. It also deepened my understanding of Mastra’s modular design and Telex’s agent ecosystem.

Future improvements

Integrate Goodreads or Notion export.

Add a “Reading Goals” tracker.

Support audiobooks and sync reading across devices.

Introduce a leaderboard for reading streaks.

Links

🔗 GitHub Repo: [https://github.com/eesuola/Booksy-Agent]

🌐 Live Demo: https://red-melodic-sunset-40618f2d-c6b7-4294-bd35-4883323b8e26.mastra.cloud/a2a/agent/booksyAgent

🤖 Telex Agent Link:[https://telex.im/telex-ai-intergration/home/colleagues/019a4d37-ff96-797a-a07e-1e5652a7e124/019a4d37-eae8-7979-b4a6-769b60698c78]

Top comments (0)