Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI Shell Team Aish LlmSession new

From Leeroopedia
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);

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment