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.
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.
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.
Prerequisites
You’ll need:
-
macOS / WSL / Linux with Node.js 18+
-
An OpenAI or Anthropic (Claude) API key
-
Your Twitter/X archive (.zip)
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
Step 1 — Generate Your Characterfile
This step turns your tweet history into a Digital Twin.
-
Request your archive
From X/Twitter → Settings → Download an archive. -
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.jsonin your current directory
-
-
Place it in your project root
/Digital-Twin-Starter-kit ├─ controller/ ├─ services/ ├─ routes/ ├─ character.json ← here └─ index.js
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:
Load character.json
Generate a tweet in your tone
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.
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.
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
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
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.
Architecture Sketch
User Tweets → tweets2character → character.json
↓
Alith Agent ← character.json (persona)
↓
LLM (OpenAI/Claude)
↓
tweetController.js → Twitter API