You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A simple Telegram bot that uses the [OpenAI Agents SDK](https://github.com/openai/openai-agents-python) to interact with [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers.
3
+
A Telegram bot powered by [agent-core](https://github.com/John-Lin/agent-core) that interacts with [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) servers. Supports two interchangeable providers:
4
4
5
-
See also: [agentic-slackbot](https://github.com/John-Lin/agentic-slackbot) — a similar demo bot for Slack.
5
+
-**OpenAI** (default) — via [OpenAI Agents SDK](https://github.com/openai/openai-agents-python); works with OpenAI and Azure OpenAI v1.
6
+
-**Claude** — via [claude-agent-sdk](https://pypi.org/project/claude-agent-sdk/).
7
+
8
+
Switch providers by setting `"provider"` in `agent_config.json`.
9
+
10
+
See also: [agentic-slackbot](https://github.com/John-Lin/agentic-slackbot) and [agentic-discord-bot](https://github.com/John-Lin/agentic-discord-bot) — similar bots for Slack and Discord.
- Connects to any MCP server via `servers_config.json`
12
-
- Supports OpenAI, Azure OpenAI endpoints
13
16
- Per-conversation history with automatic truncation
14
17
- Group reply chain — after `@mention`, anyone can continue by replying
15
-
- Optional local shell via `ShellTool`, controlled by `SHELL_ENABLED` and `SHELL_SKILLS_DIR`
18
+
- Connects to any MCP server via `agent_config.json`
19
+
- Optional local shell: `ShellTool` (OpenAI, via `provider.shell`) or `Bash`/`Write`/`Edit`/… (Claude, via `provider.allowedTools`). Read-only built-ins (`Read`, `Glob`, `Grep`) are always on for Claude.
20
+
- Supports OpenAI, Azure OpenAI v1, and Anthropic Claude
16
21
17
22
## Install Dependencies
18
23
@@ -28,87 +33,129 @@ uv sync
28
33
- Use the command `/setprivacy` in the BotFather chat.
29
34
- Select your bot.
30
35
- Choose "Disable" to allow the bot to receive all messages in groups.
31
-
4. Set the bot token and username in the `.envrc` or `.env` file.
36
+
4. Set the bot token and username in the `.env` file.
32
37
33
38
## Environment Variables
34
39
35
-
Create a `.envrc` or `.env` file in the root directory:
40
+
Create a `.env` file in the root directory. Set the key(s) for the provider you plan to use:
36
41
37
42
```
38
43
# Telegram bot
39
-
export BOT_USERNAME="@your_bot_username"
40
-
export TELEGRAM_BOT_TOKEN=""
44
+
BOT_USERNAME="@your_bot_username"
45
+
TELEGRAM_BOT_TOKEN=""
41
46
42
-
# OpenAI API
43
-
export OPENAI_API_KEY=""
47
+
# OpenAI provider (default)
48
+
OPENAI_API_KEY=""
44
49
45
-
# Local shell (disabled by default)
46
-
# export SHELL_ENABLED=1
47
-
# export SHELL_SKILLS_DIR="./skills" # optional; mount skills alongside the shell
50
+
# Claude provider
51
+
# ANTHROPIC_API_KEY=""
48
52
49
-
# Optional verbose OpenAI Agents SDK logging
50
-
# export AGENT_VERBOSE_LOG=1
51
-
```
53
+
# Optional: override SQLite path for session storage (in-memory by default)
54
+
# SESSION_DB_PATH="./sessions.db"
52
55
53
-
## Agent Instructions
56
+
# Optional: override the path to the instructions file (default ./instructions.md)
57
+
# AGENT_INSTRUCTIONS_PATH="./instructions.md"
54
58
55
-
The bot loads its system prompt from `instructions.md` in the project root.
56
-
If the file is missing, the bot fails fast at startup.
An example is provided in `instructions.md.example`. The bot will fail to start if this file is missing.
83
+
84
+
## Provider & MCP Server Configuration (Optional)
85
+
86
+
Create an `agent_config.json` to choose a provider and connect MCP servers. If the file is absent, the bot starts with the default OpenAI provider and no tools.
87
+
88
+
`provider` is a tagged union keyed by `type` (`"openai"` or `"anthropic"`). `mcp` uses an opencode-style schema keyed by server name, with `type: "local" | "remote"`.
72
89
73
-
Create a `servers_config.json` file to add your MCP servers. If this file is not provided, the bot starts with no MCP servers configured.
90
+
### OpenAI provider (default)
74
91
75
92
```json
76
93
{
77
-
"model": "gpt-5.4",
78
-
"mcpServers": {
94
+
"provider": {
95
+
"type": "openai",
96
+
"model": "gpt-5.4",
97
+
"apiType": "responses",
98
+
"historyTurns": 10
99
+
},
100
+
"mcp": {
79
101
"my-server": {
80
-
"command": "uvx",
81
-
"args": ["my-mcp-server"]
102
+
"type": "local",
103
+
"command": ["uvx", "my-mcp-server"]
82
104
}
83
105
}
84
106
}
85
107
```
86
108
87
-
`model` is optional and defaults to `gpt-5.4`. Each MCP server also accepts `timeout` (seconds, default `30.0`) and `enabled` (default `true`).
109
+
All `provider` fields are optional (`model` defaults to `gpt-5.4`, `apiType` to `"responses"`, `historyTurns` to `10`). Each MCP entry also accepts `timeout` (seconds, default `30.0`) and `enabled` (default `true`).
88
110
89
-
For HTTP-based MCP servers (Streamable HTTP), use `url`:
111
+
### Claude provider
90
112
91
113
```json
92
114
{
93
-
"mcpServers": {
115
+
"provider": {
116
+
"type": "anthropic",
117
+
"model": "claude-sonnet-4-6",
118
+
"allowedTools": ["WebFetch"]
119
+
},
120
+
"mcp": {
121
+
"my-stdio": {
122
+
"type": "local",
123
+
"command": ["python", "-m", "srv"],
124
+
"environment": {"FOO": "bar"}
125
+
},
126
+
"my-http": {
127
+
"type": "remote",
128
+
"url": "https://example.com/mcp",
129
+
"headers": {"Authorization": "Bearer x"}
130
+
}
131
+
}
132
+
}
133
+
```
134
+
135
+
Requires `ANTHROPIC_API_KEY`. Read-only built-ins (`Read`, `Glob`, `Grep`) are always on; `allowedTools` extends that set with any tool that can mutate files or run commands (`Bash`, `Write`, `Edit`, `WebFetch`, …). Tool names are case-sensitive and validated by the SDK — an unrecognized name is silently dropped. Billing/rate-limit/`error_max_turns` errors are surfaced to the chat as a readable message via `AgentError`.
@@ -178,26 +225,48 @@ uv run bot access group remove <GROUP_ID>
178
225
179
226
Group members do not need to pair individually — access is controlled at the group level.
180
227
228
+
## Conversation History
229
+
230
+
Each chat maintains its own conversation history. Replying to the bot's message continues the same conversation via the group reply chain.
231
+
232
+
OpenAI history length is controlled by `provider.historyTurns` in `agent_config.json` (default `10`). Claude history is managed on disk by `claude-agent-sdk` and resumed across restarts via a `chat_id -> session_id` mapping in SQLite (`SESSION_DB_PATH`).
233
+
181
234
## Local Shell (Optional)
182
235
183
-
The bot can expose a local `ShellTool`. This is **disabled by default**. Enable it with:
236
+
Local shell tools are **disabled by default** and are configured in `agent_config.json` per provider.
184
237
185
-
```
186
-
export SHELL_ENABLED=1
238
+
### OpenAI — `provider.shell`
239
+
240
+
```json
241
+
{
242
+
"provider": {
243
+
"type": "openai",
244
+
"shell": {
245
+
"enabled": true,
246
+
"skillsDir": "./skills"
247
+
}
248
+
}
249
+
}
187
250
```
188
251
189
-
With just `SHELL_ENABLED=1`, the agent gets bare local shell access with no pre-defined skills.
252
+
`provider.shell.enabled` must be a bool (strings are rejected). `provider.shell.skillsDir` is optional and mounts a skills directory alongside the `ShellTool`.
190
253
191
-
### Shell Skills (Optional)
254
+
### Claude — `provider.allowedTools`
192
255
193
-
You can optionally mount a skills directory alongside the shell. Each immediate subdirectory containing a `SKILL.md` file is registered as a skill and exposed to the agent as a hint (skills are advisory metadata — they do **not** sandbox command execution).
256
+
Read-only built-ins (`Read`, `Glob`, `Grep`) are always on. Add mutating or exec-capable tools explicitly:
`SHELL_SKILLS_DIR` is ignored unless `SHELL_ENABLED` is set. If the directory is missing or contains no valid skills, the bot falls back to a bare shell and logs a warning.
267
+
### Shell Skills (OpenAI only)
268
+
269
+
Each immediate subdirectory of `skillsDir` containing a `SKILL.md` file is registered as a skill and exposed to the agent as a hint (skills are advisory metadata — they do **not** sandbox command execution). If the directory is missing or contains no valid skills, the bot falls back to a bare shell and logs a warning.
201
270
202
271
The `SKILL.md` file should have YAML frontmatter with `name` and `description` fields:
203
272
@@ -215,26 +284,52 @@ Detailed instructions for the agent...
A `docker-compose.yml` and `run.sh` are provided for convenience. Both mount `instructions.md`, `agent_config.json`, `access.json`, persist sessions to `./data`, and mount `./skills` as the agent skills directory.
0 commit comments