trusty-agents-common 0.3.0

Stable agent-plugin surface (ToolExecutor, AgentPlugin, ToolResult) shared by trusty-agents and external agent crates.
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
//! Stable plugin API surface shared between `trusty-agents` and external agent crates.
//!
//! Why: The original design placed `ToolExecutor` / `AgentPlugin` / `ToolResult`
//!      inside the host crate's `lib.rs`. That created a hard cargo dependency
//!      cycle (trusty-agents → cto-assistant → trusty-agents), because external agent
//!      crates need the trait to implement it AND `trusty-agents` needs the agent
//!      crate to inject the plugin at startup. Cargo cannot resolve circular
//!      path dependencies even when they are logically one-directional at the
//!      binary level. Extracting the minimal trait surface into this tiny
//!      crate breaks the cycle: both `trusty-agents` and every agent crate depend
//!      on `trusty-agents-common`, but never on each other through the lib.
//! What: Re-defines the previously trusty-agents-internal types — `ToolExecutor`
//!       trait, `ToolResult` enum, `ToolExecutionTier` enum, `ServiceTier`
//!       enum (RBAC tiers), and `AgentPlugin` struct — as the public surface.
//!       Also hosts the harness-adapter framework (`adapters`) and the
//!       JSON-backed session ledger (`session_registry`), both moved here in
//!       Wave 1 of the trusty-agents-common build-out (issue #862, refs #830/#832).
//!       `trusty-agents` re-exports them via `trusty_agents::agent_api`,
//!       `trusty_agents::adapters`, and `trusty_agents::session_registry` for
//!       source-level compatibility with the existing call sites in
//!       `crates/trusty-agents/src/**`.
//! Test: Compile-tested transitively via `crates/cto-assistant` (downstream
//!       agent) and `crates/trusty-agents` (host).

/// Portable perf value types: `TokenUsage`, `PhaseRecord`, `PerfTotals`, `PerfRecord`.
///
/// Why: Moved to trusty-agents-common in Wave 2 (issue #867, refs #830/#832) so
///      external crates and the runner seam can reference `TokenUsage` (used in
///      `AgentOutput`) without depending on the full `trusty-agents` binary crate.
///      `PerfCollector` (stateful, tokio-dependent) stays in `trusty-agents::perf`.
/// What: The four portable plain-data types for per-phase token counting,
///       cost tracking, and full run record serialisation.
/// Test: Unit tests in `perf::tests` plus compile-tested via `trusty-agents`.
pub mod perf;

/// AgentRunner DI seam: `HistoryMessage`, `RunContext`, `AgentOutput`, and
/// the `AgentRunner` async trait.
///
/// Why: Moved to trusty-agents-common in Wave 2 (issue #867, refs #830/#832)
///      so external crates that need to implement or test against `AgentRunner`
///      can depend on this lightweight crate without pulling in the full
///      `trusty-agents` binary crate.
/// What: The runner seam — once `TokenUsage` (perf) is here, the only
///       remaining dependencies are `std`, `anyhow`, `async-trait`, and
///       `serde`. `HistoryMessage` is the portable IPC wire form
///       (`{role, content}` + serde); its `into_typed()` conversion
///       (requiring `async-openai`) stays in `trusty-agents::session`.
/// Test: `test_run_with_history_forwards_ctx` in `runner::tests` (bug #122
///       regression guard); compile-tested via `trusty-agents`.
pub mod runner;

/// Harness adapter framework: `HarnessAdapter` trait, value types, pattern
/// helpers, `AdapterRegistry`, and 7 concrete adapters.
///
/// Why: Moved to trusty-agents-common in Wave 1 (issue #862) so external
///      crates that need to implement or enumerate adapters can do so without
///      depending on the full `trusty-agents` binary crate. Zero internal
///      `crate::` dependencies confirmed pre-move.
/// What: Re-exports everything that was under `trusty-agents::adapters`.
/// Test: All unit tests in the submodules; `cargo test -p trusty-agents-common`
///       exercises them in-place.
pub mod adapters;

/// JSON-backed session ledger (`SessionsRegistry` + `SessionEntry`).
///
/// Why: Moved to trusty-agents-common in Wave 1 (issue #862) alongside the
///      adapter framework. The registry is purely `std`/`anyhow`/`chrono`/`serde`
///      — no host-crate dependencies — making it a clean extraction.
/// What: `SessionsRegistry` provides `open`, `record_start`, `record_end`,
///       `list` over a flat `sessions.json` file.
/// Test: `record_start_appends_entry`, `record_end_updates_status`, etc. in
///       the `tests` module of `session_registry.rs`.
pub mod session_registry;

/// Unified harness event envelope, process-global broadcast bus, and filter.
///
/// Why: Wave 3 (epic #830, refs #833) unifies real-time event streaming across
///      the three harnesses (`trusty-agents`, `trusty-mpm`, `trusty-code`) onto
///      one `HarnessEvent` envelope flowing over a single process-global
///      broadcast bus. Phase 0 (this module) lands the foundation only — the
///      types, the bus, the subscription API, and a lightweight `Filter` — with
///      NO consumers wired yet. Migration of existing emit sites happens in
///      P1–P4. See ADR-0005.
/// What: Re-exports `HarnessEvent`, `HarnessPayload`, `HarnessSource`,
///       `LifecycleEvent`, `Lag`, `Filter`, the `bus`/`subscribe`/`publish`/
///       `emit`/`recv_with_lag` helpers, and the `EVENT_LINE_PREFIX` relay
///       constant from the `events::*` submodules.
/// Test: `events::tests` is the comprehensive suite for this foundation type.
pub mod events;

/// Canonical harness-understanding instructions shared by all consumers (DOC-21).
///
/// Why: Both trusty-mpm's SM prompt and a future t-code overseer need the same
///      harness mental model — session lifecycle, pane signals, decision protocol,
///      and per-harness specifics. A single shared source prevents drift.
/// What: Four structured accessors (`agnostic`, `mpm_session_manager`, `tcode`,
///       `overseer`) plus a `harness_understanding` convenience that concatenates
///       all sections. Content is bundled markdown compiled in via `include_str!`.
/// Test: `harness_doc::tests` exercises every accessor and the full-doc combinator.
pub mod harness_doc;

/// Portable tool-output compression: `compress_tool_output(_async)` + filters.
///
/// Why: Hoisted from `trusty-agents::compress::tool_output` in issue #1959 so
///      `trusty-mpm` (and any future consumer) can compress tool output
///      without a full `trusty-agents` path dependency — needed by the `tm
///      hook` `PreToolUse` Bash rewrite spike (issue #1956).
/// What: Dispatch (`compress_tool_output`), the async RTK-then-native wrapper
///       (`compress_tool_output_async`), and the path-reporting variant
///       (`compress_tool_output_async_with_path`) used for stats logging.
/// Test: `cargo test -p trusty-agents-common` exercises `compress::tool_output::tests`
///       in place; `trusty-agents`'s `llm::tool_loop` tests cover the
///       re-exported call site.
pub mod compress;

/// Agent compose/deploy/manifest machinery: `builder`, `manifest`,
/// `deployer`, and the shared `frontmatter` line parser.
///
/// Why: Extracted from `trusty-mpm::core::{agent_builder,agent_manifest,
///      agent_deployer,frontmatter}` (#2892), mirroring the precedent set by
///      `ToolExecutor`/`AgentRunner`, so `trusty-code` can eventually consume
///      the same `extends:`-inheritance composer and ownership-tracked
///      deployer instead of forking them.
/// What: `builder::compose_agent` / `builder::source_chain` resolve an
///      inheritance chain into one flattened Markdown document;
///      `manifest::AgentManifest` tracks which deployed files a harness owns
///      via a sha256 checksum ledger; `deployer::deploy_agents(_filtered)`
///      writes composed agents into a target directory without clobbering
///      user edits. `trusty-mpm` re-exports every item here from its
///      `core::agent_builder` / `core::agent_manifest` / `core::agent_deployer`
///      / `core::frontmatter` modules for source compatibility.
/// Test: `cargo test -p trusty-agents-common agents::` exercises every
///      submodule in place.
pub mod agents;

/// Skill deploy/manifest/tier machinery: `manifest`, `deployer`, `tiers`.
///
/// Why: Extracted from `trusty-mpm::core::{skill_deployer,skill_manifest,
///      skill_tiers}` (#2892, #2818), mirroring the agent compose/deploy/
///      manifest extraction, so `trusty-code` can eventually consume the same
///      ownership-tracked skill deployer and tier-precedence resolver instead
///      of forking them.
/// What: `manifest::SkillManifest` tracks which deployed skill files a
///      harness owns via a sha256 checksum ledger (reusing
///      `agents::manifest::ManifestError`); `deployer::deploy_skills(_filtered)`
///      writes skill sources into `<dest>/<name>/SKILL.md` without clobbering
///      user edits; `tiers::plan_skill_tiers` / `deploy_all_skill_tiers`
///      resolve and deploy the project-custom > user-custom > bundled
///      precedence. `trusty-mpm` re-exports every item here from its
///      `core::skill_deployer` / `core::skill_manifest` / `core::skill_tiers`
///      modules for source compatibility with the existing call sites.
/// Test: `cargo test -p trusty-agents-common skills::` exercises every
///      submodule in place.
pub mod skills;

/// `WorkstreamConnector` trait + value types: the DOC-44 "engineering lead /
/// virtual twin" architecture's Layer 1 tool-control surface (issue #3007,
/// twin Phase 1).
///
/// Why: DOC-44 requires a unified, tool-agnostic session-control trait both
/// `trusty-mpm` and `trusty-code` implement, living one level below both so
/// neither harness crate has to depend on the other. See the module's own
/// docs for the full DOC-44/DOC-42 naming-correction context.
/// What: re-exports `WorkstreamConnector`, its request/response types, the
/// `ConnectorError` failure enum, and `ConnectorTestKit`'s shared
/// conformance assertions. The concrete tm/tcode implementations live in
/// their owning crates, not here.
/// Test: `cargo test -p trusty-agents-common connectors::` exercises every
/// submodule in place.
pub mod connectors;

/// Heterogeneous workstream ledger: the DOC-44 "engineering lead / virtual
/// twin" architecture's Layer 2 persisted state (issue #3008, twin Phase 2).
///
/// Why: DOC-44 §8 Phase 2 needs a harness-tagged (`tm`/`tcode`) registry the
/// eventual lead agent uses to track workstreams across both tools, built
/// directly on Phase 1's `connectors::BackendParams` tagging. See the
/// module's own docs for the naming correction (issue title says "DOC-42",
/// the correct id is DOC-44) and its relationship to `session_registry`
/// (a different, narrower, already-wired registry — left untouched).
/// What: `Workstream`/`Harness`/`WorkstreamStatus`/`Priority`/`NewWorkstream`
/// value types, the JSON-backed `WorkstreamLedger` (create/list/get/query/
/// update), `LedgerError`, and the `LedgerRecovery` seam
/// (`JsonFileRecovery` default + `TrustyMemoryRecovery` stub, blocked on
/// issue #3228).
/// Test: `cargo test -p trusty-agents-common workstreams::` exercises every
/// submodule in place.
pub mod workstreams;

/// Shared multi-client attach/fan-out transport (DOC-48 §5.3.1, AC-7; issue
/// #3299, epic #3292; twin epic #3052).
///
/// Why: extracted from `trusty-code::workstreams::sse` (issue #3297) — DOC-48
/// §5.3.1 designates the multi-client SSE fan-out algorithm as
/// harness-agnostic, needed by both tcode workstream observation and a
/// future `trusty-agents` background-session transport (epic #3052). See the
/// module's own docs for the trait shapes and why they carry zero
/// axum/tcode dependency.
/// What: `EventSource`/`MembershipProvider` traits, `SourceEvent`/
/// `EventEnvelope` (the AC-7.2 `{session_id, event_type, payload}` wire
/// shape), and `aggregate_live` (the fan-out combinator). HTTP/SSE framing
/// stays in each consumer.
/// Test: `cargo test -p trusty-agents-common transport::` exercises every
/// submodule in place.
pub mod transport;

use std::sync::Arc;

use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use serde_json::Value;

/// Structured result of a tool execution.
///
/// Why: Hard-failing the LLM loop on every tool error is brittle — the model
///      often can recover (retry with different args, fall back to another
///      tool, or explain the failure in its final answer). Returning a
///      structured `Error { recoverable }` lets us surface the failure back
///      to the LLM as a `tool_result` with `is_error: true` while keeping the
///      loop running, unless `recoverable = false` in which case callers may
///      choose to stop.
/// What: `Success(String)` carries a successful textual result; `Error`
///       carries a message plus a `recoverable` flag.
/// Test: `ToolResult::err(...).is_error()` is true; `ok(...).content()`
///       returns the success string. Exercised across `trusty-agents/tools/**`.
#[derive(Debug)]
pub enum ToolResult {
    Success(String),
    Error { message: String, recoverable: bool },
}

impl ToolResult {
    /// Success with a textual payload.
    ///
    /// Why: Single canonical happy-path constructor used by every tool.
    /// What: Wraps `s` in `Success`.
    /// Test: Trivially exercised by every successful tool execute().
    pub fn ok(s: impl Into<String>) -> Self {
        ToolResult::Success(s.into())
    }

    /// Recoverable error: loop continues, LLM sees `is_error: true`.
    ///
    /// Why: Most tool failures are non-fatal — wrong arg, transient network,
    ///      empty result. We want the model to see the error and decide.
    /// What: Wraps `msg` with `recoverable = true`.
    /// Test: Exercised by tool error tests across the workspace.
    pub fn err(msg: impl Into<String>) -> Self {
        ToolResult::Error {
            message: msg.into(),
            recoverable: true,
        }
    }

    /// Fatal (non-recoverable) error: callers may choose to stop the loop.
    ///
    /// Why: Some failures (invariant violations, credential rejection) shouldn't
    ///      be retried by the LLM; callers should surface them and bail.
    /// What: Wraps `msg` with `recoverable = false`.
    /// Test: Used by `is_fatal` tests in trusty-agents.
    pub fn fatal(msg: impl Into<String>) -> Self {
        ToolResult::Error {
            message: msg.into(),
            recoverable: false,
        }
    }

    /// Whether this result is an error variant.
    ///
    /// Why: Dispatch paths need a cheap predicate to log/branch on failure.
    /// What: Returns `true` for any `Error`, `false` for `Success`.
    /// Test: `cto_assistant::execute_outcome_maps_to_tool_result` checks this.
    pub fn is_error(&self) -> bool {
        matches!(self, ToolResult::Error { .. })
    }

    /// Whether this error is fatal (not recoverable). `false` for Success.
    ///
    /// Why: Callers that distinguish fatal-vs-recoverable need this to decide
    ///      whether to retry or bail.
    /// What: True only for `Error { recoverable: false, .. }`.
    /// Test: `cto_assistant::execute_outcome_maps_to_tool_result`.
    pub fn is_fatal(&self) -> bool {
        matches!(
            self,
            ToolResult::Error {
                recoverable: false,
                ..
            }
        )
    }

    /// Access the inner textual content (success body or error message).
    ///
    /// Why: The LLM tool-result payload is always a string; this lets callers
    ///      treat success/error uniformly when serialising.
    /// What: Returns the success body or the error message.
    /// Test: Implicit in every test that asserts on `result.content()`.
    pub fn content(&self) -> &str {
        match self {
            Self::Success(s) => s,
            Self::Error { message, .. } => message,
        }
    }
}

/// Two-tier tool execution model (trusty-agents #447).
///
/// Why: The dispatch path treats always-on tools fundamentally differently
///      from on-demand tools — they run automatically, their output becomes
///      context rather than a `tool_result`, and they must not appear in the
///      LLM's tool list. Encoding the distinction as an enum on the trait
///      makes it impossible to accidentally schedule an `AlwaysOn` tool as
///      `OnDemand` or vice-versa.
/// What: `OnDemand` is the default (current behavior); `AlwaysOn` opts the
///       tool into the pre-LLM context-building pipeline.
/// Test: Default exercised by every existing tool; `AlwaysOn` exercised by
///       `trusty-agents`'s `tools/always_on::build_live_context_*`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ToolExecutionTier {
    #[default]
    OnDemand,
    AlwaysOn,
}

/// RBAC service tier (trusty-agents #445).
///
/// Why: Different transports (CLI, Slack, Telegram, HTTP) expose the same
///      tool registry to users with different trust levels. Tools opt into
///      RBAC by listing the tiers that must be denied access. Defined here
///      (not in `trusty-agents/rbac`) because the `ToolExecutor::restricted_tiers`
///      signature returns `&[ServiceTier]` — external agent crates would not
///      be able to implement the trait without seeing the enum.
/// What: `All` (full access — controller / authenticated operator),
///       `Analytics` (read + analytical queries, no mutations), `ReadOnly`
///       (passive observation only, the strictest tier).
///       Serializes as `snake_case` so TOML/JSON authors can write
///       `tier = "read_only"` rather than the variant name. `Default` is
///       `All` so callsites that forget to set a tier degrade open at the
///       controller (unauthenticated transports MUST set a stricter default).
/// Test: `trusty-agents/rbac` covers serde + ordering; `trusty-agents/tools/mod::dispatch_for_user_*`
///       covers integration with dispatch.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize, Serialize, Default)]
#[serde(rename_all = "snake_case")]
pub enum ServiceTier {
    /// Full access — the controller / authenticated operator.
    #[default]
    All,
    /// Analytics-only tier — read + analytical queries, no mutations.
    Analytics,
    /// Read-only tier — passive observation only. The strictest tier.
    ReadOnly,
}

/// A tool invocable by an LLM through function calling.
///
/// Why: Replaces hardcoded string-match dispatch with polymorphic execution.
///      Living in `trusty-agents-common` (not in `trusty-agents`) so external agent
///      crates can implement it without depending on the full host crate,
///      breaking the cargo dependency cycle.
/// What: Supplies OpenAI-compatible JSON schema via `schema()` and executes
///       parsed arguments in `execute()`. Returns a structured `ToolResult`
///       so failures can be surfaced back to the LLM without tearing down
///       the loop.
/// Test: See unit tests in `trusty-agents/tools/mod.rs` for `ToolRegistry`.
#[async_trait]
pub trait ToolExecutor: Send + Sync {
    /// Tool name — must match `function.name` in the schema and the LLM's
    /// `tool_call.name`.
    fn name(&self) -> &str;

    /// Full OpenAI-compatible tool schema object (`{"type":"function", ...}`).
    fn schema(&self) -> Value;

    /// Execute the tool with already-parsed JSON arguments.
    ///
    /// Why: Returning `ToolResult` rather than `Result<String>` means
    ///      transient / user-visible failures (missing arg, HTTP 500, refused
    ///      command) flow back to the LLM as structured errors instead of
    ///      aborting the whole turn.
    /// What: Returns `ToolResult::Success` on success or `ToolResult::Error`
    ///       on failure.
    /// Test: Each concrete impl has tests; registry dispatches through this.
    async fn execute(&self, args: Value) -> ToolResult;

    /// Tiers that are NOT permitted to invoke this tool.
    ///
    /// Why: RBAC at the dispatch boundary; see `ServiceTier`.
    /// What: Default returns empty (no restriction). Concrete tools override.
    /// Test: exercised by `trusty-agents`'s `tools/mod::filter_tools_for_user_*`.
    fn restricted_tiers(&self) -> &[ServiceTier] {
        &[]
    }

    /// Whether this tool is `AlwaysOn` or `OnDemand`.
    ///
    /// Why: Always-on tools run automatically before each LLM call; on-demand
    ///      tools appear in the LLM's tool list. See `ToolExecutionTier`.
    /// What: Default returns `OnDemand`.
    /// Test: exercised by `trusty-agents`'s `tools/always_on::build_live_context_*`.
    fn execution_tier(&self) -> ToolExecutionTier {
        ToolExecutionTier::OnDemand
    }

    /// The OpenRPC scope this tool was discovered under (trusty-agents #453,
    /// #3208), e.g. `"google.gmail.read"`.
    ///
    /// Why: Only tools sourced from the OpenRPC tool registry (endpoints like
    ///      `gworkspace`, `trusty-memory`) carry a meaningful scope —
    ///      in-process tools (git, delegate_to_agent, shell, ...) are gated
    ///      entirely by the existing name/glob allowlist + RBAC-tier checks
    ///      and have no scope concept. Defaulting to `None` means "not part
    ///      of the scoped surface, not subject to scope-pattern gating"
    ///      rather than "unscoped == open" — callers that DO consult scopes
    ///      only apply the check when this returns `Some`.
    /// What: Default returns `None`. `RegistryToolExecutor` overrides this
    ///       with its `DiscoveredTool`'s `scope` field.
    /// Test: `trusty-agents/tools/registry/adapter` round-trips the override;
    ///       `trusty-agents/ctrl/pm_task/dispatch/persona::filter_persona_tool_names_*`
    ///       covers the enforcement consumer.
    fn scope(&self) -> Option<&str> {
        None
    }
}

/// Named bundle of `ToolExecutor`s for a specific persona.
///
/// Why: Replaces hard-coded persona-to-tool branches in `trusty-agents`'s
///      `ctrl/mod.rs` with a data-driven injection point. New agent crates
///      register by adding themselves to the plugin list constructed in
///      `trusty-agents`'s `main.rs`; ctrl never needs to learn their names.
///      Lives here (not in `trusty-agents`) so agent crates can construct one
///      without depending on the host.
/// What: Holds the persona name the plugin's tools apply to plus an
///       `Arc<dyn ToolExecutor>` per tool. Cloning is cheap (Arc reference
///       counts) so the plugin can be reused across sessions.
/// Test: `cargo test -p cto-assistant agent_plugin_targets_cto_assistant`.
#[derive(Clone)]
pub struct AgentPlugin {
    /// Persona name (e.g. `"cto-assistant"`) this plugin's tools belong to.
    pub persona_name: String,
    /// Tool executors to register when the named persona becomes active.
    pub tools: Vec<Arc<dyn ToolExecutor>>,
}

impl AgentPlugin {
    /// Construct a plugin for the named persona.
    ///
    /// Why: Single canonical constructor keeps callers from accidentally
    ///      leaving fields uninitialised when the struct grows.
    /// What: Stores the persona name (converting `impl Into<String>` so
    ///       call sites can pass `&str` literals) and the tool vector.
    /// Test: Indirectly via `cto_assistant::agent_plugin()`.
    pub fn new(persona_name: impl Into<String>, tools: Vec<Arc<dyn ToolExecutor>>) -> Self {
        Self {
            persona_name: persona_name.into(),
            tools,
        }
    }
}