objectiveai_sdk/agent/openrouter/context_compression.rs
1//! Context compression engine for OpenRouter long-context requests.
2
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6/// Which context-compression engine to enable on outgoing OpenRouter
7/// chat-completions requests. Maps onto OpenRouter's request-body
8/// `plugins` array — see <https://openrouter.ai/docs/features/middle-out>.
9#[derive(
10 Debug,
11 Clone,
12 Copy,
13 PartialEq,
14 Serialize,
15 Deserialize,
16 JsonSchema,
17 arbitrary::Arbitrary,
18)]
19#[schemars(rename = "agent.openrouter.ContextCompression")]
20pub enum ContextCompression {
21 /// Middle-out compression — drops content from the middle of the
22 /// conversation when the request would otherwise exceed the
23 /// model's context window. The only engine documented today.
24 ///
25 /// Intentionally no `#[schemars(title)]` here: the builder's
26 /// single-variant-anyOf flatten merges the variant's title onto
27 /// the parent schema, clobbering the enum's `agent.openrouter
28 /// .ContextCompression` rename. Add a per-variant title only
29 /// once a second variant lands.
30 #[serde(rename = "middle-out")]
31 MiddleOut,
32}
33
34impl ContextCompression {
35 /// Hook used during agent ID computation. There's no default-to-
36 /// collapse for this field — every variant is meaningful — so we
37 /// pass the value through unchanged.
38 pub fn prepare(self) -> Option<Self> {
39 Some(self)
40 }
41
42 /// Validates the setting (always succeeds — every variant is
43 /// inhabited by a documented OpenRouter engine).
44 pub fn validate(&self) -> Result<(), String> {
45 Ok(())
46 }
47}