diff options
| author | Ben Sima <ben@bensima.com> | 2025-12-13 00:35:24 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-12-13 00:35:24 -0500 |
| commit | 4ff40843e7a6801b7785bfff7f4e9e8fff4e27d4 (patch) | |
| tree | 6b41438d0726f96746697af0584ab2f2542ffabf /Omni/Agent/Telegram.hs | |
| parent | 817bdb1f33e9825946a2da2aa1ff8f91b6166366 (diff) | |
telegram: fix parsing, add webpage reader, use gemini
- Fix Provider.hs to strip leading whitespace from OpenRouter responses
- Fix FunctionCall parser to handle missing 'arguments' field
- Use eitherDecode for better error messages on parse failures
- Switch to claude-sonnet-4.5 for main agent
- Use gemini-2.0-flash for conversation summarization (cheaper)
- Add read_webpage tool for fetching and summarizing URLs
- Add tagsoup to Haskell deps (unused, kept for future)
Diffstat (limited to 'Omni/Agent/Telegram.hs')
| -rw-r--r-- | Omni/Agent/Telegram.hs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/Omni/Agent/Telegram.hs b/Omni/Agent/Telegram.hs index d224acc..c55dc5a 100644 --- a/Omni/Agent/Telegram.hs +++ b/Omni/Agent/Telegram.hs @@ -83,6 +83,7 @@ import qualified Omni.Agent.Tools.Calendar as Calendar import qualified Omni.Agent.Tools.Notes as Notes import qualified Omni.Agent.Tools.Pdf as Pdf import qualified Omni.Agent.Tools.Todos as Todos +import qualified Omni.Agent.Tools.WebReader as WebReader import qualified Omni.Agent.Tools.WebSearch as WebSearch import qualified Omni.Test as Test import System.Environment (lookupEnv) @@ -423,6 +424,7 @@ handleAuthorizedMessage tgConfig provider engineCfg msg uid userName chatId = do searchTools = case Types.tgKagiApiKey tgConfig of Just kagiKey -> [WebSearch.webSearchTool kagiKey] Nothing -> [] + webReaderTools = [WebReader.webReaderTool (Types.tgOpenRouterApiKey tgConfig)] pdfTools = [Pdf.pdfTool] notesTools = [ Notes.noteAddTool uid, @@ -440,7 +442,7 @@ handleAuthorizedMessage tgConfig provider engineCfg msg uid userName chatId = do Todos.todoCompleteTool uid, Todos.todoDeleteTool uid ] - tools = memoryTools <> searchTools <> pdfTools <> notesTools <> calendarTools <> todoTools + tools = memoryTools <> searchTools <> webReaderTools <> pdfTools <> notesTools <> calendarTools <> todoTools let agentCfg = Engine.defaultAgentConfig @@ -472,7 +474,7 @@ handleAuthorizedMessage tgConfig provider engineCfg msg uid userName chatId = do sendMessage tgConfig chatId "hmm, i don't have a response for that" else sendMessage tgConfig chatId response - checkAndSummarize provider uid chatId + checkAndSummarize (Types.tgOpenRouterApiKey tgConfig) uid chatId putText <| "Responded to " @@ -487,8 +489,8 @@ maxConversationTokens = 4000 summarizationThreshold :: Int summarizationThreshold = 3000 -checkAndSummarize :: Provider.Provider -> Text -> Int -> IO () -checkAndSummarize provider uid chatId = do +checkAndSummarize :: Text -> Text -> Int -> IO () +checkAndSummarize openRouterKey uid chatId = do (_, currentTokens) <- Memory.getConversationContext uid chatId maxConversationTokens when (currentTokens > summarizationThreshold) <| do putText <| "Context at " <> tshow currentTokens <> " tokens, summarizing..." @@ -498,9 +500,10 @@ checkAndSummarize provider uid chatId = do [ (if Memory.cmRole m == Memory.UserRole then "User: " else "Assistant: ") <> Memory.cmContent m | m <- reverse recentMsgs ] + gemini = Provider.defaultOpenRouter openRouterKey "google/gemini-2.0-flash-001" summaryResult <- Provider.chat - provider + gemini [] [ Provider.Message Provider.System "You are a conversation summarizer. Summarize the key points, decisions, and context from this conversation in 2-3 paragraphs. Focus on information that would be useful for continuing the conversation later." Nothing Nothing, Provider.Message Provider.User ("Summarize this conversation:\n\n" <> conversationText) Nothing Nothing @@ -510,7 +513,7 @@ checkAndSummarize provider uid chatId = do Right summaryMsg -> do let summary = Provider.msgContent summaryMsg _ <- Memory.summarizeAndArchive uid chatId summary - putText "Conversation summarized and archived" + putText "Conversation summarized and archived (gemini)" checkOllama :: IO (Either Text ()) checkOllama = do @@ -610,7 +613,7 @@ startBot maybeToken = do Just key -> do let orKey = Text.pack key tgConfig = Types.defaultTelegramConfig token allowedIds kagiKey orKey - provider = Provider.defaultOpenRouter orKey "anthropic/claude-sonnet-4" + provider = Provider.defaultOpenRouter orKey "anthropic/claude-sonnet-4.5" putText <| "Allowed user IDs: " <> tshow allowedIds putText <| "Kagi search: " <> if isJust kagiKey then "enabled" else "disabled" runTelegramBot tgConfig provider |
