@ngaf/langgraph
v0.0.46
Published
Adapter that wraps a LangGraph agent into the runtime-neutral `Agent` contract from `@ngaf/chat`. The Angular equivalent of LangGraph's React `useStream()` hook — signal-driven access to messages, status, tool calls, interrupts, subagents, regenerate, and
Readme
@ngaf/langgraph
Adapter that wraps a LangGraph agent into the runtime-neutral Agent contract from @ngaf/chat. The Angular equivalent of LangGraph's React useStream() hook — signal-driven access to messages, status, tool calls, interrupts, subagents, regenerate, and thread history.
Part of Agent UI for Angular. MIT licensed.
Install
npm install @ngaf/langgraph @ngaf/chatPeer dependencies: @angular/core ^20.0.0 || ^21.0.0, @langchain/core ^1.1.0, @langchain/langgraph-sdk ^1.7.0, rxjs ~7.8.0
What it does
agent()— Angular Signal-based handle to a LangGraph streaming run. Returnsmessages(),status(),isLoading(),error(),interrupt(),toolCalls(), plus actions (submit,stop,regenerate,reload).provideAgent()— configure the LangGraph endpoint once inapp.config.ts. Per-call overrides are accepted byagent()itself.- Thread persistence — pass
threadId: signal(...)+onThreadIdto round-trip thread IDs through your own storage (localStorage, URL, etc.). MockAgentTransport— deterministic in-memory transport for tests. Never mockagent()itself; swap the transport instead.extractCitations()— populatesMessage.citationsfrom LangGraph message metadata. Reads fromadditional_kwargs.citations(preferred) oradditional_kwargs.sources(fallback).
Quick start
// app.config.ts
import { provideAgent } from '@ngaf/langgraph';
export const appConfig: ApplicationConfig = {
providers: [
provideAgent({
apiUrl: 'https://your-langgraph-platform.com',
}),
],
};// chat.component.ts
import { Component } from '@angular/core';
import { agent } from '@ngaf/langgraph';
import { ChatComponent } from '@ngaf/chat';
@Component({
imports: [ChatComponent],
template: `<chat [agent]="chat" />`,
})
export class ChatComponentHost {
chat = agent({
apiUrl: 'https://your-langgraph-platform.com',
assistantId: 'my-agent',
});
}
agent()must be called within an Angular injection context (component field initializer or constructor). Calling it inngOnInitor any async context throwsNG0203: inject() must be called from an injection context.
Citations example
// In your LangGraph node:
const response = await llm.invoke([...]);
return new AIMessage({
content: response.content,
additional_kwargs: {
citations: [
{
id: 'doc-1',
index: 1,
title: 'Example Article',
url: 'https://example.com/article',
snippet: 'Relevant excerpt...',
},
],
},
});
// Message.citations auto-populates in @ngaf/chat via extractCitations()Documentation
- Quickstart
agent()API reference- Human-in-the-loop / interrupts
- Thread persistence
- Testing with
MockAgentTransport
License
MIT — free for any use. See LICENSE.
