# LangDAG

> LLM conversation management as Directed Acyclic Graphs -- a Go alternative to LangGraph

LangDAG is a high-performance Go library and CLI for managing LLM conversations as trees of nodes. Each message (user, assistant, tool call, tool result) is a node. Prompting from any node creates a child, enabling natural branching, forking, and exploration of alternative conversation paths. It is designed as a lightweight, performant alternative to Python-based frameworks like LangGraph (LangChain) and LlamaIndex.

## Why LangDAG

- **Go performance**: Pure Go, ~1ms overhead, single static binary, zero runtime dependencies
- **DAG-native**: Every conversation is a tree; branch from any node to explore alternatives
- **Multi-provider**: Anthropic, OpenAI, Gemini, Grok (plus Azure OpenAI, Google Vertex AI, AWS Bedrock)
- **Tool use**: First-class support for tool definitions and tool_use/tool_result flows
- **SQLite storage**: Persistent conversation history with full replay, zero setup
- **Simple API**: One concept (nodes), one verb (prompt)
- **Migration tooling**: Import existing LangGraph conversations (JSON export or direct SQLite)

## Go Library

```
go get langdag.com/langdag
```

Key API:
- `langdag.New(Config{}) (*Client, error)` -- create client
- `client.Prompt(ctx, message, ...opts) (*PromptResult, error)` -- new conversation
- `client.PromptFrom(ctx, nodeID, message, ...opts) (*PromptResult, error)` -- continue/branch
- `client.ListConversations(ctx)` / `client.GetNode(ctx, id)` / `client.GetSubtree(ctx, id)`
- `client.GetAncestors(ctx, id)` / `client.DeleteNode(ctx, id)`
- Options: `WithModel()`, `WithSystemPrompt()`, `WithMaxTokens()`, `WithTools()`
- Streaming: `result.Stream` is a `<-chan StreamChunk`; drain to receive content tokens

## SDKs (REST API clients)

- Python: `pip install langdag` -- sync and async clients
- TypeScript: `npm install langdag`

## CLI

```
langdag prompt "What is LangDAG?"           # new conversation
langdag prompt <node-id> "Tell me more"     # continue from node
langdag prompt                              # interactive mode
langdag ls                                  # list root nodes
langdag show <id>                           # show node tree
langdag rm <id>                             # delete node + subtree
langdag import langgraph --file export.json # import from LangGraph
```

## Model Catalog

Deployment-aware built-in catalog with canonical model IDs, routeable offerings,
deployment-specific native model IDs, pricing, context windows, capabilities,
aliases, and freshness metadata.
- `langdag models [--provider p] [--update] [--json]`
- `DefaultModelCatalog()`, `LoadRuntimeModelCatalog()`, `LoadRemoteModelCatalog(ctx, opts)`, `RefreshModelCatalogCache(ctx, opts)`, `LoadModelCatalog(path)`, `FetchModelCatalog(ctx, path)`

## REST API

```
POST   /prompt                  Start new conversation tree
POST   /nodes/{id}/prompt       Continue from existing node
GET    /nodes                   List root nodes
GET    /nodes/{id}              Get a single node
GET    /nodes/{id}/tree         Get full tree from node
DELETE /nodes/{id}              Delete node and subtree
GET    /health                  Health check
```

## LangGraph Migration

LangDAG includes tooling to import conversations from LangGraph:
- Go package: `langdag.com/langdag/internal/migrate/langgraph`
- CLI: `langdag import langgraph --file export.json` or `--sqlite /path/to/langgraph.db`
- Python export tool: `tools/langgraph-export/` (supports InMemorySaver, SqliteSaver, PostgresSaver)

## Links

- Docs: https://langdag.com
- GitHub: https://github.com/aduermael/langdag
- Detailed reference: https://langdag.com/llms-full.txt
- License: MIT
