This release is a pre-release and may not be stable for production use.
Your Digital Companion. Self-hosted Telegram bot orchestrating multiple AI providers (OpenAI, Anthropic, Google, xAI, DeepSeek, Mistral, Alibaba, MiniMax) with autonomous agent capabilities, MCP integrations, and async task execution. Not a tool. A partner.
pip install chibi-bot==1.22.0.dev202611180950 Copy PIP instructions
Your Digital Companion. Not a Tool. A Partner. Self-hosted, asynchronous Telegram bot that orchestrates multiple AI providers, tools, and sub-agents to get real work done.
🌍 Read this in other languages: Español • Português (Brasil) • Українська • Bahasa Indonesia • Türkçe • Русский • 日本語 • 繁體中文 • 简体中文
Chibi is built for the moment you realize you need more than “an AI tool.” You need a partner that can coordinate models, run work in the background, and integrate with your systems - without you babysitting prompts.
Chibi is an asynchronous, self-hosted Telegram-based digital companion that orchestrates multiple AI providers and tools to deliver outcomes: code changes, research syntheses, media generation, and operational tasks.
Chibi supports multiple providers behind a single conversation. Add one key or many - Chibi can route per task.
Exact model availability depends on your configured provider keys and enabled features.
Install Chibi via pip and run it as a command-line application:
# Install the package pip install chibi-bot # Set up the agent (add API keys, update settings, etc) chibi config # Start the bot chibi start The bot will run as a background service. Use CLI commands to manage it.
Chibi can serve its local clients over the versioned local JSONL protocol:
chibi stdio --tui chibi stdio --vscode chibi stdio --pycharm chibi stdio --neovim The command is intended to be started by the client frontend, not used interactively. Chibi owns the v1 protocol and supports compatible clients that negotiate the same version. The stdio process writes protocol frames only to stdout and diagnostics to stderr. Existing Chibi command, tool, permission and moderation behavior remains authoritative; the client adds no tool policy layer.
version: '3.8' services: chibi: image: pysergio/chibi:latest restart: unless-stopped environment: TELEGRAM_BOT_TOKEN: ${TELEGRAM_BOT_TOKEN} # Required OPENAI_API_KEY: ${OPENAI_API_KEY} # Or any other provider # Add more API keys as needed volumes: - chibi_data:/app/data volumes: chibi_data: {} Get a bot token from @BotFather
Each provider requires its own API key. Here are the direct links:
📖 Full guide with setup instructions: chibi.bot/guides/get-api-keys
Ask me 3 questions to clarify my goal, then propose a plan and execute step 1.
Spawn 3 sub-agents: one to research options, one to draft a recommendation, one to list risks. Return a single decision.
Inspect the project files and summarize what this repo does. Then propose 5 improvements and open a checklist.
Start a background task: gather sources on X and deliver a synthesis in 30 minutes. Keep me updated.
Chibi can keep context while switching providers mid-thread, or choose the best model per step - balancing cost, capability, and speed.
Connect Chibi to external tools and services (or build your own):
If a tool can be exposed via MCP, Chibi can learn to use it.
You: “Run the tests and fix what’s broken. I’ll work on the frontend.” Chibi: *spawns sub-agent, executes tests, analyzes failures, proposes fixes* Researchers
You: “Research the latest developments in quantum computing. I need a synthesis by tomorrow.” Chibi: *spawns multiple research agents, aggregates sources, delivers a report* Creators
You: “Generate a cyberpunk cityscape and compose a synthwave track to match.” Chibi: *generates an image, creates music, delivers both* Teams
You: “Review this PR and update the documentation accordingly.” Chibi: *analyzes changes, suggests improvements, updates docs via MCP* Privacy, control, and safety Self-hosted: your data stays on your infrastructure Public Mode: users can bring their own API keys (no shared master key required) Access control: whitelist users/groups/models Storage options: local volumes or Redis Tool safety: agent tools are configurable; terminal execution is moderated and can be restricted MAX_HISTORY_TOKENS — context summarization threshold (breaking default change) MAX_HISTORY_TOKENS is the threshold at which Chibi auto-summarizes a conversation to keep context manageable. Its semantics changed: it now compares against the real, provider-reported prompt token count (the entire outgoing request: system prompt + activated skills + tool schemas + tool-call arguments + per-message structural overhead + conversation content) instead of the old heuristic that measured only conversation content + role. The real figure is ~4.8x larger than the old estimate for an identical conversation (see fix_context_size/context_size_accounting_analysis.md for the measured breakdown).
REACTIVE_CONTEXT_RECOVERY (default: true) is the reactive safety net that complements the proactive MAX_HISTORY_TOKENS threshold. When a provider rejects a request with a typed context_length_exceeded error, Chibi automatically summarizes the conversation history and retries the turn exactly once. If the retry succeeds, the user receives a normal answer (with a short note that context was compressed). If the retry overflows again or recovery fails for any reason, the turn falls back to the existing apology path — the summarization+retry loop can never run more than once per original turn. Set to false to disable reactive recovery and keep the pre-existing behavior (log + apology, no retry).
CONTEXT_FORCED_COMPACTION_ENABLED (default: true) enables the post-answer forced-compaction check: after every delivered answer, the thread's context is re-measured in the background and, once it has reached the point where the configured history limit MAX_HISTORY_TOKENS is reached (capped by the model's context window where it is known, so the threshold is never above the physical window), the conversation is unconditionally compacted — the stored history is replaced by a seed whose summary message opens with a [SYSTEM] Context was forcibly compacted marker, followed by a detailed summary, a "Current work in progress" section and a "Background tasks" section. The check is fire-and-forget: it never delays, breaks or alters the delivered answer, and it never runs for sub-agent threads. After a failed attempt the thread backs off for three delivered turns or thirty minutes, whichever comes first. Set to false to disable the automatic check; the agent's own compaction tools (summarize_history, clear_tool_call_history), the trim guard and REACTIVE_CONTEXT_RECOVERY stay in place. The full lifecycle of all compaction layers is described in docs/context-compaction.md.
The agent's working directory - used for terminal commands and reported to the model as its current CWD - is thread-scoped, mirroring how the selected LLM model is bound per thread.
On corporate networks with TLS-inspecting (MITM) proxies, long single-shot LLM requests (30–120 s with no visible traffic) can be killed as "idle" — you see ConnectionResetError / WinError 64 in the logs or a generic connection error in the chat. Chibi automatically retries such failures 4 times with growing waits (~30 s → 180 s) on every provider family and, if all retries fail, reports a clear "connection was interrupted" message instead of a generic error. If the problem persists, set HTTPS_PROXY to your corporate proxy (if it whitelists the AI API hosts) or ask IT to whitelist the provider hosts (api.openai.com, api.anthropic.com, *.googleapis.com, api.mistral.ai).
A note on Gemini specifically: the google-genai SDK silently switches its async transport to aiohttp whenever aiohttp happens to be importable in the environment. In a Chibi install that is always the case — aiohttp arrives as a hard dependency via two independent chains (dashscope, and chromadb → kubernetes), so the issue is not dashscope-only. The bare aiohttp session has no MITM-aware proxy/transport handling, and its keep-alive connections get killed by TLS-inspecting proxies with raw aiohttp.client_exceptions.ServerDisconnectedError tracebacks. Chibi now forces all Gemini async traffic onto its MITM-aware httpx2 client (a maintained httpx fork, injected via client-level HttpOptions(httpx_async_client=...) on every google.genai.Client construction), so Gemini connections go through the same proxy-aware, retrying transport as the other providers.
Chibi can automatically - or manually, if you prefer - fall back to another provider when an LLM request fails on rate limits, server errors, timeouts or network failures (context overflow and moderation errors are deliberately not failover triggers: they have their own recovery paths).
Two environment variables control the behaviour, independently for the main chat and for sub-agent requests:
FAILOVER_CHAIN_MASTER=auto FAILOVER_CHAIN_SUBAGENT=openai/gpt-4o,anthropic/claude-sonnet-4 The pair grammar splits on the first slash only - providers never contain slashes, while model names may (e.g. google/gemini-3.5-flash-lite). Validation is non-fatal by design: every invalid entry (empty, missing slash, empty provider/model part, duplicate pair) produces a clear warning and is skipped - a malformed chain never prevents Chibi from starting.
Within a single request no (provider, model) pair is ever retried, and a provider whose model list could not be enumerated is skipped as a same-model candidate but remains a default-model candidate.
An ordered chain of provider/model pairs fully replaces the auto ladder for that role. The head of the chain is the primary; the cooldown never blocks a manual chain (explicit user choice).
Every fallback attempt is announced - an in-chat warning for master requests, a log warning for sub-agent requests - and the final failure, when it comes, is always reported honestly.
Please read CONTRIBUTING.md before submitting.
Ready to meet your digital companion? Get Started →
telegram bot ai agent llm mcp openai anthropic deepseek gemini ollama asyncio minimax self-hosted
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




