Skip to main content
Run Telegram, Discord, Slack, and other bots for weeks — bounded lock caches and agent-scoped locks keep memory stable with no extra configuration.
from praisonaiagents import Agent
from praisonai.bots import Bot

agent = Agent(name="assistant", instructions="Be helpful")
bot = Bot("telegram", agent=agent)
bot.run()
The user messages your bot channel; session locks stay bounded while the same agent handles concurrent chats.

How It Works

Quick Start

1

Simple Usage

from praisonaiagents import Agent
from praisonai.bots import Bot

agent = Agent(name="assistant", instructions="Be helpful")
bot = Bot("telegram", agent=agent)
bot.run()  # Bounded locks are active by default
Nothing extra is required — debounce, session, and run-control paths share the same bounded per-user lock cache.
2

With Configuration

from praisonaiagents import Agent
from praisonaiagents import BotConfig
from praisonai.bots import Bot

agent = Agent(name="assistant", instructions="Be helpful")
config = BotConfig(session_ttl=86400)  # Reap idle sessions after 24h

bot = Bot("telegram", agent=agent, config=config)
bot.run()

What’s Bounded by Default

ResourceDefault limitWhen it cleans up
Per-user lock cache10,000 entries, 1 hour TTLIdle, unlocked entries evict automatically
Agent locksOne per agent instanceRemoved when the agent is garbage-collected
Session historiesOpt-in via session_ttlSee Session Persistence
Recreating agents per request is safe. Agent locks no longer reuse stale id(agent) keys, so unrelated users cannot share locks or swap histories.

Operational Knobs

For mid-run cancellation and stale session cleanup, see Bot Run ControlSessionRunControl.cleanup_stale_sessions(max_age_seconds=3600) removes abandoned run-control state.

Multi-Agent Safety

Earlier releases keyed agent locks on id(agent). CPython may reuse that integer after garbage collection, so long-running gateways that recreated agents per request could silently mix up two users’ histories. Agent locks now follow agent lifetime via WeakKeyDictionary; per-user locks stay bounded even if you never call cleanup helpers.
Released in PR #1972 — Upgrade to pick up the fix. See Session Persistence → Bounded lock caches for details.

Best Practices

Create the agent once at startup — agent locks follow instance lifetime via WeakKeyDictionary, so recreating agents per request is safe but wasteful.
Default lock caches evict after 1 hour; set BotConfig(session_ttl=…) when conversations stay idle longer than your support SLA.
Call SessionRunControl.cleanup_stale_sessions on a schedule in long-lived gateways to drop abandoned run-control state.
Ensure you are on a release that includes bounded agent locks — earlier builds could mix histories when id(agent) was reused.

Session Persistence

Bot session storage and bounded lock behaviour

Messaging Bots

Platform setup, debounce, and chunking

Inbound DLQ

Persist failed messages for replay

Cross-Platform Mirror

One conversation across every channel