Skip to main content

ag_ui/
context.rs

1//! Additional context handed to an agent alongside the messages.
2
3use serde::{Deserialize, Serialize};
4
5/// One piece of ambient context for a run.
6///
7/// Contexts are free-form label/value pairs — the current page a user is on,
8/// a selected record, a feature flag — that the agent may fold into its prompt
9/// without them appearing as conversation messages.
10#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
11#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
12#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
13pub struct Context {
14    /// What this value is, in words the model can use.
15    pub description: String,
16    /// The value itself, already rendered to a string.
17    pub value: String,
18}
19
20impl Context {
21    /// Builds a context entry.
22    pub fn new(description: impl Into<String>, value: impl Into<String>) -> Self {
23        Self {
24            description: description.into(),
25            value: value.into(),
26        }
27    }
28}