Create Telegram Bot agent - the first concrete agent that validates the infrastructure.
This is the first agent built on top of the shared infrastructure (Provider, Memory, Registry). It serves as a family assistant accessible via Telegram, demonstrating cross-agent memory sharing.
-- Omni/Agent/Telegram.hs
data TelegramConfig = TelegramConfig
{ tgBotToken :: Text
, tgPollingTimeout :: Int -- seconds, default 30
}
data TelegramMessage = TelegramMessage
{ tmUpdateId :: Int
, tmChatId :: Int64
, tmUserId :: Int64
, tmUserName :: Maybe Text
, tmText :: Text
}
-- Poll for new messages
getUpdates :: TelegramConfig -> Int -> IO [TelegramMessage]
-- Send reply
sendMessage :: TelegramConfig -> Int64 -> Text -> IO ()
runTelegramBot :: TelegramConfig -> EngineConfig -> IO ()
runTelegramBot tgConfig engineConfig = do
-- Poll loop
forever do
messages <- getUpdates tgConfig lastUpdateId
for_ messages handleMessage
handleMessage :: TelegramMessage -> IO ()
handleMessage msg = do
-- Get or create user
user <- Memory.getOrCreateUserByTelegramId (tmUserId msg) (fromMaybe "Unknown" (tmUserName msg))
-- Recall relevant memories
memories <- Memory.recallMemories (userId user) (tmText msg) 10
-- Build agent config with memory context
let systemPrompt = telegramSystemPrompt <> formatMemories memories
agentConfig = AgentConfig
{ agentTools = Registry.telegramTools -- [remember, recall, web_search]
, agentSystemPrompt = systemPrompt
, agentMaxIterations = 5
, ...
}
-- Run agent
result <- Engine.runAgent engineConfig agentConfig (tmText msg)
-- Send response
sendMessage tgConfig (tmChatId msg) (resultFinalMessage result)
You are a helpful family assistant on Telegram. You help with questions,
remember important information about family members, and provide friendly assistance.
When you learn something important about the user (preferences, facts about them,
their interests), use the 'remember' tool to store it for future reference.
Be concise in responses - Telegram is a chat interface, not a document.
Be friendly and helpful. This is a family bot, keep content appropriate.
jr telegram [--token=TOKEN] Start Telegram bot (uses TELEGRAM_BOT_TOKEN env if not provided)
User: Hi, I'm Ben and I work as an AI engineer Bot: Nice to meet you, Ben! I've noted that you're an AI engineer. How can I help you today? [remember tool called: 'Ben works as an AI engineer']
User: What papers should I read? Bot: Since you're an AI engineer, you might be interested in... [recall tool found: 'Ben works as an AI engineer']