Skip to main content

zeph_common/
policy.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4//! Policy LLM client trait and minimal message types.
5//!
6//! Defines the interface used by `zeph-tools` adversarial policy validation,
7//! moved here to keep `zeph-tools` decoupled from `zeph-llm`.
8
9use std::future::Future;
10use std::pin::Pin;
11
12/// Minimal message type for policy LLM calls.
13///
14/// Uses a dedicated type rather than importing `zeph-llm::Message` to keep
15/// `zeph-common` free of `zeph-*` dependencies.
16#[derive(Debug, Clone)]
17pub struct PolicyMessage {
18    /// Role of the message sender.
19    pub role: PolicyRole,
20    /// Message content.
21    pub content: String,
22}
23
24/// Role for a [`PolicyMessage`].
25#[derive(Debug, Clone, Copy, PartialEq, Eq)]
26pub enum PolicyRole {
27    /// System-level instruction.
28    System,
29    /// User-level prompt.
30    User,
31}
32
33/// Trait for sending chat messages to the policy LLM.
34///
35/// Implemented externally (e.g. in `runner.rs` on a newtype wrapping `Arc<AnyProvider>`).
36/// `zeph-tools` defines the usage; `zeph-common` defines the contract, keeping both
37/// crates decoupled from `zeph-llm`.
38pub trait PolicyLlmClient: Send + Sync {
39    /// Send a sequence of messages and return the assistant's text response.
40    ///
41    /// # Errors
42    ///
43    /// Returns `Err(String)` if the LLM call fails (network error, timeout, etc.).
44    fn chat<'a>(
45        &'a self,
46        messages: &'a [PolicyMessage],
47    ) -> Pin<Box<dyn Future<Output = Result<String, String>> + Send + 'a>>;
48}