Skip to main content

platonic_core/
tool.rs

1//! Tool-call and tool-result boundary types.
2
3use crate::{ArtifactId, EffectClass, ToolCallId, ToolName};
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6
7/// A model-authored tool proposal before host validation.
8#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
9#[serde(deny_unknown_fields)]
10pub struct ToolProposal {
11    /// Registered tool name requested by the model.
12    pub tool: ToolName,
13    /// JSON input to validate against the registered schema.
14    pub input: Value,
15}
16
17/// A host-validated tool invocation evaluated by policy.
18#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
19#[serde(deny_unknown_fields)]
20pub struct ToolCall {
21    /// Stable call id assigned by the harness.
22    pub id: ToolCallId,
23    /// Registered tool name.
24    pub tool: ToolName,
25    /// Host/registry-declared effect class.
26    pub effect: EffectClass,
27    /// JSON input validated against the registered tool schema.
28    pub input: Value,
29}
30
31/// Controls which audience sees a tool result.
32#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
33#[serde(rename_all = "snake_case")]
34pub enum ResultVisibility {
35    /// Only model receives it.
36    Model,
37    /// Only user-facing transcript receives it.
38    User,
39    /// Model and user-facing transcript both receive it.
40    Both,
41}
42
43/// Structured tool result; raw output should be kept as an artifact when large.
44#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
45#[serde(deny_unknown_fields)]
46pub struct ToolResult {
47    /// Tool call this result answers.
48    pub call_id: ToolCallId,
49    /// Short model-usable summary.
50    pub summary: String,
51    /// Structured data result.
52    pub data: Value,
53    /// Artifacts created or referenced by this result.
54    pub artifacts: Vec<ArtifactId>,
55    /// Visibility boundary for this result.
56    pub visibility: ResultVisibility,
57}