# LangGraphAgent

Package: `@threadplane/langgraph` · 0.3.4

Reference: /docs/api/langgraph/LangGraphAgent

```typescript
import type { LangGraphAgent } from '@threadplane/langgraph';
```

## LangGraphAgent

Unified LangGraph agent surface returned by `injectAgent()`.

Extends the runtime-neutral `AgentWithHistory` contract (chat-consumable)
with the full LangGraph-specific API. One object drives both `<chat>` and
any LangGraph-specific demo. Raw LangGraph signals are prefixed with
`langGraph` to avoid collision with the runtime-neutral names.

```typescript
export interface LangGraphAgent<T = unknown, ResolvedBag extends BagTemplate = BagTemplate> extends AgentWithHistory<T>  {
  activeSubagents: Signal<SubagentStreamRef[]>;
  branch: Signal<string>;
  clientTools: ClientToolsCapability;
  customEvents: Signal<CustomStreamEvent[]>;
  experimentalBranchTree: Signal<AgentBranchTree<T>>;
  getMessagesMetadata: (msg: BaseMessage, idx?: number) => MessageMetadata<Record<string, unknown>> | undefined;
  getSubagent: (toolCallId: string) => SubagentStreamRef | undefined;
  getSubagentsByMessage: (msg: CoreAIMessage) => SubagentStreamRef[];
  getSubagentsByType: (type: string) => SubagentStreamRef[];
  getToolCalls: (msg: CoreAIMessage) => ToolCallWithResult[];
  hasValue: Signal<boolean>;
  interrupt: Signal<AgentInterrupt | undefined>;
  isThreadLoading: Signal<boolean>;
  joinStream: (runId: string, lastEventId?: string) => Promise<void>;
  langGraphHistory: Signal<ThreadState<T>[]>;
  langGraphInterrupts: Signal<Interrupt<ResolvedBag['InterruptType']>[]>;
  langGraphMessages: Signal<BaseMessage[]>;
  langGraphToolCalls: Signal<ToolCallWithResult[]>;
  lifecycle: AgentLifecycle;
  queue: Signal<AgentQueue>;
  regenerate: (assistantMessageIndex: number) => Promise<void>;
  reload: () => void;
  setBranch: (branch: string) => void;
  submit: (input: AgentSubmitInput | null | undefined, opts?: AgentSubmitOptions & LangGraphSubmitOptions) => Promise<void>;
  switchThread: (threadId: string | null) => void;
  toolProgress: Signal<ToolProgress[]>;
  value: Signal<T>;
}
```

### activeSubagents

Filtered list of subagents with status 'running'.

```typescript
activeSubagents: Signal<SubagentStreamRef[]>;
```

### branch

Current branch identifier for time-travel navigation.

```typescript
branch: Signal<string>;
```

### clientTools

Client-declared, client-executed tools. Call setCatalog() to register
tool specs; the catalog is automatically shipped with every run via
`input.client_tools`. Pending tool calls appear in pending() after
the run ends; resolve() returns a result and continues the run.

```typescript
clientTools: ClientToolsCapability;
```

### customEvents

Raw custom events stream (signal of array). The runtime-neutral
 `events$` Observable is derived from this.

```typescript
customEvents: Signal<CustomStreamEvent[]>;
```

### experimentalBranchTree

Experimental branch tree derived from LangGraph checkpoint history.

```typescript
experimentalBranchTree: Signal<AgentBranchTree<T>>;
```

### getMessagesMetadata

Get metadata for a specific message by index.

```typescript
getMessagesMetadata: (msg: BaseMessage, idx?: number) => MessageMetadata<Record<string, unknown>> | undefined;
```

### getSubagent

Get a subagent stream by the tool call ID that spawned it.

```typescript
getSubagent: (toolCallId: string) => SubagentStreamRef | undefined;
```

### getSubagentsByMessage

Get subagent streams spawned by the tool calls on a specific AI message.

```typescript
getSubagentsByMessage: (msg: CoreAIMessage) => SubagentStreamRef[];
```

### getSubagentsByType

Get subagent streams by their configured subagent type/name.

```typescript
getSubagentsByType: (type: string) => SubagentStreamRef[];
```

### getToolCalls

Get tool call results associated with an AI message (LangGraph types).

```typescript
getToolCalls: (msg: CoreAIMessage) => ToolCallWithResult[];
```

### hasValue

True once at least one value or message has been received.

```typescript
hasValue: Signal<boolean>;
```

### interrupt

Current human-in-the-loop pause, or `undefined` when the run is not paused.

Narrowed from the neutral `Agent` contract, where `interrupt` is optional
because a runtime without human-in-the-loop support omits it. The LangGraph
adapter always provides it, so `injectAgent().interrupt()` type-checks
directly under `strictNullChecks` — no `?.()` needed.

```typescript
interrupt: Signal<AgentInterrupt | undefined>;
```

### isThreadLoading

True while a thread switch is loading state from the server.

```typescript
isThreadLoading: Signal<boolean>;
```

### joinStream

Join an already-running stream by run ID.

```typescript
joinStream: (runId: string, lastEventId?: string) => Promise<void>;
```

### langGraphHistory

Raw LangGraph history (ThreadState[]). Use `history` for AgentCheckpoint[].

```typescript
langGraphHistory: Signal<ThreadState<T>[]>;
```

### langGraphInterrupts

All interrupts received during the current run (raw LangGraph shape).

```typescript
langGraphInterrupts: Signal<Interrupt<ResolvedBag['InterruptType']>[]>;
```

### langGraphMessages

Raw LangChain BaseMessage list. Use `messages` for chat rendering.

```typescript
langGraphMessages: Signal<BaseMessage[]>;
```

### langGraphToolCalls

Raw LangGraph tool calls (with run-state). Use `toolCalls` for chat rendering.

```typescript
langGraphToolCalls: Signal<ToolCallWithResult[]>;
```

### lifecycle

Lifecycle signals for observability/telemetry. Eight read-only signals
capture key transitions (first stream chunk, first interrupt, tool
call start/complete, thread create/persist, errors). All reset on
`switchThread()`. See [AgentLifecycle](/docs/api/langgraph/AgentLifecycle).

```typescript
lifecycle: AgentLifecycle;
```

### queue

Pending server-side runs created via `multitaskStrategy: 'enqueue'`.

```typescript
queue: Signal<AgentQueue>;
```

### regenerate

Discards the assistant message at the given index AND all messages after
it, then re-runs the agent against the trimmed conversation tail. The
preceding user message (at index - 1) is preserved and re-submitted as
the agent's input. No new user message is added to the history.

Throws if the message at `index` is not 'assistant' role, or if the
agent is currently loading another response.

```typescript
regenerate: (assistantMessageIndex: number) => Promise<void>;
```

### reload

Re-submit the last input to restart the stream.

```typescript
reload: () => void;
```

### setBranch

Set the active branch for time-travel navigation.

```typescript
setBranch: (branch: string) => void;
```

### submit

Submit input, resume commands, checkpoint forks, or other LangGraph run options.

```typescript
submit: (input: AgentSubmitInput | null | undefined, opts?: AgentSubmitOptions & LangGraphSubmitOptions) => Promise<void>;
```

### switchThread

Switch to a different thread, resetting derived state.

```typescript
switchThread: (threadId: string | null) => void;
```

### toolProgress

Progress updates for currently executing tools.

```typescript
toolProgress: Signal<ToolProgress[]>;
```

### value

Current agent state values (raw, typed per the type parameter T).

```typescript
value: Signal<T>;
```