Skip to main content

causa_kernel/context/model/
value.rs

1//! Fact vocabulary of the model door — what the fact machine validates and
2//! records. The gateway envelope (`ModelOutput`), the transport error, and
3//! request parameters (`ModelRef`, `GenerationOptions`, `ToolSurface`) are
4//! port vocabulary and live in `crate::ports::gateway`.
5
6use serde::{Deserialize, Serialize};
7
8use crate::context::block::TextPayload;
9
10/// A tool call as the model proposed it, before the caller assigns its declaration `BlockId`. Exactly what the gateway parsed off the wire.
11#[derive(Debug, Clone, Default, Serialize, Deserialize)]
12pub struct ToolCallDraft {
13    /// Name of the tool the model asked to invoke.
14    pub tool_name: String,
15    /// Tool arguments as a JSON object; validated by the kernel before commit.
16    pub arguments: serde_json::Value,
17    /// Provider-issued identifier for this tool call, if the upstream model
18    /// API assigned one. The kernel records it verbatim (on the envelope
19    /// `BlockMeta`) and pairs tool results by the declaration `BlockId`, never by this field.
20    /// `ToolCallId` remains a borrowed content key for concurrent deduplication.
21    #[serde(default)]
22    pub provider_call_id: Option<String>,
23}
24
25/// Why the model stopped producing output for this round, as reported by
26/// the gateway. The kernel validates only the EndTurn/ToolUse structural
27/// pairing; interpreting terminal reasons is driver policy.
28#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
29#[serde(rename_all = "snake_case")]
30pub enum ModelStopReason {
31    /// The model ended its turn without requesting tools; `tool_calls` must
32    /// be empty.
33    EndTurn,
34    /// The model requested tool invocations; `tool_calls` must be non-empty.
35    ToolUse,
36    /// Output was cut off at the token limit.
37    MaxTokens,
38    /// The model (or a provider content filter) refused to produce output.
39    Refusal,
40}
41
42/// The model door's fact shape: what the model said (text) and asked (tool
43/// calls). Named for the participant, not for any wire role.
44#[derive(Debug, Clone, Serialize, Deserialize)]
45pub struct ModelResponse {
46    /// What the model said. Blank text produces no fact block on commit.
47    pub text: TextPayload,
48    /// What the model asked for, in its draft order; ids are assigned at
49    /// commit.
50    pub tool_calls: Vec<ToolCallDraft>,
51}