Skip to main content

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