vtcode_config/core/advisor.rs
1//! Configuration for the Claude Advisor server-side tool.
2//!
3//! The advisor pairs a faster executor model with a higher-intelligence advisor
4//! model that provides strategic guidance mid-generation. The advisor runs as an
5//! Anthropic server-side tool and is therefore only honored for Anthropic models
6//! and providers.
7
8use serde::{Deserialize, Serialize};
9
10/// Cache lifetime for the advisor's own transcript across calls in a conversation.
11#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
13pub enum AdvisorCacheTtl {
14 /// 5 minute cache lifetime.
15 #[serde(rename = "5m")]
16 FiveMinutes,
17 /// 1 hour cache lifetime.
18 #[serde(rename = "1h")]
19 OneHour,
20}
21
22impl AdvisorCacheTtl {
23 /// Returns the wire string for the `ttl` field.
24 pub fn as_str(self) -> &'static str {
25 match self {
26 Self::FiveMinutes => "5m",
27 Self::OneHour => "1h",
28 }
29 }
30}
31
32/// Enables prompt caching for the advisor's own transcript across calls within a
33/// conversation. This is an on/off switch, not a cache-control breakpoint.
34#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
35#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
36pub struct AdvisorCachingConfig {
37 /// Whether advisor-side prompt caching is enabled.
38 #[serde(default = "default_advisor_caching_enabled")]
39 pub enabled: bool,
40 /// Cache lifetime for the advisor transcript.
41 #[serde(default = "default_advisor_cache_ttl")]
42 pub ttl: AdvisorCacheTtl,
43}
44
45impl Default for AdvisorCachingConfig {
46 fn default() -> Self {
47 Self {
48 enabled: default_advisor_caching_enabled(),
49 ttl: default_advisor_cache_ttl(),
50 }
51 }
52}
53
54#[inline]
55const fn default_advisor_caching_enabled() -> bool {
56 false
57}
58
59#[inline]
60fn default_advisor_cache_ttl() -> AdvisorCacheTtl {
61 AdvisorCacheTtl::FiveMinutes
62}
63
64/// Configuration for the Claude Advisor server-side tool.
65///
66/// The advisor tool is only valid for Anthropic providers and models. When
67/// `enabled` is `true`, vtcode injects an `advisor_20260301` tool into the
68/// Anthropic request and sends the `advisor-tool-2026-03-01` beta header. The
69/// executor model must form a valid pair with the configured advisor model
70/// (see `vtcode_config::constants::models::anthropic::advisor_compatibility`).
71#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
72#[derive(Debug, Clone, Serialize, Deserialize)]
73pub struct AdvisorConfig {
74 /// Master toggle for the Anthropic server-side advisor tool.
75 #[serde(default = "default_advisor_enabled")]
76 pub enabled: bool,
77
78 /// Advisor model id (must be an Anthropic/Claude model at least as capable
79 /// as the executor). Empty or omitted falls back to a sensible default
80 /// advisor for the executor model.
81 #[serde(default)]
82 pub model: String,
83
84 /// Maximum number of advisor invocations per request. `None` means
85 /// unlimited (the API default). Once the executor reaches this cap, further
86 /// advisor calls return an `advisor_tool_result_error`.
87 #[serde(default)]
88 pub max_uses: Option<u32>,
89
90 /// Caps the advisor's total output (thinking plus text) per call. Minimum
91 /// 1024. `None` lets the advisor model choose its own output cap.
92 #[serde(default)]
93 pub max_tokens: Option<u32>,
94
95 /// Enables prompt caching for the advisor's own transcript across calls
96 /// within a conversation. Only worthwhile for long agent loops (three or
97 /// more expected advisor calls).
98 #[serde(default)]
99 pub caching: Option<AdvisorCachingConfig>,
100}
101
102impl Default for AdvisorConfig {
103 fn default() -> Self {
104 Self {
105 enabled: default_advisor_enabled(),
106 model: String::new(),
107 max_uses: None,
108 max_tokens: None,
109 caching: None,
110 }
111 }
112}
113
114#[inline]
115const fn default_advisor_enabled() -> bool {
116 false
117}