sombrax_agentic_core 0.1.1

SombraX Agentic Core (SAC) — a provider-agnostic Rust library for building LLM agents: content-modifying hooks, tool/MCP integration, and context optimization.
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
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
//! Hook trait and chain execution
//!
//! Provides the Hook trait for content-modifying hooks and HookChain for
//! sequential hook execution.

pub mod builtin;
pub mod context;

pub use context::HookContext;

use crate::error::{HookError, HookResult, HookStage};
use crate::message::Message;
use crate::provider::CompletionResponse;
use crate::telemetry::Metrics;
use crate::tool::ToolDefinition;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::time::Instant;

/// Re-export HookContext from context module
pub use crate::context::HookContext as ContextHookContext;

/// Decision returned by pre_tool_call hook
#[derive(Debug, Clone)]
pub enum ToolCallDecision {
    /// Proceed with the tool call using (possibly modified) arguments
    Proceed(serde_json::Value),
    /// Block the tool call with a reason (returned to model as error)
    Block(String),
}

impl ToolCallDecision {
    /// Check if this decision allows proceeding
    pub fn should_proceed(&self) -> bool {
        matches!(self, ToolCallDecision::Proceed(_))
    }

    /// Get the arguments if proceeding
    pub fn args(&self) -> Option<&serde_json::Value> {
        match self {
            ToolCallDecision::Proceed(args) => Some(args),
            ToolCallDecision::Block(_) => None,
        }
    }

    /// Get the block reason if blocked
    pub fn block_reason(&self) -> Option<&str> {
        match self {
            ToolCallDecision::Block(reason) => Some(reason),
            ToolCallDecision::Proceed(_) => None,
        }
    }
}

/// Content-modifying hook trait (FR-001, FR-002, FR-003, FR-007, FR-008, FR-016)
///
/// Hooks can intercept and modify content at various points in the agent lifecycle.
/// All methods have default pass-through implementations.
///
/// # Example
///
/// ```ignore
/// #[derive(Clone)]
/// struct LoggingHook;
///
/// impl Hook for LoggingHook {
///     async fn pre_completion(
///         &self,
///         message: Message,
///         history: &[Message],
///         ctx: &mut HookContext,
///     ) -> HookResult<Message> {
///         tracing::info!("Processing message: {:?}", message);
///         Ok(message) // Pass through unchanged
///     }
/// }
/// ```
pub trait Hook: Clone + Send + Sync + 'static {
    /// Called before the completion request is sent to the model (FR-001)
    ///
    /// Can modify the message content before it reaches the LLM.
    fn pre_completion(
        &self,
        message: Message,
        history: &[Message],
        ctx: &mut crate::context::HookContext,
    ) -> impl Future<Output = HookResult<Message>> + Send {
        let _ = (history, ctx);
        async { Ok(message) }
    }

    /// Called after the completion response is received (FR-002)
    ///
    /// Can modify the response content before it's returned to the caller.
    fn post_completion<R: Send + Sync + 'static>(
        &self,
        response: CompletionResponse<R>,
        ctx: &mut crate::context::HookContext,
    ) -> impl Future<Output = HookResult<CompletionResponse<R>>> + Send {
        let _ = ctx;
        async { Ok(response) }
    }

    /// Message-only post-completion hook for dynamic dispatch
    ///
    /// Override this to modify the response message when using dynamic dispatch.
    /// This is called by the hook chain for all hooks.
    fn post_completion_message(
        &self,
        message: Message,
        ctx: &mut crate::context::HookContext,
    ) -> impl Future<Output = HookResult<Message>> + Send {
        let _ = ctx;
        async { Ok(message) }
    }

    /// Called before a tool is executed (FR-007)
    ///
    /// Can modify arguments, or block the tool call entirely.
    fn pre_tool_call(
        &self,
        tool_name: &str,
        args: serde_json::Value,
        ctx: &mut crate::context::HookContext,
    ) -> impl Future<Output = HookResult<ToolCallDecision>> + Send {
        let _ = (tool_name, ctx);
        async { Ok(ToolCallDecision::Proceed(args)) }
    }

    /// Called after a tool returns its result (FR-008)
    ///
    /// Can modify the tool result before it's added to conversation history.
    fn post_tool_call(
        &self,
        tool_name: &str,
        result: String,
        ctx: &mut crate::context::HookContext,
    ) -> impl Future<Output = HookResult<String>> + Send {
        let _ = (tool_name, ctx);
        async { Ok(result) }
    }

    /// Called before tool definitions are sent to the model (FR-016)
    ///
    /// Can filter or modify which tools the model sees.
    fn filter_tools(
        &self,
        tools: Vec<ToolDefinition>,
        ctx: &mut crate::context::HookContext,
    ) -> impl Future<Output = HookResult<Vec<ToolDefinition>>> + Send {
        let _ = ctx;
        async { Ok(tools) }
    }

    /// Called after the model returns a response (including during tool loop)
    ///
    /// This is called for every model response, whether or not it contains tool calls.
    /// Useful for displaying/logging assistant text content before tool execution.
    fn on_assistant_message(
        &self,
        message: &Message,
        ctx: &mut crate::context::HookContext,
    ) -> impl Future<Output = HookResult<()>> + Send {
        let _ = (message, ctx);
        async { Ok(()) }
    }

    /// Returns the hook name for error reporting
    fn name(&self) -> &str {
        std::any::type_name::<Self>()
    }
}

/// No-op hook implementation for unit type.
///
/// This allows `()` to be used as a default generic parameter for hooks,
/// enabling patterns like `AgentBuildOptions<H: Hook = ()>` where no
/// hook is provided.
impl Hook for () {
    fn name(&self) -> &str {
        "NoOpHook"
    }
}

/// Dynamic dispatch trait for hooks (type-erased)
pub trait HookDyn: Send + Sync {
    /// Returns the hook name
    fn name(&self) -> &str;

    /// Pre-completion hook with dynamic dispatch
    fn pre_completion<'a>(
        &'a self,
        message: Message,
        history: &'a [Message],
        ctx: &'a mut crate::context::HookContext,
    ) -> Pin<Box<dyn Future<Output = HookResult<Message>> + Send + 'a>>;

    /// Post-completion hook with dynamic dispatch
    fn post_completion_dyn<'a>(
        &'a self,
        message: Message,
        ctx: &'a mut crate::context::HookContext,
    ) -> Pin<Box<dyn Future<Output = HookResult<Message>> + Send + 'a>>;

    /// Pre-tool-call hook with dynamic dispatch
    fn pre_tool_call<'a>(
        &'a self,
        tool_name: &'a str,
        args: serde_json::Value,
        ctx: &'a mut crate::context::HookContext,
    ) -> Pin<Box<dyn Future<Output = HookResult<ToolCallDecision>> + Send + 'a>>;

    /// Post-tool-call hook with dynamic dispatch
    fn post_tool_call<'a>(
        &'a self,
        tool_name: &'a str,
        result: String,
        ctx: &'a mut crate::context::HookContext,
    ) -> Pin<Box<dyn Future<Output = HookResult<String>> + Send + 'a>>;

    /// Filter-tools hook with dynamic dispatch
    fn filter_tools<'a>(
        &'a self,
        tools: Vec<ToolDefinition>,
        ctx: &'a mut crate::context::HookContext,
    ) -> Pin<Box<dyn Future<Output = HookResult<Vec<ToolDefinition>>> + Send + 'a>>;

    /// On-assistant-message hook with dynamic dispatch
    fn on_assistant_message<'a>(
        &'a self,
        message: &'a Message,
        ctx: &'a mut crate::context::HookContext,
    ) -> Pin<Box<dyn Future<Output = HookResult<()>> + Send + 'a>>;
}

/// Wrapper to implement HookDyn for any Hook
struct HookWrapper<H: Hook>(H);

impl<H: Hook> HookDyn for HookWrapper<H> {
    fn name(&self) -> &str {
        Hook::name(&self.0)
    }

    fn pre_completion<'a>(
        &'a self,
        message: Message,
        history: &'a [Message],
        ctx: &'a mut crate::context::HookContext,
    ) -> Pin<Box<dyn Future<Output = HookResult<Message>> + Send + 'a>> {
        Box::pin(Hook::pre_completion(&self.0, message, history, ctx))
    }

    fn post_completion_dyn<'a>(
        &'a self,
        message: Message,
        ctx: &'a mut crate::context::HookContext,
    ) -> Pin<Box<dyn Future<Output = HookResult<Message>> + Send + 'a>> {
        Box::pin(Hook::post_completion_message(&self.0, message, ctx))
    }

    fn pre_tool_call<'a>(
        &'a self,
        tool_name: &'a str,
        args: serde_json::Value,
        ctx: &'a mut crate::context::HookContext,
    ) -> Pin<Box<dyn Future<Output = HookResult<ToolCallDecision>> + Send + 'a>> {
        Box::pin(Hook::pre_tool_call(&self.0, tool_name, args, ctx))
    }

    fn post_tool_call<'a>(
        &'a self,
        tool_name: &'a str,
        result: String,
        ctx: &'a mut crate::context::HookContext,
    ) -> Pin<Box<dyn Future<Output = HookResult<String>> + Send + 'a>> {
        Box::pin(Hook::post_tool_call(&self.0, tool_name, result, ctx))
    }

    fn filter_tools<'a>(
        &'a self,
        tools: Vec<ToolDefinition>,
        ctx: &'a mut crate::context::HookContext,
    ) -> Pin<Box<dyn Future<Output = HookResult<Vec<ToolDefinition>>> + Send + 'a>> {
        Box::pin(Hook::filter_tools(&self.0, tools, ctx))
    }

    fn on_assistant_message<'a>(
        &'a self,
        message: &'a Message,
        ctx: &'a mut crate::context::HookContext,
    ) -> Pin<Box<dyn Future<Output = HookResult<()>> + Send + 'a>> {
        Box::pin(Hook::on_assistant_message(&self.0, message, ctx))
    }
}

/// An ordered chain of hooks
///
/// Hooks are executed sequentially, with each hook receiving the output of the previous.
/// The first error stops the chain and propagates.
#[derive(Default)]
pub struct HookChain {
    hooks: Vec<Arc<dyn HookDyn>>,
    metrics: Option<Metrics>,
}

impl HookChain {
    /// Create a new empty hook chain
    pub fn new() -> Self {
        Self {
            hooks: Vec::new(),
            metrics: Some(Metrics::global()),
        }
    }

    /// Add a hook to the chain
    pub fn add<H: Hook>(&mut self, hook: H) {
        self.hooks.push(Arc::new(HookWrapper(hook)));
    }

    /// Create a new chain with a hook added
    pub fn with<H: Hook>(mut self, hook: H) -> Self {
        self.add(hook);
        self
    }

    /// Check if the chain is empty
    pub fn is_empty(&self) -> bool {
        self.hooks.is_empty()
    }

    /// Get the number of hooks in the chain
    pub fn len(&self) -> usize {
        self.hooks.len()
    }

    /// Execute pre-completion hooks in order
    pub async fn execute_pre_completion(
        &self,
        mut message: Message,
        history: &[Message],
        ctx: &mut crate::context::HookContext,
    ) -> HookResult<Message> {
        tracing::debug!("executing pre_completion hook chain");

        for hook in &self.hooks {
            if ctx.is_cancelled() {
                return Err(HookError::Cancelled);
            }

            let hook_name = hook.name().to_string();
            let start = Instant::now();

            tracing::debug!(
                hook_name = %hook_name,
                stage = "pre_completion",
                "executing hook"
            );

            message = hook
                .pre_completion(message, history, ctx)
                .await
                .map_err(|e| match e {
                    HookError::HookFailed {
                        message, source, ..
                    } => HookError::HookFailed {
                        hook_name: hook_name.clone(),
                        stage: HookStage::PreCompletion,
                        message,
                        source,
                    },
                    other => other,
                })?;

            let duration = start.elapsed();
            tracing::debug!(
                hook_name = %hook_name,
                duration_ms = %duration.as_millis(),
                "pre_completion hook completed"
            );

            // Record hook duration metric (FR-021)
            if let Some(metrics) = &self.metrics {
                metrics.record_hook_duration(&hook_name, "pre_completion", duration);
            }
        }

        Ok(message)
    }

    /// Execute post-completion hooks in order
    pub async fn execute_post_completion<R: Send + Sync + 'static>(
        &self,
        mut response: CompletionResponse<R>,
        ctx: &mut crate::context::HookContext,
    ) -> HookResult<CompletionResponse<R>> {
        tracing::debug!("executing post_completion hook chain");

        for hook in &self.hooks {
            if ctx.is_cancelled() {
                return Err(HookError::Cancelled);
            }

            let hook_name = hook.name().to_string();
            let start = Instant::now();

            tracing::debug!(
                hook_name = %hook_name,
                stage = "post_completion",
                "executing hook"
            );

            // For dynamic dispatch, we process the message only
            let new_message = hook
                .post_completion_dyn(response.message, ctx)
                .await
                .map_err(|e| match e {
                    HookError::HookFailed {
                        message, source, ..
                    } => HookError::HookFailed {
                        hook_name: hook_name.clone(),
                        stage: HookStage::PostCompletion,
                        message,
                        source,
                    },
                    other => other,
                })?;

            response = CompletionResponse {
                message: new_message,
                usage: response.usage,
                raw: response.raw,
                reasoning_content: response.reasoning_content,
                finish_reason: response.finish_reason,
            };

            let duration = start.elapsed();
            tracing::debug!(
                hook_name = %hook_name,
                duration_ms = %duration.as_millis(),
                "post_completion hook completed"
            );

            // Record hook duration metric (FR-021)
            if let Some(metrics) = &self.metrics {
                metrics.record_hook_duration(&hook_name, "post_completion", duration);
            }
        }

        Ok(response)
    }

    /// Execute pre-tool-call hooks in order
    pub async fn execute_pre_tool_call(
        &self,
        tool_name: &str,
        mut args: serde_json::Value,
        ctx: &mut crate::context::HookContext,
    ) -> HookResult<ToolCallDecision> {
        tracing::debug!(tool_name = %tool_name, "executing pre_tool_call hook chain");

        for hook in &self.hooks {
            if ctx.is_cancelled() {
                return Err(HookError::Cancelled);
            }

            let hook_name = hook.name().to_string();
            let start = Instant::now();

            let decision = hook
                .pre_tool_call(tool_name, args, ctx)
                .await
                .map_err(|e| match e {
                    HookError::HookFailed {
                        message, source, ..
                    } => HookError::HookFailed {
                        hook_name: hook_name.clone(),
                        stage: HookStage::PreToolCall,
                        message,
                        source,
                    },
                    other => other,
                })?;

            let duration = start.elapsed();
            tracing::debug!(
                hook_name = %hook_name,
                duration_ms = %duration.as_millis(),
                "pre_tool_call hook completed"
            );

            // Record hook duration metric (FR-021)
            if let Some(metrics) = &self.metrics {
                metrics.record_hook_duration(&hook_name, "pre_tool_call", duration);
            }

            match decision {
                ToolCallDecision::Block(reason) => {
                    tracing::info!(
                        hook_name = %hook_name,
                        tool_name = %tool_name,
                        reason = %reason,
                        "tool call blocked by hook"
                    );
                    return Ok(ToolCallDecision::Block(reason));
                }
                ToolCallDecision::Proceed(new_args) => {
                    args = new_args;
                }
            }
        }

        Ok(ToolCallDecision::Proceed(args))
    }

    /// Execute post-tool-call hooks in order
    pub async fn execute_post_tool_call(
        &self,
        tool_name: &str,
        mut result: String,
        ctx: &mut crate::context::HookContext,
    ) -> HookResult<String> {
        tracing::debug!(tool_name = %tool_name, "executing post_tool_call hook chain");

        for hook in &self.hooks {
            if ctx.is_cancelled() {
                return Err(HookError::Cancelled);
            }

            let hook_name = hook.name().to_string();
            let start = Instant::now();

            result = hook
                .post_tool_call(tool_name, result, ctx)
                .await
                .map_err(|e| match e {
                    HookError::HookFailed {
                        message, source, ..
                    } => HookError::HookFailed {
                        hook_name: hook_name.clone(),
                        stage: HookStage::PostToolCall,
                        message,
                        source,
                    },
                    other => other,
                })?;

            let duration = start.elapsed();
            tracing::debug!(
                hook_name = %hook_name,
                duration_ms = %duration.as_millis(),
                "post_tool_call hook completed"
            );

            // Record hook duration metric (FR-021)
            if let Some(metrics) = &self.metrics {
                metrics.record_hook_duration(&hook_name, "post_tool_call", duration);
            }
        }

        Ok(result)
    }

    /// Execute filter-tools hooks in order
    pub async fn execute_filter_tools(
        &self,
        mut tools: Vec<ToolDefinition>,
        ctx: &mut crate::context::HookContext,
    ) -> HookResult<Vec<ToolDefinition>> {
        tracing::debug!("executing filter_tools hook chain");

        for hook in &self.hooks {
            if ctx.is_cancelled() {
                return Err(HookError::Cancelled);
            }

            let hook_name = hook.name().to_string();
            let start = Instant::now();
            let tools_before = tools.len();

            tools = hook.filter_tools(tools, ctx).await.map_err(|e| match e {
                HookError::HookFailed {
                    message, source, ..
                } => HookError::HookFailed {
                    hook_name: hook_name.clone(),
                    stage: HookStage::FilterTools,
                    message,
                    source,
                },
                other => other,
            })?;

            let duration = start.elapsed();
            tracing::debug!(
                hook_name = %hook_name,
                duration_ms = %duration.as_millis(),
                tools_before = %tools_before,
                tools_after = %tools.len(),
                "filter_tools hook completed"
            );

            // Record hook duration metric (FR-021)
            if let Some(metrics) = &self.metrics {
                metrics.record_hook_duration(&hook_name, "filter_tools", duration);
            }
        }

        Ok(tools)
    }

    /// Execute on-assistant-message hooks in order
    ///
    /// Called after the model returns a response, before tool execution begins.
    /// This allows hooks to display or log assistant text content.
    pub async fn execute_on_assistant_message(
        &self,
        message: &Message,
        ctx: &mut crate::context::HookContext,
    ) -> HookResult<()> {
        tracing::debug!("executing on_assistant_message hook chain");

        for hook in &self.hooks {
            if ctx.is_cancelled() {
                return Err(HookError::Cancelled);
            }

            let hook_name = hook.name().to_string();
            let start = Instant::now();

            tracing::debug!(
                hook_name = %hook_name,
                stage = "on_assistant_message",
                "executing hook"
            );

            hook.on_assistant_message(message, ctx)
                .await
                .map_err(|e| match e {
                    HookError::HookFailed {
                        message, source, ..
                    } => HookError::HookFailed {
                        hook_name: hook_name.clone(),
                        stage: HookStage::OnAssistantMessage,
                        message,
                        source,
                    },
                    other => other,
                })?;

            let duration = start.elapsed();
            tracing::debug!(
                hook_name = %hook_name,
                duration_ms = %duration.as_millis(),
                "on_assistant_message hook completed"
            );

            // Record hook duration metric (FR-021)
            if let Some(metrics) = &self.metrics {
                metrics.record_hook_duration(&hook_name, "on_assistant_message", duration);
            }
        }

        Ok(())
    }
}

impl Clone for HookChain {
    fn clone(&self) -> Self {
        Self {
            hooks: self.hooks.clone(),
            metrics: Some(Metrics::global()),
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[derive(Clone)]
    struct TestHook {
        prefix: String,
    }

    impl Hook for TestHook {
        async fn pre_completion(
            &self,
            mut message: Message,
            _history: &[Message],
            _ctx: &mut crate::context::HookContext,
        ) -> HookResult<Message> {
            message.prepend_text(&self.prefix);
            Ok(message)
        }
    }

    #[tokio::test]
    async fn test_hook_chain_pre_completion() {
        let mut chain = HookChain::new();
        chain.add(TestHook {
            prefix: "A: ".to_string(),
        });
        chain.add(TestHook {
            prefix: "B: ".to_string(),
        });

        let mut ctx = crate::context::HookContext::new("test-123");
        let message = Message::user("Hello");

        let result = chain
            .execute_pre_completion(message, &[], &mut ctx)
            .await
            .unwrap();

        // B runs after A, so "B: " is prepended to "A: Hello"
        assert_eq!(result.text(), "B: A: Hello");
    }

    #[test]
    fn test_tool_call_decision() {
        let proceed = ToolCallDecision::Proceed(serde_json::json!({"a": 1}));
        assert!(proceed.should_proceed());
        assert!(proceed.args().is_some());
        assert!(proceed.block_reason().is_none());

        let block = ToolCallDecision::Block("Not allowed".to_string());
        assert!(!block.should_proceed());
        assert!(block.args().is_none());
        assert_eq!(block.block_reason(), Some("Not allowed"));
    }

    #[test]
    fn test_hook_chain_operations() {
        let mut chain = HookChain::new();
        assert!(chain.is_empty());
        assert_eq!(chain.len(), 0);

        chain.add(TestHook {
            prefix: "A".to_string(),
        });
        assert!(!chain.is_empty());
        assert_eq!(chain.len(), 1);

        let chain2 = chain.with(TestHook {
            prefix: "B".to_string(),
        });
        assert_eq!(chain2.len(), 2);
    }
}