Agent Messaging Guide
How to send and receive messages between AILANG core and external projects using the unified messaging system.
Quick Reference
# List all messages
ailang messages list
# Show only unread messages
ailang messages list --unread
# Read full message content
ailang messages read MSG_ID
# Acknowledge (mark as read)
ailang messages ack MSG_ID
ailang messages ack --all
# Send a message
ailang messages send user "Your message" --title "Title" --from "agent-name"
# Send with GitHub sync
ailang messages send user "Bug report" --title "Parser crash" --type bug --github
# Semantic search
ailang messages search "parser error"
ailang messages search "bugs" --neural # Uses Ollama embeddings
# Find duplicates
ailang messages dedupe
ailang messages dedupe --apply # Mark duplicates
Storage Backend
All messages are stored in a SQLite database:
- Location:
~/.ailang/state/collaboration.db - Accessible via: CLI (
ailang messages) and Collaboration Hub dashboard - Message statuses:
unread,read,archived,deleted
Message Format
Messages in the system contain:
{
"id": "uuid",
"message_id": "msg_20251210_123456_abc123",
"from_agent": "agent-name",
"to_inbox": "user",
"message_type": "notification",
"title": "Brief title",
"payload": "Detailed message content",
"category": "bug|feature|general",
"github_issue": 42,
"github_repo": "owner/repo",
"simhash": 1234567890123456789,
"dup_of": "original_message_id",
"embedding": "[0.123, 0.456, ...]",
"embedding_model": "ollama:nomic-embed-text",
"status": "unread",
"created_at": "2025-12-10T12:34:56Z"
}
Semantic Search Fields (v0.5.11+)
| Field | Description |
|---|---|
simhash | 64-bit locality-sensitive hash for fast similarity |
dup_of | Message ID this is a duplicate of (set by dedupe) |
embedding | JSON-encoded float32 vector (neural search) |
embedding_model | Model used to generate embedding (e.g., "ollama:nomic-embed-text") |
Architecture
External Project AILANG Core
| |
| ailang messages send user "msg" |
|------------------------------------>|
| -> collaboration.db |
| |
| (Optional) --github flag |
|------------------------------------>|
| -> GitHub Issue created |
| |
|<------------------------------------|
| ailang messages send proj "..." |
| -> collaboration.db |
Workflows
Responding to Bug Reports
- Check inbox:
ailang messages list --unread - Read full message:
ailang messages read MSG_ID - Create design doc if needed
- Send acknowledgment:
ailang messages send PROJECT_NAME "Bug acknowledged - design doc created for vX.Y.Z" \
--title "Bug acknowledged" --from "ailang" - Acknowledge original:
ailang messages ack MSG_ID
Sending to GitHub Issues
Use the --github flag to also create a GitHub issue:
# Report a bug (creates GitHub issue with "bug" label)
ailang messages send user "Parser crashes on nested records" \
--title "Parser crash bug" --type bug --github
# Request a feature
ailang messages send user "Add async/await syntax" \
--title "Async support" --type feature --github
# The message is ALWAYS saved locally first
# GitHub sync is optional and fails gracefully
CLI Commands
List Messages
ailang messages list # All messages
ailang messages list --unread # Only unread
ailang messages list --inbox user # Filter by inbox
ailang messages list --from agent-name # Filter by sender
ailang messages list --json # JSON output
ailang messages list --limit 50 # Limit results
Read Message Content
ailang messages read MSG_ID # Full content, marks as read
ailang messages read MSG_ID --peek # View without marking read
ailang messages read MSG_ID --json # JSON output
Acknowledge Messages
ailang messages ack MSG_ID # Mark specific message as read
ailang messages ack --all # Mark all as read
ailang messages ack --all --inbox user # Mark all in inbox as read
Un-acknowledge (Mark Unread)
ailang messages unack MSG_ID # Move back to unread
Send Messages
# Basic send
ailang messages send INBOX "message content" --title "Title" --from "agent"
# With GitHub sync
ailang messages send INBOX "message" --type bug --github
ailang messages send INBOX "message" --type feature --github
ailang messages send INBOX "message" --github --repo owner/repo
Reply to GitHub Issues
Add comments to existing GitHub issue threads:
# Reply to a message that has a linked GitHub issue
ailang messages reply MSG_ID "Fixed in v0.5.10" --from "claude-code"
# Reply with explicit repo override
ailang messages reply MSG_ID "Working on it" --repo owner/repo
The reply command only works for messages created with --github flag. It adds a comment to the same issue thread, keeping the conversation together.
Import from GitHub
ailang messages import-github # Import from default repo
ailang messages import-github --repo owner/repo # Specific repo
ailang messages import-github --labels bug,help # Filter by labels
ailang messages import-github --dry-run # Preview without importing
Cleanup Old Messages
ailang messages cleanup --older-than 7d # Remove messages older than 7 days
ailang messages cleanup --expired # Remove expired messages
ailang messages cleanup --dry-run # Preview without deleting
Watch for New Messages
ailang messages watch # Watch all inboxes
ailang messages watch --inbox user # Watch specific inbox
GitHub Integration
Configuration
Create ~/.ailang/config.yaml:
github:
expected_user: YourGitHubUsername # REQUIRED: Must match gh auth status
default_repo: owner/repo # Default repo for issues
create_labels: # Labels added to created issues
- ailang-message
watch_labels: # Labels to filter when importing
- ailang-message
auto_import: true # Auto-import on session start
How It Works
-
Account Validation: The
expected_usermust match the activeghaccount- Run
gh auth statusto check current account - Switch accounts with
gh auth switch --user USERNAME - This prevents accidentally creating issues in wrong repos
- Run
-
Auto-Label Creation: Labels are automatically created if they don't exist
from:agent-name(purple) - who sent the messagebug(red),feature(cyan),general(light blue)ailang-message(blue) - identifies AILANG messages
-
Title Prefix: Issues are prefixed with sender name
[agent-name] Original Title
-
Issue Linking: Created issue number is saved to database
- Query with:
SELECT * FROM inbox_messages WHERE github_issue_number IS NOT NULL
- Query with:
Workflow
# 1. Check GitHub auth
gh auth status
# 2. Switch account if needed
gh auth switch --user YourUsername
# 3. Send message with GitHub sync
ailang messages send user "Bug: parser crashes" --type bug --github
# 4. Import issues from GitHub on session start (automatic via hook)
ailang messages import-github
Integration with Claude Code
The SessionStart hook (scripts/hooks/session_start.sh) automatically:
- Imports GitHub issues as messages (respects
auto_importconfig) - Checks for unread messages
- Injects message summary into system reminders
Messages appear at session start. After handling:
ailang messages ack <message-id> # Acknowledge specific message
ailang messages ack --all # Acknowledge all messages
Message Types and Routing
| Type | Purpose | Goes to GitHub? |
|---|---|---|
bug | Bug report | Yes (with --github) |
feature | Feature request | Yes (with --github) |
general | General communication | No (local only) |
Routing guidance:
- Bugs and features → Use
--githubfor visibility across all AILANG instances - Coordination messages → Local only, for agent-to-agent communication
- Instructions from humans → Create GitHub issues, they'll be imported automatically
Bi-directional GitHub Sync
The messaging system supports two-way sync with GitHub:
Sending to GitHub (Agent → GitHub)
# Bug reports and feature requests go to GitHub for visibility
ailang messages send user "Parser crash" --type bug --github
Importing from GitHub (GitHub → Local)
# Import issues from GitHub (runs automatically on session start)
ailang messages import-github
# Or manually with filters
ailang messages import-github --labels help-wanted
Use case: Human instructions via GitHub
You can write instructions as GitHub issues and have agents pick them up:
- Create issue on GitHub with
ailang-messagelabel - Next session,
import-githubruns automatically - Issue appears in agent's inbox as a message
- Agent reads and acts on the instructions
Semantic Search
Find messages by meaning, not just exact text matches. AILANG uses SimHash (locality-sensitive hashing) for fast, zero-cost semantic search.
Search Commands
# Search for messages by semantic content
ailang messages search "parser error handling"
ailang messages search "type inference bugs" --threshold 0.5
# Find messages similar to a specific message
ailang messages list --similar-to MSG_ID --threshold 0.70
# Hide duplicate messages (collapsed view)
ailang messages list --collapsed
# Show only duplicates of a specific message
ailang messages list --duplicates-of MSG_ID
Search Flags
| Flag | Default | Description |
|---|---|---|
--threshold | 0.70 | Minimum similarity (0.0-1.0) |
--limit | 20 | Maximum results |
--max-scan | 1000 | Maximum messages to scan |
--inbox | (all) | Filter by inbox |
--neural | false | Use neural embeddings (requires Ollama) |
--simhash | true | Force SimHash mode (default, fast) |
--json | false | Output as JSON |
How SimHash Works
SimHash generates a 64-bit fingerprint for each message based on word frequencies. Similar messages have similar fingerprints, allowing fast similarity comparison using Hamming distance:
- Score 1.0: Identical or near-identical messages
- Score 0.9+: Very similar (likely duplicates)
- Score 0.7-0.9: Related topics
- Score below 0.7: Different content
Benefits:
- ✅ Zero API costs (runs locally)
- ✅ Fast (O(1) comparison)
- ✅ Deterministic (same input → same output)
- ✅ Works offline
Deduplication
Find and mark duplicate messages to reduce inbox noise.
Dedupe Commands
# Report duplicates (dry run)
ailang messages dedupe
# Report with custom threshold
ailang messages dedupe --threshold 0.90
# Actually mark duplicates
ailang messages dedupe --apply
# Filter by inbox
ailang messages dedupe --inbox user --apply
How Deduplication Works
- Find groups: Messages with similarity ≥ threshold are grouped
- Select representative: Oldest message in each group is kept
- Mark duplicates: Newer messages get
dup_ofset to representative's ID - View behavior:
--collapsedhides messages withdup_ofset
Dedupe Report
Duplicate Report
Found 3 duplicate groups (7 messages)
Group 1 (95% similar, 2 duplicates):
* Keep: msg_20251210_123456_abc123
Parser crashes on nested records
- Archive: msg_20251210_134500_def456
Parser crash with nested records
- Archive: msg_20251210_145600_ghi789
Nested record parser crash
Neural Embeddings (Ollama)
For more sophisticated semantic search, use neural embeddings via local Ollama.
Prerequisites
- Install Ollama: https://ollama.ai
- Start Ollama server:
ollama serve - Pull an embedding model:
ollama pull nomic-embed-text # Fast, good quality
ollama pull embeddinggemma # Google's embedding model
ollama pull mxbai-embed-large # High quality, slower
Configuration
Create or update ~/.ailang/config.yaml:
embeddings:
# Provider: "ollama" (local) or "none" (SimHash only)
provider: ollama
ollama:
# Model name - see 'ollama list' for available models
model: nomic-embed-text
# Ollama API endpoint
endpoint: http://localhost:11434
# Request timeout
timeout: 30s
search:
# Default search mode: "simhash" (fast) or "neural" (semantic)
default_mode: simhash
# Similarity thresholds (0.0-1.0)
simhash_threshold: 0.70
neural_threshold: 0.75
Environment Variables
Override config with environment variables:
# Provider
export AILANG_EMBED_PROVIDER=ollama
# Model
export AILANG_OLLAMA_MODEL=nomic-embed-text
# Endpoint
export AILANG_OLLAMA_ENDPOINT=http://localhost:11434
Using Neural Search
# Require Ollama to be running
ailang messages search "parser bugs" --neural
# Compare: SimHash (default, fast)
ailang messages search "parser bugs" --simhash
How Neural Search Works
- Query embedding: Your search query is converted to a vector
- Lazy embedding: Messages without embeddings are embedded on-demand (up to 50 per search)
- Cosine similarity: Vectors are compared using cosine similarity
- Cached: Embeddings are stored in the database for reuse
Benefits:
- ✅ Understands semantic meaning ("error" matches "bug", "crash", "failure")
- ✅ Cross-lingual potential (with multilingual models)
- ✅ Better for conceptual search
Trade-offs:
- ⚠️ Requires Ollama running locally
- ⚠️ First search embeds messages (slower startup)
- ⚠️ Uses more storage (768+ floats per message)
Model Recommendations
| Model | Dimension | Speed | Quality | Use Case |
|---|---|---|---|---|
nomic-embed-text | 768 | Fast | Good | General purpose |
mxbai-embed-large | 1024 | Medium | Better | High accuracy needs |
embeddinggemma | 768 | Fast | Good | Google model |
all-minilm | 384 | Very Fast | OK | Quick searches |
Checking Ollama Status
# Check if Ollama is running
curl http://localhost:11434/api/tags
# List available models
ollama list
# Pull a model
ollama pull nomic-embed-text
Aliases
The messages command has an alias for convenience:
ailang msg list # Same as: ailang messages list
ailang msg send ... # Same as: ailang messages send ...
See Also
- Semantic Caching vs Vector DBs - When to use semantic caching
- Cross-Project Messaging - Send feedback from your projects
- Agent Workflows - Automated agent workflows
- State System - Persistent state management