A community Go port of LangChain — the Python AI application framework. Build LLM agents and LLM applications in Go using LangChain's abstractions: chat models, tools, prompts, output parsers, messages, vector stores, retrievers, and the create_agent factory.
Not affiliated with or endorsed by LangChain, Inc. Preview quality (
v0.3.1); the public API may still change beforev1.0.0.
A Go port of:
langchain_core→core/— base abstractions and interfaces.langchain(the actively-maintainedlangchain_v1package) →langchain/— concrete implementations, the agent factory, middleware, tools.langchain_text_splitters→textsplitters/.langchain-tests→standardtests/— shared conformance suites.model-profiles→modelprofiles/+ thecmd/langchain-profilesCLI.
It is not a port of langchain_classic (the legacy package), and not a full port of langgraph — only the minimal graph runtime that create_agent depends on is internalized as a private package (see Not supported).
All tests green: go test ./... — 920+ tests across 51 packages.
messages (unified struct, content blocks, tool calls, trimming, serialization) · runnables (composition, batch, stream, fallback, branch, router, JSON/ASCII/Mermaid graph export) · language (ChatModel / LLM interfaces, fake models, ChatModel.Stream, rate-limiter hooks) · tools (base tool, render helpers, retriever-tool adapter) · prompts (string + structured + templated, local JSON loading) · outputparser (all parser variants, format instructions, partial parsing) · callbacks (manager fan-out, stdout/streaming/file handlers, usage aggregation) · streamevents (v3 content-block protocol, ChatModelStream projection) · documents · documentloaders · indexing (incl. SQL record manager) · embeddings · vectorstores (in-memory, filtering, MMR, retriever adapters) · retrievers · exampleselectors · tracers (context/root listener, memory, filtering, replay, event streaming, stdout) · load · stores · caches · ratelimiters · retry · _api (deprecation) · _security (SSRF protection, transport validation) · utils · chathistory · httpclient · modelconfig · outputs · structuredoutput · schema.
chatmodels/embeddings— provider registries, parsing, init-spec boundaries.tools.ToolNode— concurrent dispatch, unknown-tool errors, configurable error handling,ToolCallWrapper.messages,ratelimiters.
A model ↔ tools agent loop built on an internal graph runtime, with:
- Middleware chain —
WrapModelCall/WrapToolCall(outermost-first),BeforeModel/AfterModel/BeforeAgent/AfterAgenthooks,jump_toshort-circuit convention,context.Contexton every hook (for interrupt). - 15 middleware modules: human-in-the-loop, model-call-limit, model-fallback, model/tool-retry, tool-call-limit, context-editing, file-search (ripgrep fast path), pii/redaction, provider-tool-search, shell, summarization, todo, tool-emulator, tool-selection.
system_prompt— plain string and templatedPromptTemplate(with per-call variables).state_schema— custom graph-state fields viaStateField+ reducers (WithAgentStateFields).context_schema— read-only runtime context over Gocontext.Context(WithContextValues/ContextValue).response_format—ToolStrategy,ProviderStrategy(provider-native vialanguage.StructuredCallerwhen the model implements it), andAutoStrategy(auto-selects between the two from the model's capabilities).store— cross-thread KV store, injected into each tool call (WithAgentStore).cache— model-response cache wired into the model-call path (WithAgentCache).interrupt_before/interrupt_after— pause at named graph nodes (WithAgentInterruptBefore/WithAgentInterruptAfter).model— pass a constructedlanguage.ChatModel, or a bareprovider:modelstring resolved viachatmodels.Resolve(WithAgentModel("openai:gpt-4o")).tools— explicit tools, or Go callables reflected into tools viacore/tools.FromFunc(the@toolequivalent).checkpointer— in-memory saver; interrupt / resume round trips.recursion_limit,name,debug.- Streaming —
Agent.StreamEvents: real per-token streaming (model deltas + tool/node lifecycle events) overrunnables.Stream[StreamEvent]. - Subagents (agent-as-tool) — one agent delegates to a named inner agent via a hand-rolled tool whose body calls the inner agent's
InvokeWithState(mirrors Python's@tool+agent.invoke()); the nested run is distinguishable by name viaNameFromContext. A non-streaming nested invoke no longer leaks its events into a streaming parent's stream. See the Subagents guide.
textsplitters/— full port (character, HTML, Markdown, code, recursive, header; sentence-transformers / NLTK / spaCy / KoNLPy adapter interfaces).standardtests/— chat-model / embeddings / retriever / vector-store / runnable conformance suites.modelprofiles/— profile registry, Markdown summary, thelangchain-profiles refreshCLI (merges models.dev data + TOML overrides →profiles.json).
partners/openai · partners/anthropic · partners/ollama (chat models & embeddings) · partners/chroma (vector store). partners/openai is a full integration — its ChatModel (Responses API: Invoke/Stream/tool-calling) implements language.StructuredCaller and self-registers into chatmodels.Resolve, so WithAgentModel("openai:gpt-4o") works out of the box. The others are usable integrations and validation aids; adapter slots for more partners.
langchain_classic— legacy chains, agents, memory, tools, retrievers, vectorstores, storage. The classicAgentExecutoris gone; useagents.CreateAgent.- A full
langgraphport. Only the minimal subsetcreate_agentdepends on lives here, internalized atlangchain/internal/agentruntime/(packageagentruntime, not exported). Intentionally absent: subgraphs, streaming modes beyondevents, time-travel / state history, caching/retry policies, the functional@entrypoint/@taskAPI, persistent Postgres/SQLite checkpoint backends, and the langgraph CLI/SDK. - Subagent transformer (
transformers/run.subagents) — not exposed.transformersis a langgraph stream-mode construct, and this port holds theagentruntimeboundary (no stream modes). The motivating feature — PII streaming-delta redaction — IS delivered, via a bounded middleware delta layer (WrapModelStreamHook+PIIStreamTransformer's lookback buffer); batch redaction also works. - Functional
@entrypoint/@taskAPI, time-travel, subgraphs — see above.
- Only
openai,anthropic,ollama,chroma. No Google/Gemini, AWS, Azure, Pinecone, etc. — community contributions welcome. langchain/chatmodelsparses a model name to aChatModelSpecand resolves it to a constructed partnerChatModelvia the Go provider registry (Resolve+RegisterProvider);WithAgentModel("openai:gpt-4o")works end-to-end. (anthropic/ollama/chroma are not yet registered as real Go factories — pass a constructedlanguage.ChatModelfor those.)langchain/tools.ToolNodedoes not supportCommand/Sendreturned from tools, or reflection-basedInjectedState/InjectedStore/ToolRuntimeargument injection.
core/promptsdoes not load YAML, Jinja templates, orlc://Hub prompts (string + local JSON only).core/runnablesPNG graph rendering is unsupported (JSON/ASCII/Mermaid are).- Python-style dynamic provider import / instance construction is unsupported — construct concrete models in Go.
- File tools (
Read/Write/Edit/Bash) and sandboxing are out of scope — those are provided byclaude-agent-sdk-golang, not by LangChain.
The support / gap tables above are the canonical compatibility reference. Open an issue if you need detail on a specific gap.
go get github.com/projanvil/langchain-golang@v0.3.1Requires Go 1.23+.
A minimal runnable example using the in-tree fake model (swap in a partner ChatModel for production):
package main
import (
"context"
"fmt"
"github.com/projanvil/langchain-golang/core/language"
"github.com/projanvil/langchain-golang/core/messages"
"github.com/projanvil/langchain-golang/langchain/agents"
)
func main() {
model := language.NewFakeChatModel(
language.WithResponses(messages.AI("It's sunny in Shanghai.")),
)
agent, err := agents.CreateAgent(model, nil,
agents.WithAgentSystemPrompt("You are a helpful assistant."),
agents.WithAgentName("my-agent"),
)
if err != nil {
panic(err)
}
// Non-streaming:
reply, _ := agent.Invoke(context.Background(), []messages.Message{
messages.User("What's the weather?"),
})
fmt.Println(reply[len(reply)-1].Content)
// Streaming:
stream, _ := agent.StreamEvents(context.Background(), []messages.Message{
messages.User("Tell me a story."),
})
for {
ev, ok, _ := stream.Next(context.Background())
if !ok {
break
}
if ev.Type == agents.StreamModelDelta && ev.Text != "" {
fmt.Print(ev.Text)
}
}
}For a real model, either construct a language.ChatModel from a partner package (e.g. partners/openai, partners/anthropic, partners/ollama) and pass it positionally, or resolve one from a bare name string: agents.CreateAgent(nil, nil, agents.WithAgentModel("openai:gpt-4o")) (configure via OPENAI_API_KEY / OPENAI_BASE_URL env vars).
Usage guides live under docs/ — example-driven, with every snippet offline-friendly (using the in-tree fake model unless noted):
- Getting started — install, configure a provider, run your first agent.
- Composing runnables (LCEL) —
Pipe/Pipe3-6/Parallel/Branch/Fallbacks/Retry, the Go equivalent of Python'sprompt | model | parser. - Agents —
CreateAgent— system prompts, tools, the 15-module middleware chain, structured output, interrupts. - Streaming —
Agent.StreamEvents: per-token model deltas + tool/node lifecycle events.
For the full API reference, see the package docs at pkg.go.dev. Compile-checked examples also live in each package's example_test.go.
langchain-golang/
├── core/ # langchain_core port
├── langchain/ # langchain (v1) port
│ ├── agents/ # CreateAgent + 15 middleware
│ ├── chatmodels/ embeddings/ messages/ tools/ ratelimiters/
│ └── internal/agentruntime/ # internal graph runtime (not exported)
├── textsplitters/ # langchain_text_splitters port
├── standardtests/ # langchain-tests conformance port
├── modelprofiles/ # model-profiles port
├── partners/ # openai, anthropic, ollama, chroma
└── cmd/langchain-profiles # profiles refresh CLI
This project is a Go port of LangChain (MIT License, Copyright © LangChain, Inc.) and LangGraph. All credit for the original design and abstractions belongs to the LangChain team.
MIT — Copyright © 2026 ProjAnvil.