# Class ContextPruner

Handles context pruning with multiple strategies.

- Defined in packages/nexus-agents/src/agents/context-pruner.ts:96

##### Index

### Constructors

constructor

### Methods

shouldPrune
prune
pruneCategory
getPruneCandidates
estimateFreeableTokens

## Constructors

### constructor

- new ContextPruner(config: ContextPrunerConfig): ContextPruner

  #### Parameters

  - config: ContextPrunerConfig

  #### Returns ContextPruner

  - Defined in packages/nexus-agents/src/agents/context-pruner.ts:105

## Methods

### shouldPrune

- shouldPrune(): boolean

  Check if pruning should be triggered based on usage threshold.

  #### Returns boolean

  - Defined in packages/nexus-agents/src/agents/context-pruner.ts:127

### prune

- prune(options?: PruneOptions): Promise<Result<PruneResult, ValidationError>>

  Prune context to free tokens or reach target capacity.

  #### Parameters

  - options: PruneOptions = {}

  #### Returns Promise<Result<PruneResult, ValidationError>>

  - Defined in packages/nexus-agents/src/agents/context-pruner.ts:132

### pruneCategory

- pruneCategory(
  category: "system" | "task" | "active",
  targetTokens: number,
  ): Promise<Result<PruneResult, ValidationError>>

  Prune items from a specific category.

  #### Parameters

  - category: "system" | "task" | "active"
  - targetTokens: number

  #### Returns Promise<Result<PruneResult, ValidationError>>

  - Defined in packages/nexus-agents/src/agents/context-pruner.ts:176

### getPruneCandidates

- getPruneCandidates(categories: ("system" | "task" | "active")[]): ContextItem[]

  Get candidates for pruning from specified categories.

  #### Parameters

  - categories: ("system" | "task" | "active")[]

  #### Returns ContextItem[]

  - Defined in packages/nexus-agents/src/agents/context-pruner.ts:184

### estimateFreeableTokens

- estimateFreeableTokens(categories: ("system" | "task" | "active")[]): number

  Estimate tokens that can be freed from specified categories.

  #### Parameters

  - categories: ("system" | "task" | "active")[]

  #### Returns number

  - Defined in packages/nexus-agents/src/agents/context-pruner.ts:193