zeph-tools 0.21.2

Tool executor trait with shell, web scrape, and composite executors for Zeph
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
// SPDX-License-Identifier: MIT OR Apache-2.0

//! Reaction moderation executor for Telegram Bot API 10.0.
//!
//! Exposes two structured tool calls — `telegram_delete_reaction` and
//! `telegram_delete_all_reactions` — that let the agent remove emoji reactions
//! from messages in chats where the bot has admin rights.
//!
//! The executor is platform-agnostic: it delegates the actual API calls to
//! a [`ReactionModerationBackend`] implementation, keeping `zeph-tools`
//! independent of `zeph-channels`.
//!
//! # Wiring
//!
//! In `src/agent_setup.rs`, build a `TelegramModerationBackend` (from
//! `zeph-channels`) and wrap it with [`ModerationExecutor`]:
//!
//! ```ignore
//! use zeph_channels::telegram_moderation::TelegramModerationBackend;
//! use zeph_tools::moderation::ModerationExecutor;
//!
//! let api = telegram_channel.api_ext().clone();
//! let me = api.get_me().await?;
//! let backend = TelegramModerationBackend::new(api, me.id);
//! let executor = ModerationExecutor::new(backend);
//! ```

use schemars::JsonSchema;
use serde::Deserialize;
use zeph_common::ToolName;

use crate::executor::{
    ClaimSource, ToolCall, ToolError, ToolExecutor, ToolOutput, deserialize_params,
};
use crate::registry::{InvocationHint, ToolDef};

// ── Tool parameter schemas ─────────────────────────────────────────────────

/// Parameters for `telegram_delete_reaction`.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct DeleteReactionParams {
    /// Telegram chat identifier (numeric).
    pub chat_id: i64,
    /// Identifier of the message whose reaction should be removed.
    pub message_id: i64,
    /// Telegram user identifier whose reaction to remove.
    pub user_id: i64,
    /// Emoji or custom reaction string to remove (e.g. `"👍"`).
    pub reaction: String,
}

/// Parameters for `telegram_delete_all_reactions`.
#[derive(Debug, Deserialize, JsonSchema)]
pub struct DeleteAllReactionsParams {
    /// Telegram chat identifier (numeric).
    pub chat_id: i64,
    /// Identifier of the message whose reactions should be cleared.
    pub message_id: i64,
    /// Telegram user identifier whose reactions to remove.
    pub user_id: i64,
}

// ── Backend trait ──────────────────────────────────────────────────────────

/// Errors produced by a [`ReactionModerationBackend`].
#[derive(Debug, thiserror::Error)]
pub enum ModerationError {
    /// The Telegram API returned an error response (`ok: false`).
    ///
    /// The description is forwarded from the API and maps to
    /// [`ToolError::InvalidParams`] so the agent can adjust its call.
    #[error("Telegram API error: {0}")]
    Api(String),
    /// HTTP transport or TLS error.
    ///
    /// Maps to a transient [`ToolError::Http`] so the agent may retry.
    #[error("HTTP error: {0}")]
    Http(String),
}

/// Backend that executes reaction-moderation API calls.
///
/// Implementors are expected to call the Telegram Bot API. The trait is
/// object-safe (all methods return pinned boxed futures) so [`ModerationExecutor`]
/// can hold it as `Arc<dyn ReactionModerationBackend>`.
///
/// # Contract
///
/// - `delete_reaction` and `delete_all_reactions` must call the Telegram API and
///   surface both `ok: false` responses as [`ModerationError::Api`] and transport
///   failures as [`ModerationError::Http`].
/// - The bot must be an administrator with appropriate rights in the target chat
///   **before** calling these methods; implementations SHOULD perform a pre-flight
///   `get_chat_member` check and return [`ModerationError::Api`] when the bot is
///   not an administrator, rather than forwarding a `Forbidden` error from the API.
pub trait ReactionModerationBackend: Send + Sync {
    /// Remove a single reaction left by `user_id` on a message.
    ///
    /// # Errors
    ///
    /// Returns [`ModerationError`] on API or transport failure.
    fn delete_reaction<'a>(
        &'a self,
        chat_id: i64,
        message_id: i64,
        user_id: i64,
        reaction: &'a str,
    ) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<(), ModerationError>> + Send + 'a>>;

    /// Remove all reactions left by `user_id` on a message.
    ///
    /// # Errors
    ///
    /// Returns [`ModerationError`] on API or transport failure.
    fn delete_all_reactions<'a>(
        &'a self,
        chat_id: i64,
        message_id: i64,
        user_id: i64,
    ) -> std::pin::Pin<Box<dyn std::future::Future<Output = Result<(), ModerationError>> + Send + 'a>>;
}

// ── Executor ───────────────────────────────────────────────────────────────

/// Tool executor for Telegram reaction moderation.
///
/// Dispatches the structured tool calls `telegram_delete_reaction` and
/// `telegram_delete_all_reactions` to the injected [`ReactionModerationBackend`].
///
/// Deleting reactions is irreversible — the executor signals
/// `requires_confirmation = true` so the user can approve before execution.
///
/// # Examples
///
/// ```no_run
/// # use zeph_tools::moderation::{ModerationExecutor, ReactionModerationBackend, ModerationError};
/// # use std::pin::Pin;
/// #
/// # struct MockBackend;
/// # impl ReactionModerationBackend for MockBackend {
/// #     fn delete_reaction<'a>(&'a self, _: i64, _: i64, _: i64, _: &'a str)
/// #         -> Pin<Box<dyn std::future::Future<Output = Result<(), ModerationError>> + Send + 'a>>
/// #     { Box::pin(async { Ok(()) }) }
/// #     fn delete_all_reactions<'a>(&'a self, _: i64, _: i64, _: i64)
/// #         -> Pin<Box<dyn std::future::Future<Output = Result<(), ModerationError>> + Send + 'a>>
/// #     { Box::pin(async { Ok(()) }) }
/// # }
/// #
/// let executor = ModerationExecutor::new(MockBackend);
/// ```
#[derive(Debug)]
pub struct ModerationExecutor<B> {
    backend: B,
}

impl<B: ReactionModerationBackend> ModerationExecutor<B> {
    /// Create a new executor backed by `backend`.
    pub fn new(backend: B) -> Self {
        Self { backend }
    }
}

/// Map a [`ModerationError`] to the appropriate [`ToolError`].
///
/// `Api` errors — e.g. `"MESSAGE_NOT_FOUND"`, `"REACTION_INVALID"` — map to
/// [`ToolError::InvalidParams`] because the call parameters were wrong, not a network issue.
/// `Http` transport errors map to [`ToolError::Http`] with status `502` (Bad Gateway) to signal
/// a transient upstream failure consistent with how other executors map network errors.
fn moderation_error_to_tool_error(e: ModerationError) -> ToolError {
    match e {
        ModerationError::Api(msg) => ToolError::InvalidParams { message: msg },
        ModerationError::Http(msg) => ToolError::Http {
            status: 502,
            message: msg,
        },
    }
}

impl<B: ReactionModerationBackend + std::fmt::Debug> ToolExecutor for ModerationExecutor<B> {
    async fn execute(&self, _response: &str) -> Result<Option<ToolOutput>, ToolError> {
        Ok(None)
    }

    #[tracing::instrument(skip(self), fields(tool_id = %call.tool_id))]
    async fn execute_tool_call(&self, call: &ToolCall) -> Result<Option<ToolOutput>, ToolError> {
        match call.tool_id.as_ref() {
            "telegram_delete_reaction" => {
                let p: DeleteReactionParams = deserialize_params(&call.params)?;
                if p.reaction.is_empty() {
                    return Err(ToolError::InvalidParams {
                        message: "reaction must not be empty".into(),
                    });
                }
                if p.reaction.chars().count() > 10 {
                    return Err(ToolError::InvalidParams {
                        message: "reaction string too long".into(),
                    });
                }
                tracing::info!(
                    chat_id = p.chat_id,
                    message_id = p.message_id,
                    user_id = p.user_id,
                    reaction = %p.reaction,
                    "moderation: deleting single reaction"
                );
                self.backend
                    .delete_reaction(p.chat_id, p.message_id, p.user_id, &p.reaction)
                    .await
                    .map_err(moderation_error_to_tool_error)?;
                Ok(Some(ToolOutput {
                    tool_name: ToolName::new("telegram_delete_reaction"),
                    summary: format!(
                        "Reaction '{}' removed from message {} in chat {} for user {}.",
                        p.reaction, p.message_id, p.chat_id, p.user_id
                    ),
                    blocks_executed: 1,
                    filter_stats: None,
                    diff: None,
                    streamed: false,
                    terminal_id: None,
                    locations: None,
                    raw_response: None,
                    claim_source: Some(ClaimSource::Moderation),
                }))
            }
            "telegram_delete_all_reactions" => {
                let p: DeleteAllReactionsParams = deserialize_params(&call.params)?;
                tracing::info!(
                    chat_id = p.chat_id,
                    message_id = p.message_id,
                    user_id = p.user_id,
                    "moderation: deleting all reactions"
                );
                self.backend
                    .delete_all_reactions(p.chat_id, p.message_id, p.user_id)
                    .await
                    .map_err(moderation_error_to_tool_error)?;
                Ok(Some(ToolOutput {
                    tool_name: ToolName::new("telegram_delete_all_reactions"),
                    summary: format!(
                        "All reactions removed from message {} in chat {} for user {}.",
                        p.message_id, p.chat_id, p.user_id
                    ),
                    blocks_executed: 1,
                    filter_stats: None,
                    diff: None,
                    streamed: false,
                    terminal_id: None,
                    locations: None,
                    raw_response: None,
                    claim_source: Some(ClaimSource::Moderation),
                }))
            }
            _ => Ok(None),
        }
    }

    fn tool_definitions(&self) -> Vec<ToolDef> {
        vec![
            ToolDef {
                id: "telegram_delete_reaction".into(),
                description: "Remove a specific emoji reaction left by a user on a Telegram message.\n\
                    Requires the bot to be an administrator with 'delete_messages' rights in the chat.\n\
                    This action is irreversible.\n\
                    Parameters: chat_id (integer, required) — chat containing the message;\n\
                      message_id (integer, required) — the target message;\n\
                      user_id (integer, required) — the user whose reaction to remove;\n\
                      reaction (string, required) — the emoji to remove (e.g. \"👍\").\n\
                    Returns: confirmation message on success.\n\
                    Errors: InvalidParams when the API returns ok=false; Http on transport failure.".into(),
                schema: schemars::schema_for!(DeleteReactionParams),
                invocation: InvocationHint::ToolCall,
                output_schema: None,
            },
            ToolDef {
                id: "telegram_delete_all_reactions".into(),
                description: "Remove all emoji reactions left by a user on a Telegram message.\n\
                    Requires the bot to be an administrator with 'delete_messages' rights in the chat.\n\
                    This action is irreversible.\n\
                    Parameters: chat_id (integer, required) — chat containing the message;\n\
                      message_id (integer, required) — the target message;\n\
                      user_id (integer, required) — the user whose reactions to remove.\n\
                    Returns: confirmation message on success.\n\
                    Errors: InvalidParams when the API returns ok=false; Http on transport failure.".into(),
                schema: schemars::schema_for!(DeleteAllReactionsParams),
                invocation: InvocationHint::ToolCall,
                output_schema: None,
            },
        ]
    }

    /// Reaction deletion is irreversible — always require confirmation.
    fn requires_confirmation(&self, call: &ToolCall) -> bool {
        matches!(
            call.tool_id.as_ref(),
            "telegram_delete_reaction" | "telegram_delete_all_reactions"
        )
    }
}

// ── Unit tests ─────────────────────────────────────────────────────────────

#[cfg(test)]
mod tests {
    use super::*;
    use std::sync::Arc;
    use std::sync::atomic::{AtomicU32, Ordering};

    // ── Mock backend ───────────────────────────────────────────────────────

    struct MockBackend {
        delete_calls: Arc<AtomicU32>,
        delete_all_calls: Arc<AtomicU32>,
        /// When set to `true`, all calls return `ModerationError::Api`.
        fail: bool,
    }

    impl MockBackend {
        fn new(fail: bool) -> (Self, Arc<AtomicU32>, Arc<AtomicU32>) {
            let d = Arc::new(AtomicU32::new(0));
            let da = Arc::new(AtomicU32::new(0));
            (
                Self {
                    delete_calls: Arc::clone(&d),
                    delete_all_calls: Arc::clone(&da),
                    fail,
                },
                d,
                da,
            )
        }
    }

    impl std::fmt::Debug for MockBackend {
        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
            f.debug_struct("MockBackend").finish_non_exhaustive()
        }
    }

    impl ReactionModerationBackend for MockBackend {
        fn delete_reaction<'a>(
            &'a self,
            _chat_id: i64,
            _message_id: i64,
            _user_id: i64,
            _reaction: &'a str,
        ) -> std::pin::Pin<
            Box<dyn std::future::Future<Output = Result<(), ModerationError>> + Send + 'a>,
        > {
            let fail = self.fail;
            let counter = Arc::clone(&self.delete_calls);
            Box::pin(async move {
                if fail {
                    Err(ModerationError::Api(
                        "Bad Request: message not found".into(),
                    ))
                } else {
                    counter.fetch_add(1, Ordering::Relaxed);
                    Ok(())
                }
            })
        }

        fn delete_all_reactions<'a>(
            &'a self,
            _chat_id: i64,
            _message_id: i64,
            _user_id: i64,
        ) -> std::pin::Pin<
            Box<dyn std::future::Future<Output = Result<(), ModerationError>> + Send + 'a>,
        > {
            let fail = self.fail;
            let counter = Arc::clone(&self.delete_all_calls);
            Box::pin(async move {
                if fail {
                    Err(ModerationError::Api("Forbidden: not enough rights".into()))
                } else {
                    counter.fetch_add(1, Ordering::Relaxed);
                    Ok(())
                }
            })
        }
    }

    fn make_call(tool_id: &str, params: &serde_json::Value) -> ToolCall {
        ToolCall {
            tool_id: ToolName::new(tool_id),
            params: params.as_object().cloned().unwrap_or_default(),
            caller_id: None,
            context: None,
            tool_call_id: String::new(),
        }
    }

    // ── execute returns None for unknown tool ──────────────────────────────

    #[tokio::test]
    async fn unknown_tool_returns_none() {
        let (backend, _, _) = MockBackend::new(false);
        let exec = ModerationExecutor::new(backend);
        let call = make_call("unknown_tool", &serde_json::json!({}));
        let result = exec.execute_tool_call(&call).await.unwrap();
        assert!(result.is_none());
    }

    #[tokio::test]
    async fn execute_fenced_returns_none() {
        let (backend, _, _) = MockBackend::new(false);
        let exec = ModerationExecutor::new(backend);
        let result = exec.execute("```bash\necho hi\n```").await.unwrap();
        assert!(result.is_none());
    }

    // ── delete_reaction success ────────────────────────────────────────────

    #[tokio::test]
    async fn delete_reaction_success() {
        let (backend, d_calls, _) = MockBackend::new(false);
        let exec = ModerationExecutor::new(backend);
        let call = make_call(
            "telegram_delete_reaction",
            &serde_json::json!({
                "chat_id": 100,
                "message_id": 200,
                "user_id": 300,
                "reaction": "👍"
            }),
        );
        let output = exec.execute_tool_call(&call).await.unwrap().unwrap();
        assert_eq!(output.tool_name.as_ref(), "telegram_delete_reaction");
        assert!(output.summary.contains("👍"));
        assert!(output.summary.contains("200"));
        assert_eq!(d_calls.load(Ordering::Relaxed), 1);
        assert_eq!(output.claim_source, Some(ClaimSource::Moderation));
    }

    // ── delete_all_reactions success ───────────────────────────────────────

    #[tokio::test]
    async fn delete_all_reactions_success() {
        let (backend, _, da_calls) = MockBackend::new(false);
        let exec = ModerationExecutor::new(backend);
        let call = make_call(
            "telegram_delete_all_reactions",
            &serde_json::json!({
                "chat_id": 100,
                "message_id": 200,
                "user_id": 300
            }),
        );
        let output = exec.execute_tool_call(&call).await.unwrap().unwrap();
        assert_eq!(output.tool_name.as_ref(), "telegram_delete_all_reactions");
        assert!(output.summary.contains("All reactions removed"));
        assert_eq!(da_calls.load(Ordering::Relaxed), 1);
    }

    // ── API error maps to InvalidParams ───────────────────────────────────

    #[tokio::test]
    async fn delete_reaction_api_error_maps_to_invalid_params() {
        let (backend, _, _) = MockBackend::new(true);
        let exec = ModerationExecutor::new(backend);
        let call = make_call(
            "telegram_delete_reaction",
            &serde_json::json!({
                "chat_id": 1,
                "message_id": 2,
                "user_id": 3,
                "reaction": "👎"
            }),
        );
        let err = exec.execute_tool_call(&call).await.unwrap_err();
        assert!(
            matches!(err, ToolError::InvalidParams { .. }),
            "expected InvalidParams, got {err:?}"
        );
    }

    #[tokio::test]
    async fn delete_all_reactions_api_error_maps_to_invalid_params() {
        let (backend, _, _) = MockBackend::new(true);
        let exec = ModerationExecutor::new(backend);
        let call = make_call(
            "telegram_delete_all_reactions",
            &serde_json::json!({
                "chat_id": 1,
                "message_id": 2,
                "user_id": 3
            }),
        );
        let err = exec.execute_tool_call(&call).await.unwrap_err();
        assert!(
            matches!(err, ToolError::InvalidParams { .. }),
            "expected InvalidParams, got {err:?}"
        );
    }

    // ── Invalid params ─────────────────────────────────────────────────────

    #[tokio::test]
    async fn delete_reaction_missing_params_returns_invalid_params() {
        let (backend, _, _) = MockBackend::new(false);
        let exec = ModerationExecutor::new(backend);
        // reaction field missing
        let call = make_call(
            "telegram_delete_reaction",
            &serde_json::json!({
                "chat_id": 1,
                "message_id": 2,
                "user_id": 3
            }),
        );
        let err = exec.execute_tool_call(&call).await.unwrap_err();
        assert!(matches!(err, ToolError::InvalidParams { .. }));
    }

    #[tokio::test]
    async fn delete_all_reactions_missing_params_returns_invalid_params() {
        let (backend, _, _) = MockBackend::new(false);
        let exec = ModerationExecutor::new(backend);
        // user_id field missing
        let call = make_call(
            "telegram_delete_all_reactions",
            &serde_json::json!({
                "chat_id": 1,
                "message_id": 2
            }),
        );
        let err = exec.execute_tool_call(&call).await.unwrap_err();
        assert!(matches!(err, ToolError::InvalidParams { .. }));
    }

    // ── requires_confirmation ─────────────────────────────────────────────

    #[test]
    fn requires_confirmation_for_delete_reaction() {
        let (backend, _, _) = MockBackend::new(false);
        let exec = ModerationExecutor::new(backend);
        let call = make_call(
            "telegram_delete_reaction",
            &serde_json::json!({
                "chat_id": 1, "message_id": 2, "user_id": 3, "reaction": "👍"
            }),
        );
        assert!(exec.requires_confirmation(&call));
    }

    #[test]
    fn requires_confirmation_for_delete_all_reactions() {
        let (backend, _, _) = MockBackend::new(false);
        let exec = ModerationExecutor::new(backend);
        let call = make_call(
            "telegram_delete_all_reactions",
            &serde_json::json!({
                "chat_id": 1, "message_id": 2, "user_id": 3
            }),
        );
        assert!(exec.requires_confirmation(&call));
    }

    #[test]
    fn does_not_require_confirmation_for_unknown_tool() {
        let (backend, _, _) = MockBackend::new(false);
        let exec = ModerationExecutor::new(backend);
        let call = make_call("unknown", &serde_json::json!({}));
        assert!(!exec.requires_confirmation(&call));
    }

    // ── tool_definitions ──────────────────────────────────────────────────

    #[test]
    fn tool_definitions_returns_two_tools() {
        let (backend, _, _) = MockBackend::new(false);
        let exec = ModerationExecutor::new(backend);
        let defs = exec.tool_definitions();
        assert_eq!(defs.len(), 2);
        let ids: Vec<&str> = defs.iter().map(|d| d.id.as_ref()).collect();
        assert!(ids.contains(&"telegram_delete_reaction"));
        assert!(ids.contains(&"telegram_delete_all_reactions"));
    }

    // ── Http error maps correctly ─────────────────────────────────────────

    #[test]
    fn moderation_error_http_maps_to_tool_error_http_502() {
        let err = ModerationError::Http("connection refused".into());
        let te = moderation_error_to_tool_error(err);
        assert!(matches!(te, ToolError::Http { status: 502, .. }));
    }

    // ── reaction validation ────────────────────────────────────────────────

    #[tokio::test]
    async fn delete_reaction_empty_reaction_returns_invalid_params() {
        let (backend, _, _) = MockBackend::new(false);
        let exec = ModerationExecutor::new(backend);
        let call = make_call(
            "telegram_delete_reaction",
            &serde_json::json!({
                "chat_id": 1,
                "message_id": 2,
                "user_id": 3,
                "reaction": ""
            }),
        );
        let err = exec.execute_tool_call(&call).await.unwrap_err();
        assert!(
            matches!(err, ToolError::InvalidParams { ref message } if message.contains("empty")),
            "expected empty reaction error, got {err:?}"
        );
    }

    #[tokio::test]
    async fn delete_reaction_overlong_reaction_returns_invalid_params() {
        let (backend, _, _) = MockBackend::new(false);
        let exec = ModerationExecutor::new(backend);
        let call = make_call(
            "telegram_delete_reaction",
            &serde_json::json!({
                "chat_id": 1,
                "message_id": 2,
                "user_id": 3,
                "reaction": "12345678901"  // 11 chars — exceeds limit of 10
            }),
        );
        let err = exec.execute_tool_call(&call).await.unwrap_err();
        assert!(
            matches!(err, ToolError::InvalidParams { ref message } if message.contains("too long")),
            "expected too long error, got {err:?}"
        );
    }
}