Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: Telegram autonomous agent enhancement #2338

Merged

Conversation

azep-ninja
Copy link
Contributor

Relates to

PR 2335

Risks

Low risk, minimal changes to Discord client

Background

What does this PR do?

What kind of change is this?

Features (non-breaking change which adds functionality)

This feature add the ability for agents to autonomously post, monitor channel activity for "quietness", and post a message to re-engage people.

Additionally if pinned messages monitoring is enabled, the agent will watch the group specified for pinned messages, and get the community to engage and refer to the post.

Why are we doing this? Any context or related work?

Allowing an agent to work within communities is great, being an extension of teams, when necessary, to allow a fully autonomous agent.

Documentation changes needed?

N/A

Testing

Where should a reviewer start?

Detailed testing steps

Enable in character file config.
image

Than post announcements in the specified announcement channel, and agent should create its own message in the main channel provided.

Additionally watch the main channel without activity, and agent will randomly send a message to re-engage community.

image

image

Deploy Notes

N/A

Database changes

N/A

Deployment instructions

N/A

Discord username

ninja_dev

@rferrari
Copy link
Contributor

Hey @azep-ninja , tks for this update. I tested it and looks very solid. My agent start casting some messages on the determined time interval on specific group setup. Great job!

@wtfsayo
Copy link
Member

wtfsayo commented Jan 17, 2025

@coderabbitai analyse risk

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

Tip

For best results, initiate chat on the files or code changes.

@wtfsayo Based on code analysis, the risk level appears to be low due to several built-in safeguards:

  1. Rate Limiting:
  • Configurable post intervals and delays
  • Exponential backoff for retries
  • Built-in throttling mechanisms
  1. Error Handling:
  • Robust error detection and recovery
  • Graceful handling of rate limits
  • Multiple retry attempts with increasing delays
  1. Activity Monitoring:
  • Configurable monitoring intervals
  • Built-in delays between checks
  • Rate-limited channel activity scanning

The code demonstrates careful consideration of potential issues with automated posting and monitoring, implementing multiple layers of protection against spam or excessive resource usage.

(_/)
(•ᴥ•)
/づ 📝
thoughtfully analyzing the code

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Find relevant files
echo "=== Files Changed ==="
git diff --name-status HEAD~1

echo -e "\n=== Looking for rate limiting mechanisms ==="
rg -i "rate.*limit|throttle|delay|interval" -A 3 -B 3

echo -e "\n=== Looking for message posting logic ==="
rg -i "post.*message|send.*message|create.*message" -A 3 -B 3

echo -e "\n=== Looking for monitoring logic ==="
rg -i "monitor|watch|quiet|inactive" -A 3 -B 3

echo -e "\n=== Looking for error handling ==="
rg -i "catch|error|exception|try" -A 3 -B 3

Length of output: 72181

@wtfsayo wtfsayo enabled auto-merge (squash) January 17, 2025 17:33
Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

📝 Walkthrough

Walkthrough

This pull request introduces enhanced Telegram bot functionality with new auto-posting capabilities and message handling templates. The changes span multiple files in the Telegram client package, adding sophisticated features for managing channel interactions, tracking activity, and generating dynamic messages. The modifications include new configuration interfaces, methods for monitoring channel engagement, and templates for various interaction scenarios.

Changes

File Change Summary
packages/client-telegram/src/constants.ts Removed "everyone" from TEAM_COORDINATION keywords
packages/client-telegram/src/messageManager.ts Added AutoPostConfig interface and new methods for auto-posting, including _startAutoPostMonitoring and _checkChannelActivity
packages/client-telegram/src/templates.ts Introduced four new templates: telegramShouldRespondTemplate, telegramMessageHandlerTemplate, telegramAutoPostTemplate, and telegramPinnedMessageTemplate
packages/core/src/types.ts Added optional telegramAutoPostTemplate and telegramPinnedMessageTemplate properties to Character type

Finishing Touches

  • 📝 Generate Docstrings (Beta)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
packages/client-telegram/src/messageManager.ts (3)

160-161: Simplify the condition in the if statement

The condition in the if statement is unnecessarily complex and may not work as intended.

Simplify the condition:

-                if (timeSinceLastMessage > this.autoPostConfig.inactivityThreshold || randomThreshold &&
-                    timeSinceLastAutoPost > (this.autoPostConfig.minTimeBetweenPosts || 0)) {
+                if (timeSinceLastMessage > randomThreshold &&
+                    timeSinceLastAutoPost > (this.autoPostConfig.minTimeBetweenPosts || 0)) {

163-221: Enhance error handling in _checkChannelActivity

Ensure that errors during message generation and sending are properly handled to prevent the bot from crashing.

Add try-catch blocks around message generation and sending to handle potential exceptions.


961-971: Update lastChannelActivity appropriately

lastChannelActivity should be updated only when a message is processed, not at the start of handleMessage.

Move the update after processing the message to accurately reflect channel activity.

packages/core/src/types.ts (2)

749-750: Add comments for new template properties

Including comments for telegramAutoPostTemplate and telegramPinnedMessageTemplate will improve maintainability and clarity.

Apply this diff:

+            /**
+             * Template for Telegram auto-post messages
+             */
             telegramAutoPostTemplate?: string;
+            /**
+             * Template for Telegram pinned message highlights
+             */
             telegramPinnedMessageTemplate?: string;

853-860: Mark autoPost configuration properties as optional

Properties within autoPost should be optional to handle partial configurations gracefully.

Ensure optional properties are correctly typed:

                autoPost?: {
                    enabled?: boolean;
                    monitorTime?: number;
                    inactivityThreshold?: number;
                    mainChannelId?: string;
                    pinnedMessagesGroups?: string[];
                    minTimeBetweenPosts?: number;
                };
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5a28cd9 and 2718c21.

📒 Files selected for processing (4)
  • packages/client-telegram/src/constants.ts (0 hunks)
  • packages/client-telegram/src/messageManager.ts (6 hunks)
  • packages/client-telegram/src/templates.ts (1 hunks)
  • packages/core/src/types.ts (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/client-telegram/src/constants.ts
🔇 Additional comments (4)
packages/client-telegram/src/messageManager.ts (1)

82-90: Handle potential undefined mainChannelId in autoPostConfig

The mainChannelId may be undefined if not provided in the configuration. This could lead to issues when attempting to send messages. Consider adding validation or setting a default value.

packages/client-telegram/src/templates.ts (3)

3-76: Validate placeholders in telegramShouldRespondTemplate

Ensure all placeholders like {{agentName}}, {{user1}}, and {{bio}} are correctly replaced at runtime to prevent template rendering issues.


78-115: Check variable usage in telegramMessageHandlerTemplate

Confirm that all variables such as {{goals}}, {{actions}}, and {{currentPost}} are properly defined and used consistently.


116-153: Review instructions in telegramAutoPostTemplate for clarity

The instructions are detailed and extensive. Verify that they align with the desired behavior and that no unintended directives are included.

@wtfsayo wtfsayo self-requested a review January 17, 2025 17:38
wtfsayo and others added 2 commits January 17, 2025 23:18
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@wtfsayo wtfsayo merged commit 94ee57b into elizaOS:develop Jan 17, 2025
3 checks passed
@azep-ninja azep-ninja deleted the feat/telegram-agent-autonomous-enhancements branch January 18, 2025 17:36
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants