Build Your Digital Twin Using LazAI

Build Your Digital Twin Using LazAI

by Danny Steffe | LazAI Dev Ambassador

Ever wished your AI could tweet like you — same tone, same quirks, same vibe?

That’s exactly what LazAI’s Digital Twin does.Your Digital Twin is an AI persona trained on your own content. It speaks in your voice, understands your style, and can even post on your behalf — either manually or on a schedule.

Let’s walk through how it works and how to build your own.


:gear: What’s a Digital Twin?

In LazAI, a Digital Twin is your AI clone — a portable, interoperable persona that lives in a single JSON file called character.json.

That file defines your style, tone, traits, and examples — basically, your digital personality.
The beauty of it: any Alith agent or LLM can load it instantly.

:puzzle_piece: Why use one?

  • Portable persona: one JSON file, usable across any LLM or agent.

  • Separation of concerns: keep your style/persona in JSON and logic in code.

  • Composable: swap personas without touching the backend.


:toolbox: Prerequisites

You’ll need:

  • macOS / WSL / Linux with Node.js 18+

  • An OpenAI or Anthropic (Claude) API key

  • Your Twitter/X archive (.zip)


:rocket: Step 0 — Setup

Clone the starter kit and install dependencies:

git clone https://github.com/0xLazAI/Digital-Twin-Starter-kit.git
cd Digital-Twin-Starter-kit


:brain: Step 1 — Generate Your Characterfile

This step turns your tweet history into a Digital Twin.

  1. Request your archive
    From X/Twitter → Settings → Download an archive.

  2. Generate your character.json

    npx tweets2character ~/Downloads/twitter-YYYY-MM-DD-<hash>.zip
    
    
    • Choose OpenAI or Claude

    • Paste your API key when prompted

    • Output: character.json in your current directory

  3. Place it in your project root

    /Digital-Twin-Starter-kit
      ├─ controller/
      ├─ services/
      ├─ routes/
      ├─ character.json   ← here
      └─ index.js
    
    

:robot: Step 2 — Integrate with an Alith Agent

Now, let’s bring your character to life.

LazAI uses Alith, a modular agent framework, to load your character.json as a preamble — the persona context fed into an LLM.

Your agent will:
:white_check_mark: Load character.json
:white_check_mark: Generate a tweet in your tone
:white_check_mark: Post it manually or automatically

Example:

const { Agent, LLM } = await import('alith');

const characterData = JSON.parse(fs.readFileSync('./character.json', 'utf8'));

const preamble = [
  `You are ${characterData.name}.`,
  characterData.bio?.join(' ') || '',
  characterData.lore ? `Lore: ${characterData.lore.join(' ')}` : '',
  characterData.style?.post ? `Style for posts: ${characterData.style.post.join(' ')}` : ''
].filter(Boolean).join('\n');

const model = LLM.from_model_name('gpt-4o-mini');
const agent = Agent.new('twitter_agent', model).preamble(preamble);

const chat = agent.chat();
const result = await chat.user(`Write one tweet in ${characterData.name}'s voice.`).complete();
console.log(result.content);

The persona is decoupled from the logic, so you can swap character.json anytime without touching your backend.


:high_voltage: Step 3 — Automate Tweets with Cron

Let your Digital Twin tweet for you automatically.
Here’s how:

const cron = require('node-cron');
const { postTweetCron } = require('../controller/twitterController');

cron.schedule('* * * * *', async () => {
  await postTweetCron();
}, {
  scheduled: true,
  timezone: "UTC"
});

This runs every minute (you can adjust it).
Behind the scenes, your Alith agent wakes up, loads your character.json, and posts a new tweet in your style.


:puzzle_piece: Environment Variables

# .env
TWITTER_USERNAME=username
TWITTER_PASSWORD=password
TWITTER_EMAIL=email

LLM_MODEL=gpt-4o-mini
ALITH_API_KEY=your_key_if_required

Install deps:

npm i alith node-cron


:test_tube: Step 4 — Manual Test

Run locally to test your setup:

curl -X POST http://localhost:3000/tweet \
  -H "Content-Type: application/json" \
  -d '{"username":"someone"}'

Start your app:

npm run dev


:repeat_button: Updating Your Twin

Want a new version of yourself?
Just regenerate your file:

npx tweets2character <path_to_new_archive.zip>

Replace your existing character.json, restart the server — and your new personality is live.


:brick: Architecture Sketch

User Tweets → tweets2character → character.json 
      ↓
  Alith Agent ← character.json (persona)
      ↓
  LLM (OpenAI/Claude)
      ↓
  tweetController.js → Twitter API


2 Likes

This is hands-down one of the coolest tutorials