How timifaloye/bookly-support-agent works
Purpose and Entry Points
Bookly Support Agent is a Node.js/TypeScript prototype for SMS/iMessage bookstore support. It accepts customer messages, maintains conversation context, uses LLMs to classify and answer requests, invokes order/return tools, and performs an asynchronous response-accuracy check.
Local CLI execution starts from src/index.ts. The production messaging path is the OSIS webhook server in src/server.ts, which delegates inbound events to src/osis/webhookHandler.ts.
OSIS Ingress and Webhook Safety
The OSIS adapter validates, parses, logs, and deduplicates inbound provider webhooks before agent processing:
• src/osis/webhookHandler.ts
• src/osis/signature.ts
• src/osis/webhookPayload.ts
Duplicate protection is backed by SQLite through src/osis/sqliteDedupeTracker.ts; this preserves idempotency across development-server restarts. The OSIS client in src/osis/client.ts is the outbound messaging boundary and requires OSIS credentials.
Conversation Persistence
Conversation history is abstracted behind a store and persisted in SQLite for the webhook runtime:
• src/state/conversationStore.ts
• src/state/sqliteConversationStore.ts
The agent retrieves prior turns for each customer/channel conversation, appends the inbound message and generated response, and supplies history to the model pipeline. This separates stateful conversations from stateless business tools.
Agent Orchestration and LLM Pipeline
src/claude/agent.ts is the central coordinator. It runs a three-stage flow:
1. classify user intent;
2. generate a tool-aware support reply;
3. run a background hallucination/accuracy check.
Core model-facing modules are:
• src/claude/intentClassifier.ts
• src/claude/systemPrompt.ts
• src/claude/hallucinationCheck.ts
Anthropic is the primary Claude integration; OpenAI is also required by the application, likely for the accuracy-check stage. Tool execution is mediated rather than directly exposed to model logic via src/claude/tools.ts and src/claude/toolExecutor.ts.
Intent, Tool, and Policy Boundary
Customer requests are mapped to a constrained support domain: verification, order status, return eligibility, and return creation:
• src/tools/verifyCustomer.ts
• src/tools/getOrderStatus.ts
• src/tools/checkReturnEligibility.ts
• src/tools/createReturnRequest.ts
Return decision logic is separated from tool transport in src/tools/returnEligibility.ts. The tools read/update prototype business records and policies through:
• src/data/orders.ts
• src/data/policy.ts
• src/data/returnRequests.ts
This boundary keeps LLM output from directly mutating data; return creation is an explicit tool action.
Return Confirmation and Email
After creating a return request, confirmation content and delivery are handled outside the core agent:
• src/claude/returnConfirmationMessage.ts
• src/lib/confirmation.ts
• src/lib/email.ts
src/lib/resendEmailClient.ts integrates Resend when RESEND_API_KEY is configured; otherwise confirmations are recorded without actual delivery. This makes email an optional external side effect rather than a prerequisite for request creation.
Runtime and Operational Constraints
The runtime is Node.js 24+ with TypeScript. Required external services are Anthropic, OpenAI, and, for live messaging, OSIS; Resend is optional. SQLite supports both conversation persistence and webhook deduplication. src/lib/devWatchWarning.ts reflects an operational distinction: auto-restart development mode is not intended for real webhook traffic despite durable local SQLite state.
Main entry points: agent.ts Support Agent · webhookHandler.ts Webhook Handler · tools.ts Support Toolset · intentClassifier.ts Intent Classifier
Components 20
OSIS Messaging
- Webhook Server
src/server.ts - Webhook Handler · Validates, parses, logs, and deduplicates inbound events.
src/osis/webhookHandler.ts - Signature Validation
src/osis/signature.ts - Webhook Payload Parser
src/osis/webhookPayload.ts - Webhook Dedupe · Preserves inbound idempotency across restarts.
src/osis/sqliteDedupeTracker.ts - OSIS Client · Outbound SMS/iMessage boundary.
src/osis/client.ts
Agent Pipeline
- Support Agent · Coordinates classification, reply generation, and background accuracy checking.
src/claude/agent.ts - Intent Classifier
src/claude/intentClassifier.ts - Support Prompt
src/claude/systemPrompt.ts - Tool Executor · Keeps model logic from directly mutating business data.
src/claude/toolExecutor.ts - Accuracy Check · Asynchronously evaluates generated responses.
src/claude/hallucinationCheck.ts - Anthropic Claude
- OpenAI · Required application LLM integration, likely used for accuracy evaluation.
Support Tools
- Support Toolset · Verification, order status, return eligibility, and return creation.
src/claude/tools.ts - Return Policy Logic
src/tools/returnEligibility.ts - Prototype Business Records
src/data/orders.ts
Durable State
- Conversation Store · Persists customer and channel conversation turns.
src/state/sqliteConversationStore.ts
Return Notifications
- Return Confirmation
src/lib/confirmation.ts - Email Delivery · Records confirmations when Resend is not configured.
src/lib/resendEmailClient.ts
Other components
- Local CLI
src/index.ts
Connections 20
- Local CLI → Support Agent: local messages
- Webhook Server → Webhook Handler: inbound webhook
- Webhook Handler → Signature Validation: validate
- Webhook Handler → Webhook Payload Parser: parse
- Webhook Handler → Webhook Dedupe: deduplicate
- Webhook Handler → Support Agent: accepted message
- Support Agent → Conversation Store: load and append turns
- Support Agent → Intent Classifier: classify
- Intent Classifier → Anthropic Claude: intent model call
- Support Agent → Support Prompt: build reply context
- Support Agent → Tool Executor: invoke approved actions
- Tool Executor → Support Toolset: dispatch
- Support Toolset → Return Policy Logic: evaluate return
- Support Toolset → Prototype Business Records: read or update
- Support Agent → Anthropic Claude: generate reply
- Support Agent → Accuracy Check: background check
- Accuracy Check → OpenAI: evaluate response
- Support Agent → OSIS Client: send reply
- Support Toolset → Return Confirmation: return created
- Return Confirmation → Email Delivery: deliver or record