Implementation:AI Shell Team Aish LlmSession new
| Knowledge Sources | |
|---|---|
| Domains | LLM, Session_Management |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Concrete tool for reconstructing an LLM session from persisted credentials with API dialect resolution provided by the aish-llm crate.
= Description
The LlmSession::new constructor creates a new session from API credentials (api_base, api_key, model) and optional parameters (temperature, max_tokens). It internally creates a StreamContext, resolves the API dialect for the model and endpoint, and initializes the session state: empty tool registry, fresh cancellation token, token stats, plan mode state, and context budget.
The with_context constructor accepts a pre-built StreamContext for cases where the caller needs to control the context creation (e.g., setting a codex_auth_path).
Usage
Call this constructor when creating a new session or resuming one from stored credentials. After construction, register tools and wire up the context manager.
Code Reference
Source Location
- Repository: aish
- File: crates/aish-llm/src/session.rs
Signature
impl LlmSession {
pub fn new(
api_base: &str,
api_key: &str,
model: &str,
temperature: Option<f64>,
max_tokens: Option<u32>,
) -> Self
pub fn with_context(
stream_ctx: StreamContext,
temperature: Option<f64>,
max_tokens: Option<u32>,
) -> Self
}
Import
use aish_llm::LlmSession;
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| api_base | &str | Yes | Provider API endpoint URL |
| api_key | &str | Yes | Authentication key |
| model | &str | Yes | Model name |
| temperature | Option<f64> | No | Sampling temperature |
| max_tokens | Option<u32> | No | Max response tokens |
Outputs
| Name | Type | Description |
|---|---|---|
| return | LlmSession | Initialized session with resolved dialect, empty tools, fresh state |
Usage Examples
Session Reconstruction on Resume
use aish_llm::LlmSession;
// Reconstruct from saved session record
let session = LlmSession::new(
&session_record.api_base(),
&session_record.api_key(),
&session_record.model,
Some(0.7),
Some(4096),
);
// Register tools
session.register_tool(bash_tool);
session.register_tool(read_file_tool);