gadk_agent/context/prompt_use.rs
1// Copyright 2026 Chris Olson
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! The prompt version an agent's instruction was rendered from.
16
17/// The prompt version that produced an agent's instruction. The instruction provider records it
18/// in the invocation's context ([`ReadonlyContext::record_prompt`](crate::ReadonlyContext::record_prompt));
19/// plugins read it to attribute model calls to prompt versions.
20#[derive(Debug, Clone, PartialEq, Eq)]
21#[non_exhaustive]
22pub struct PromptUse {
23 /// The prompt name.
24 pub name: String,
25 /// The version number.
26 pub version: u32,
27 /// The label the version was selected by (`latest` for the newest version), or `None` for a
28 /// version selected by number.
29 pub label: Option<String>,
30}
31
32impl PromptUse {
33 /// Version `version` of prompt `name`, without a label.
34 pub fn new(name: impl Into<String>, version: u32) -> Self {
35 Self {
36 name: name.into(),
37 version,
38 label: None,
39 }
40 }
41
42 /// Sets the label the version was selected by.
43 pub fn with_label(mut self, label: impl Into<String>) -> Self {
44 self.label = Some(label.into());
45 self
46 }
47}
48
49#[cfg(test)]
50mod tests {
51 use super::PromptUse;
52
53 #[test]
54 fn new_has_no_label_and_with_label_sets_it() {
55 let used = PromptUse::new("triage", 3);
56 assert_eq!(
57 (used.name.as_str(), used.version, used.label.as_deref()),
58 ("triage", 3, None)
59 );
60 let labelled = used.clone().with_label("production");
61 assert_eq!(labelled.label.as_deref(), Some("production"));
62 assert_eq!(labelled.version, 3);
63 assert_ne!(used, labelled);
64 }
65}