Implementation:AI Shell Team Aish LlmSession process input
| 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);