pub struct AgentSession {Show 15 fields
pub cwd: PathBuf,
pub messages: Vec<Message>,
pub system_prompt: String,
pub model: Model,
pub thinking: ThinkingLevel,
pub tools: Vec<Arc<dyn AgentTool>>,
pub client: Client,
pub gate: Arc<dyn ToolGate>,
pub api_key: Option<String>,
pub auth_token: Option<String>,
pub session_file: Option<PathBuf>,
pub total_usage: Usage,
pub max_tokens: Option<usize>,
pub cache_control: bool,
pub compact_model: Option<Model>,
}Fields§
§cwd: PathBuf§messages: Vec<Message>§system_prompt: String§model: Model§thinking: ThinkingLevel§tools: Vec<Arc<dyn AgentTool>>§client: Client§gate: Arc<dyn ToolGate>§api_key: Option<String>§auth_token: Option<String>§session_file: Option<PathBuf>§total_usage: Usage§max_tokens: Option<usize>Override the model’s default output-token cap, if set.
cache_control: boolAttach Anthropic prompt-caching markers. Default true (--no-cache flips it).
compact_model: Option<Model>Override the model used for background compaction summaries. None
(default) resolves via Self::default_compact_model — the cheapest
tier (haiku), or PIXIE_PI_COMPACT_MODEL. Pinned per-session in tests.
Implementations§
Source§impl AgentSession
impl AgentSession
Sourcepub fn new(
cwd: PathBuf,
system_prompt: String,
model: Model,
thinking: ThinkingLevel,
tools: Vec<Arc<dyn AgentTool>>,
client: Client,
) -> Self
pub fn new( cwd: PathBuf, system_prompt: String, model: Model, thinking: ThinkingLevel, tools: Vec<Arc<dyn AgentTool>>, client: Client, ) -> Self
Construct a session from its core parts, with sensible defaults for token caps, caching, the allow-all gate, and an empty transcript.
Sourcepub fn stream_options(&self) -> SimpleStreamOptions
pub fn stream_options(&self) -> SimpleStreamOptions
Build the streaming options for the current model + thinking level.
Sourcepub fn run(
&self,
prompts: Vec<Message>,
cancel: CancellationToken,
) -> AgentEventStream
pub fn run( &self, prompts: Vec<Message>, cancel: CancellationToken, ) -> AgentEventStream
Start an agent run for the given prompt messages.
Sourcepub fn estimated_tokens(&self) -> usize
pub fn estimated_tokens(&self) -> usize
Estimated token count of the current transcript.
Sourcepub fn context_usage(&self) -> f64
pub fn context_usage(&self) -> f64
Token-budget fraction used (0.0–1.0+).
Sourcepub fn should_compact(&self) -> bool
pub fn should_compact(&self) -> bool
True when the transcript exceeds the compaction budget.
Sourcepub async fn compact(&mut self) -> usize
pub async fn compact(&mut self) -> usize
Compaction: summarize the oldest messages (cut at a user boundary) and replace them with the summary, keeping the recent tail. Falls back to a plain “messages dropped” note if the model is unavailable or fails, so compaction always reduces the transcript and never hard-fails. Returns the number of messages dropped.
Sourcepub fn add_usage(&mut self, usage: &Usage)
pub fn add_usage(&mut self, usage: &Usage)
Accumulate usage from a turn into the session total.