# What Is the Maximum Session Prompt Length in OpenMAIC?

> Discover the maximum session prompt length in OpenMAIC. Learn about the 2048 character limit and where it's defined in the workbench source code to optimize your interactions.

- Repository: [MAIC/OpenMAIC](https://github.com/THU-MAIC/OpenMAIC)
- Tags: api-reference
- Published: 2026-09-09

---

**The maximum session prompt length in OpenMAIC is 2,048 characters, enforced by the `SESSION_PROMPT_MAX_CHARS` constant defined in the workbench source code.**

The OpenMAIC workbench caps initial session prompts to preserve model token budgets and prevent excessive memory consumption. When working with the THU-MAIC/OpenMAIC repository, developers interact with this limit through the session management API, which automatically truncates any input exceeding the boundary.

## Where the Limit Is Defined

According to the OpenMAIC source code, the limit is hard-coded as a TypeScript constant in the session prompt utility module. In [`lib/workbench/session-prompt.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/workbench/session-prompt.ts), the repository exports:

```typescript
export const SESSION_PROMPT_MAX_CHARS = 2048;

```

This value is referenced throughout the workbench whenever a new session is created or an existing prompt is updated, establishing the definitive maximum session prompt length for the entire system.

## How the Limit Is Enforced

When a user initiates a session via the `session_start` event, the backend validates the supplied prompt against `SESSION_PROMPT_MAX_CHARS`. If the input exceeds the maximum session prompt length, the system automatically truncates it to the first 2,048 characters before persisting it to session metadata.

### The normalisePrompt Function

The normalization logic resides in the `normalisePrompt` function within [`lib/workbench/session-prompt.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/workbench/session-prompt.ts). This helper trims whitespace and applies the character ceiling:

```typescript
/**
 * Normalise and enforce the maximum prompt length.
 */
export function normalisePrompt(prompt: string): string {
  // Trim whitespace and cut off any excess characters.
  const trimmed = prompt.trim();
  return trimmed.slice(0, SESSION_PROMPT_MAX_CHARS);
}

```

### Session Start Handling

The enforcement triggers during session initialization. The `handleSessionStart` function demonstrates the validation workflow:

```typescript
// Called when a session is started
function handleSessionStart(event: SessionStartEvent) {
  const safePrompt = normalisePrompt(event.payload.prompt);
  // Store the safePrompt in session metadata …
}

```

## Key Source Files

The implementation of the maximum session prompt length spans three primary locations in the codebase:

- **[`lib/workbench/session-prompt.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/workbench/session-prompt.ts)** – Defines the `SESSION_PROMPT_MAX_CHARS` constant and exports the `normalisePrompt` helper that implements truncation.
- **[`lib/workbench/workspace-session-memory.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/workbench/workspace-session-memory.ts)** – Persists the validated prompt within session metadata after the length check.
- **[`tests/workbench/session-fold.test.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/tests/workbench/session-fold.test.ts)** – Contains unit tests verifying that prompts exceeding 2,048 characters are correctly folded to the limit.

## Summary

- OpenMAIC enforces a **2,048-character maximum** for all session initial prompts.
- The limit is defined by the constant **`SESSION_PROMPT_MAX_CHARS`** in [`lib/workbench/session-prompt.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/workbench/session-prompt.ts).
- The **`normalisePrompt`** function automatically truncates excess characters and trims whitespace.
- Validated prompts are stored via **[`workspace-session-memory.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/workspace-session-memory.ts)** to ensure compliance across the workbench.

## Frequently Asked Questions

### What happens if a session prompt exceeds 2,048 characters in OpenMAIC?

If the supplied prompt exceeds the maximum session prompt length, the `normalisePrompt` function truncates the string to the first 2,048 characters after trimming leading and trailing whitespace. The system stores this truncated version in session metadata without throwing an error, ensuring the model receives only the compliant portion.

### Where is the session prompt length limit defined in the OpenMAIC codebase?

The limit is defined in [`lib/workbench/session-prompt.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/workbench/session-prompt.ts) as the exported constant `SESSION_PROMPT_MAX_CHARS` with a hard-coded value of `2048`. This file also contains the `normalisePrompt` utility that enforces the constraint during session creation.

### Is the 2,048-character limit configurable in OpenMAIC?

Based on the current source code analysis, the maximum session prompt length is hard-coded as a constant and not exposed through configuration files or environment variables. To alter the limit, developers must modify the `SESSION_PROMPT_MAX_CHARS` value in [`lib/workbench/session-prompt.ts`](https://github.com/THU-MAIC/OpenMAIC/blob/main/lib/workbench/session-prompt.ts) and rebuild the project.

### Does OpenMAIC count whitespace toward the 2,048-character limit?

The `normalisePrompt` function first removes leading and trailing whitespace using `prompt.trim()` before applying the slice operation. While outer whitespace is discarded, internal whitespace characters within the 2,048-character window are preserved and counted toward the maximum session prompt length.