talon-agent 1.6.0 → 1.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +184 -50
- package/package.json +1 -1
- package/src/backend/claude-sdk/handler.ts +1 -1
- package/src/backend/claude-sdk/stream.ts +13 -8
package/README.md
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
# Talon
|
|
2
2
|
|
|
3
3
|
[](https://nodejs.org)
|
|
4
|
-
[](https://www.typescriptlang.org/)
|
|
5
5
|
[](https://github.com/anthropics/claude-agent-sdk-typescript)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
[](https://github.com/dylanneve1/talon/actions/workflows/ci.yml)
|
|
8
8
|
|
|
9
|
-
Multi-platform agentic AI harness powered by Claude. Runs on Telegram
|
|
9
|
+
Multi-platform agentic AI harness powered by Claude. Runs on **Telegram**, **Teams**, and **Terminal** with full tool access through MCP.
|
|
10
|
+
|
|
11
|
+
---
|
|
10
12
|
|
|
11
13
|
## Features
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
| | |
|
|
16
|
+
|---|---|
|
|
17
|
+
| **Multi-frontend** | Telegram (Grammy + GramJS userbot), Microsoft Teams (Bot Framework), Terminal with live tool visibility |
|
|
18
|
+
| **Claude Agent SDK** | Streaming responses, extended thinking, adaptive effort, 1M token context, dynamic model discovery |
|
|
19
|
+
| **MCP tools** | Messaging, media, history, search, web fetch, cron jobs, stickers, file system, admin controls |
|
|
20
|
+
| **Plugins** | Hot-reloadable plugin system. Built-in: GitHub, MemPalace, Playwright, Brave Search |
|
|
21
|
+
| **Background agents** | Heartbeat (periodic maintenance) and Dream (memory consolidation + diary) |
|
|
22
|
+
| **Per-chat settings** | Model, effort level, and pulse toggle per conversation via inline keyboard |
|
|
23
|
+
| **Model registry** | Models discovered from the SDK at startup --- new models appear in all pickers automatically |
|
|
24
|
+
|
|
25
|
+
---
|
|
20
26
|
|
|
21
27
|
## Quick Start
|
|
22
28
|
|
|
@@ -24,39 +30,134 @@ Multi-platform agentic AI harness powered by Claude. Runs on Telegram, Teams, an
|
|
|
24
30
|
git clone https://github.com/dylanneve1/talon.git && cd talon
|
|
25
31
|
npm install
|
|
26
32
|
|
|
27
|
-
# Interactive setup (select frontend, configure tokens)
|
|
33
|
+
# Interactive setup (select frontend, configure tokens, pick model)
|
|
28
34
|
npx talon setup
|
|
29
35
|
|
|
30
36
|
# Start
|
|
31
|
-
npx talon start # configured frontend (
|
|
37
|
+
npx talon start # configured frontend (daemon mode)
|
|
32
38
|
npx talon chat # terminal chat mode
|
|
33
39
|
```
|
|
34
40
|
|
|
35
|
-
|
|
41
|
+
**Prerequisites:**
|
|
42
|
+
- [Node.js 22+](https://nodejs.org/)
|
|
43
|
+
- [Claude Code](https://docs.anthropic.com/en/docs/claude-code) installed and authenticated (`claude` CLI on PATH)
|
|
44
|
+
|
|
45
|
+
---
|
|
36
46
|
|
|
37
47
|
## Architecture
|
|
38
48
|
|
|
39
49
|
```
|
|
40
|
-
index.ts
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
index.ts Composition root
|
|
51
|
+
|
|
|
52
|
+
+-- core/ Platform-agnostic engine
|
|
53
|
+
| +-- models.ts Model registry (dynamic SDK discovery)
|
|
54
|
+
| +-- gateway.ts HTTP bridge for MCP tool calls
|
|
55
|
+
| +-- dispatcher.ts Per-chat serial, cross-chat parallel execution
|
|
56
|
+
| +-- plugin.ts Plugin loader, registry, hot-reload
|
|
57
|
+
| +-- heartbeat.ts Periodic background agent
|
|
58
|
+
| +-- dream.ts Memory consolidation agent
|
|
59
|
+
| +-- pulse.ts Conversation-aware group engagement
|
|
60
|
+
| +-- cron.ts Persistent scheduled jobs
|
|
61
|
+
| +-- tools/ MCP tool definitions (13 files)
|
|
62
|
+
|
|
|
63
|
+
+-- backend/
|
|
64
|
+
| +-- claude-sdk/ Claude Agent SDK (modular: handler, stream,
|
|
65
|
+
| | options, state, warm, models, constants)
|
|
66
|
+
| +-- opencode/ OpenCode SDK alternative backend
|
|
67
|
+
|
|
|
68
|
+
+-- frontend/
|
|
69
|
+
| +-- telegram/ Grammy bot + GramJS userbot (10 files)
|
|
70
|
+
| +-- teams/ Bot Framework + Graph API
|
|
71
|
+
| +-- terminal/ Readline CLI with tool call visibility
|
|
72
|
+
|
|
|
73
|
+
+-- storage/ Sessions, history, chat settings,
|
|
74
|
+
| cron jobs, media index, daily logs
|
|
75
|
+
+-- util/ Config, logging, workspace, paths, time
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Dependency rule:** `core/` imports nothing from `frontend/` or `backend/`. Frontends and backends depend on core types, never on each other.
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Built-in Plugins
|
|
83
|
+
|
|
84
|
+
### GitHub
|
|
85
|
+
|
|
86
|
+
GitHub API access via the official GitHub MCP server. Gives the agent access to repositories, issues, PRs, code search, and more.
|
|
87
|
+
|
|
88
|
+
**Requirements:** Docker installed and running.
|
|
89
|
+
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"github": {
|
|
93
|
+
"enabled": true,
|
|
94
|
+
"token": "ghp_..."
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The token is optional --- defaults to the output of `gh auth token` if the GitHub CLI is authenticated.
|
|
100
|
+
|
|
101
|
+
### MemPalace
|
|
102
|
+
|
|
103
|
+
Structured long-term memory with vector search. The agent can store, search, and retrieve memories semantically. Integrates with Dream mode for automatic memory consolidation and personal diary entries.
|
|
104
|
+
|
|
105
|
+
**Requirements:** Python 3.10+ with the `mempalace` package.
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# Set up a Python environment
|
|
109
|
+
python -m venv ~/.talon/mempalace-venv
|
|
110
|
+
~/.talon/mempalace-venv/bin/pip install mempalace # Unix
|
|
111
|
+
# or: ~/.talon/mempalace-venv/Scripts/pip install mempalace # Windows
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"mempalace": {
|
|
117
|
+
"enabled": true,
|
|
118
|
+
"palacePath": "~/.talon/workspace/palace",
|
|
119
|
+
"pythonPath": "~/.talon/mempalace-venv/bin/python"
|
|
120
|
+
}
|
|
121
|
+
}
|
|
55
122
|
```
|
|
56
123
|
|
|
57
|
-
|
|
124
|
+
Both paths are optional --- defaults to `~/.talon/workspace/palace/` and the venv Python respectively.
|
|
125
|
+
|
|
126
|
+
### Playwright
|
|
58
127
|
|
|
59
|
-
|
|
128
|
+
Headless browser automation via the Playwright MCP server. The agent can browse websites, take screenshots, generate PDFs, fill forms, and scrape content.
|
|
129
|
+
|
|
130
|
+
**Requirements:** None --- `@playwright/mcp` is bundled with Talon.
|
|
131
|
+
|
|
132
|
+
```json
|
|
133
|
+
{
|
|
134
|
+
"playwright": {
|
|
135
|
+
"enabled": true,
|
|
136
|
+
"browser": "chromium",
|
|
137
|
+
"headless": true
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Supported browsers: `chromium` (default), `chrome`, `firefox`, `webkit`, `msedge`.
|
|
143
|
+
|
|
144
|
+
### Brave Search
|
|
145
|
+
|
|
146
|
+
Web search via the Brave Search MCP server. Replaces the built-in WebSearch/WebFetch tools with higher-quality search results.
|
|
147
|
+
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"braveApiKey": "BSA..."
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Get an API key at [brave.com/search/api](https://brave.com/search/api/).
|
|
155
|
+
|
|
156
|
+
---
|
|
157
|
+
|
|
158
|
+
## Custom Plugins
|
|
159
|
+
|
|
160
|
+
Plugins add MCP tools and gateway actions without modifying core code. SOLID interface --- only `name` is required.
|
|
60
161
|
|
|
61
162
|
```json
|
|
62
163
|
{
|
|
@@ -80,59 +181,92 @@ export default {
|
|
|
80
181
|
};
|
|
81
182
|
```
|
|
82
183
|
|
|
184
|
+
Plugins support hot-reload via the `reload_plugins` MCP tool --- no restart required.
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
83
188
|
## CLI
|
|
84
189
|
|
|
85
190
|
```
|
|
86
|
-
talon setup Interactive setup wizard
|
|
87
|
-
talon start Start
|
|
191
|
+
talon setup Interactive setup wizard
|
|
192
|
+
talon start Start as a background daemon
|
|
193
|
+
talon stop Stop the daemon
|
|
88
194
|
talon chat Terminal chat mode (always available)
|
|
89
|
-
talon status Health, sessions,
|
|
90
|
-
talon config View
|
|
195
|
+
talon status Health, sessions, plugins, disk usage
|
|
196
|
+
talon config View or edit configuration
|
|
91
197
|
talon logs Tail structured log file
|
|
92
|
-
talon doctor Validate environment
|
|
198
|
+
talon doctor Validate environment and dependencies
|
|
93
199
|
```
|
|
94
200
|
|
|
201
|
+
---
|
|
202
|
+
|
|
95
203
|
## Configuration
|
|
96
204
|
|
|
97
|
-
|
|
205
|
+
Config file: `~/.talon/config.json`
|
|
98
206
|
|
|
99
207
|
| Field | Default | Description |
|
|
100
208
|
|-------|---------|-------------|
|
|
101
|
-
| `frontend` | `"telegram"` | `"telegram"`, `"terminal"`, or
|
|
102
|
-
| `
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
209
|
+
| `frontend` | `"telegram"` | `"telegram"`, `"terminal"`, `"teams"`, or an array |
|
|
210
|
+
| `backend` | `"claude"` | `"claude"` or `"opencode"` |
|
|
211
|
+
| `botToken` | --- | Telegram bot token |
|
|
212
|
+
| `model` | `"claude-sonnet-4-6"` | Default model (discovered from SDK at startup) |
|
|
213
|
+
| `concurrency` | `1` | Max concurrent AI queries (1--20) |
|
|
105
214
|
| `pulse` | `true` | Periodic group engagement |
|
|
215
|
+
| `heartbeat` | `false` | Background maintenance agent |
|
|
216
|
+
| `heartbeatIntervalMinutes` | `60` | Heartbeat interval |
|
|
217
|
+
| `braveApiKey` | --- | Brave Search API key |
|
|
218
|
+
| `timezone` | --- | IANA timezone (e.g. `"Europe/London"`) |
|
|
106
219
|
| `plugins` | `[]` | External plugin packages |
|
|
107
|
-
| `adminUserId` |
|
|
108
|
-
| `
|
|
220
|
+
| `adminUserId` | --- | Telegram user ID for `/admin` commands |
|
|
221
|
+
| `allowedUsers` | --- | Whitelist of Telegram user IDs |
|
|
222
|
+
| `apiId` / `apiHash` | --- | Telegram API credentials for full message history |
|
|
223
|
+
| `github` | --- | GitHub plugin config (see above) |
|
|
224
|
+
| `mempalace` | --- | MemPalace plugin config (see above) |
|
|
225
|
+
| `playwright` | --- | Playwright plugin config (see above) |
|
|
226
|
+
|
|
227
|
+
---
|
|
109
228
|
|
|
110
229
|
## Terminal Mode
|
|
111
230
|
|
|
112
231
|
```bash
|
|
113
|
-
talon chat
|
|
232
|
+
npx talon chat
|
|
114
233
|
```
|
|
115
234
|
|
|
116
|
-
Tool calls shown in real-time with parameters. Streaming phase indicators (thinking/responding/using tools). Per-turn stats
|
|
235
|
+
Tool calls shown in real-time with parameters. Streaming phase indicators (thinking / responding / using tools). Per-turn stats: duration, tokens, cache hit rate, tool count.
|
|
236
|
+
|
|
237
|
+
Commands: `/model`, `/effort`, `/reset`, `/status`, `/help`
|
|
238
|
+
|
|
239
|
+
---
|
|
117
240
|
|
|
118
241
|
## Production
|
|
119
242
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
243
|
+
**Docker:**
|
|
244
|
+
```bash
|
|
245
|
+
docker compose up -d
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**Systemd:** `talon.service` included in the repository.
|
|
249
|
+
|
|
250
|
+
**Health endpoint:** `GET http://localhost:19876/health` returns JSON with uptime, memory, queue depth, active sessions, and last activity timestamp.
|
|
251
|
+
|
|
252
|
+
**Logging:** Structured JSON via pino to `~/.talon/talon.log`. Rotated on startup when the file exceeds 10MB.
|
|
253
|
+
|
|
254
|
+
**Resilience:** Dynamic model fallback on overload, session auto-retry on expiry, rate limit handling with backoff, atomic file writes, graceful shutdown with 15-second drain timeout.
|
|
255
|
+
|
|
256
|
+
---
|
|
125
257
|
|
|
126
258
|
## Development
|
|
127
259
|
|
|
128
260
|
```bash
|
|
129
261
|
npm run dev # watch mode
|
|
130
|
-
npm test #
|
|
131
|
-
npm run test:coverage # with coverage
|
|
262
|
+
npm test # 1300+ tests
|
|
263
|
+
npm run test:coverage # with coverage report
|
|
132
264
|
npm run typecheck # tsc --noEmit
|
|
133
265
|
npm run lint # oxlint
|
|
134
266
|
```
|
|
135
267
|
|
|
268
|
+
---
|
|
269
|
+
|
|
136
270
|
## License
|
|
137
271
|
|
|
138
272
|
MIT
|
package/package.json
CHANGED
|
@@ -122,7 +122,7 @@ export async function handleMessage(
|
|
|
122
122
|
|
|
123
123
|
// Final result — read token counts and context info
|
|
124
124
|
if (isResult(message)) {
|
|
125
|
-
processResultMessage(message, state);
|
|
125
|
+
processResultMessage(message, state, options.model ?? activeModel);
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
} catch (err) {
|
|
@@ -178,6 +178,7 @@ export function processAssistantMessage(
|
|
|
178
178
|
export function processResultMessage(
|
|
179
179
|
msg: SDKResultMessage,
|
|
180
180
|
state: StreamState,
|
|
181
|
+
sdkModel: string,
|
|
181
182
|
): void {
|
|
182
183
|
state.numApiCalls = msg.num_turns ?? 0;
|
|
183
184
|
|
|
@@ -191,21 +192,25 @@ export function processResultMessage(
|
|
|
191
192
|
(last.cache_creation_input_tokens ?? 0);
|
|
192
193
|
}
|
|
193
194
|
|
|
194
|
-
//
|
|
195
|
+
// Read token counts from the ACTIVE model's usage only.
|
|
196
|
+
// modelUsage is keyed by the exact SDK model string (e.g. "claude-sonnet-4-6[1m]")
|
|
197
|
+
// and contains cumulative session totals per model — summing all entries
|
|
198
|
+
// double-counts when switching models mid-session.
|
|
195
199
|
const modelUsage: Record<string, ModelUsage> = msg.modelUsage;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
state.
|
|
199
|
-
state.
|
|
200
|
-
state.
|
|
201
|
-
|
|
200
|
+
const mu = modelUsage[sdkModel] ?? Object.values(modelUsage).at(-1);
|
|
201
|
+
if (mu) {
|
|
202
|
+
state.sdkInputTokens = mu.inputTokens ?? 0;
|
|
203
|
+
state.sdkOutputTokens = mu.outputTokens ?? 0;
|
|
204
|
+
state.sdkCacheRead = mu.cacheReadInputTokens ?? 0;
|
|
205
|
+
state.sdkCacheWrite = mu.cacheCreationInputTokens ?? 0;
|
|
206
|
+
if (mu.contextWindow > 0) {
|
|
202
207
|
state.contextWindow = mu.contextWindow;
|
|
203
208
|
}
|
|
204
209
|
}
|
|
205
210
|
|
|
206
211
|
log(
|
|
207
212
|
"agent",
|
|
208
|
-
`SDK result:
|
|
213
|
+
`SDK result: sdkModel=${sdkModel}, contextWindow=${state.contextWindow}, contextTokens=${state.contextTokens}, numApiCalls=${state.numApiCalls}`,
|
|
209
214
|
);
|
|
210
215
|
|
|
211
216
|
// Fallback: if no text was captured via streaming or assistant messages,
|