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 process input

From Leeroopedia
Knowledge Sources
Domains LLM, Agent_Architecture
Last Updated 2026-10-29 00:00 GMT

Overview

Concrete tool for orchestrating the iterative LLM tool-calling loop from user input to final response provided by the aish-llm crate.

Description

The LlmSession::process_input method is the core entry point for agentic interaction. It assembles the prompt, sends the message to the LLM, and enters a tool-calling loop: for each LLM response with tool calls, it normalizes the calls, runs security preflight, executes each tool, appends results as messages, and sends the updated conversation back to the LLM. The loop continues until the LLM responds with text only (no tool calls) or the maximum iteration limit (default 20) is reached.

The method emits LlmEvent events at each step for real-time UI rendering (streaming text, tool calls, tool results). A cancellation token allows the user to interrupt the loop at any iteration. It also tracks token usage and integrates with Langfuse tracing.

Usage

Call this method when the user submits input to the AI shell. It handles the entire agentic cycle: prompt assembly, LLM calls, tool execution, security checks, and result feedback.

Code Reference

Source Location

  • Repository: aish
  • File: crates/aish-llm/src/session.rs

Signature

impl LlmSession {
    pub async fn process_input(
        &self,
        user_msg: &ChatMessage,
        context_messages: &[ChatMessage],
        system_message: Option<&str>,
        stream: bool,
    ) -> Result<ProcessResult, AishError>
}

pub struct ProcessResult {
    pub text: String,           // Final assistant text
    pub messages: Vec<ChatMessage>, // New messages from this turn
    pub tool_calls: Vec<ToolCallRecord>,
}

Import

use aish_llm::{LlmSession, ChatMessage, ProcessResult};

I/O Contract

Inputs

Name Type Required Description
user_msg &ChatMessage Yes User's input message
context_messages &[ChatMessage] Yes Prior conversation context
system_message Option<&str> No System prompt override
stream bool Yes SSE streaming flag

Outputs

Name Type Description
return Result<ProcessResult, AishError> Final assistant text, new messages, tool call records

Usage Examples

Processing User Input

use aish_llm::{LlmSession, ChatMessage};

let session = LlmSession::new(
    "https://api.openai.com/v1",
    "sk-...",
    "gpt-4",
    Some(0.7),
    Some(4096),
);

let user_msg = ChatMessage::user("List all Python files in the current directory");
let result = session.process_input(
    &user_msg,
    &context_messages,
    None,  // use default system prompt
    true,  // SSE streaming
).await?;

println!("{}", result.text);

Related Pages

Implements Principle

Requires Environment

Page Connections

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