8000 GitHub - yiwang20/x-super-agent: Local AI agent with HTTP + Telegram channels · GitHub
[go: up one dir, main page]

Skip to content

About

Local AI agent with HTTP + Telegram channels

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

X-Super-Agent

A local multi-channel AI agent with Telegram integration, Azure OpenAI backend, and powerful local tool execution.

Features

  • Multi-channel support: Telegram (with abstract interface for Slack/Discord/HTTP)
  • Azure OpenAI: GPT-4o or other Azure OpenAI deployments
  • Tool execution:
    • exec - Execute shell commands (git, npm, python, curl, etc.)
    • read - Read files and directories
    • write - Write/create files
    • http - Make HTTP requests
  • Security controls: Directory whitelists, command blacklists, domain restrictions
  • Conversation memory: Per-user conversation history

Quick Start

  1. Clone and install:
npm install
  1. Copy and configure environment:
cp .env.example .env
# Edit .env with your credentials
  1. Build and run:
npm run build
npm start

Or for development:

npm run dev

Configuration

Required Environment Variables

Variable Description
AZURE_OPENAI_API_KEY Your Azure OpenAI API key
AZURE_OPENAI_ENDPOINT Azure OpenAI endpoint URL
TELEGRAM_BOT_TOKEN Telegram bot token from @BotFather

Optional Environment Variables

Variable Description Default
AZURE_OPENAI_DEPLOYMENT Model deployment name gpt-4o
AZURE_OPENAI_API_VERSION API version 2024-02-15-preview
TELEGRAM_ALLOWED_USERS Comma-separated user IDs (allow all)
ALLOWED_DIRECTORIES Allowed paths for file ops $HOME,/tmp,cwd
BLOCKED_COMMANDS Blocked command patterns (dangerous only)
ALLOWED_HTTP_DOMAINS Allowed domains for HTTP (all)
MAX_FILE_SIZE Max file size in bytes 10485760

Usage

Telegram Commands

  • Send any message to interact with the agent
  • /clear - Clear conversation history

Example Interactions

You: List files in current directory
Agent: [Uses exec tool: ls -la]
       Here are the files...

You: Read the package.json file
Agent: [Uses read tool]
       The package.json contains...

You: Create a hello.txt file with "Hello World"
Agent: [Uses write tool]
       Created hello.txt...

You: Make a GET request to httpbin.org/ip
Agent: [Uses http tool]
       Your IP is...

Running as a Service

Using PM2

npm run build
npm run pm2:start

# Other PM2 commands
npm run pm2:stop
npm run pm2:restart
npm run pm2:logs

Using systemd

Create /etc/systemd/system/x-super-agent.service:

[Unit]
Description=X-Super-Agent
After=network.target

[Service]
Type=simple
User=your-user
WorkingDirectory=/path/to/x-super-agent
ExecStart=/usr/bin/node dist/index.js
Restart=on-failure
EnvironmentFile=/path/to/x-super-agent/.env

[Install]
WantedBy=multi-user.target

Security Notes

  • By default, security restrictions are relaxed to allow most operations
  • Configure TELEGRAM_ALLOWED_USERS to restrict bot access
  • Configure ALLOWED_DIRECTORIES to limit file operations
  • Configure BLOCKED_COMMANDS to prevent dangerous commands
  • The agent can execute most shell commands - use with care

Architecture

src/
├── core/
│   ├── types.ts    # Type definitions
│   ├── llm.ts      # Azure OpenAI client
│   └── agent.ts    # Agent loop implementation
├── tools/
│   ├── index.ts    # Tool registry
│   ├── exec.ts     # Shell command execution
│   ├── read.ts     # File reading
│   ├── write.ts    # File writing
│   ├── http.ts     # HTTP requests
│   └── security.ts # Security configuration
├── channels/
│   ├── base.ts     # Abstract channel interface
│   ├── telegram.ts # Telegram implementation
│   └── index.ts    # Channel exports
└── index.ts        # Entry point

Adding New Channels

Implement the BaseChannel abstract class:

import { BaseChannel } from './base';

export class MyChannel extends BaseChannel {
  name = 'my-channel';

  async start(): Promise<void> {
    // Initialize and start listening
  }

  async stop(): Promise<void> {
    // Cleanup
  }
}

License

MIT

About

Local AI agent with HTTP + Telegram channels

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0