langchain-dartmouth
Skill0 starsChanged 35 days agoBSD-3-ClauseView on GitHub
Build Python LLM applications with the `langchain_dartmouth` package, Dartmouth's LangChain integration for Dartmouth-hosted and Dartmouth-provided models. Use when writing or debugging code that imports langchain_dartmouth (DartmouthLLM, ChatDartmouth, DartmouthEmbeddings, DartmouthReranker, DartmouthDecisions), when choosing which Dartmouth model class or model name to use, when wiring authentication (DARTMOUTH_API_KEY / DARTMOUTH_CHAT_API_KEY), or when building chains, RAG pipelines, agents, or decision-model calls on Dartmouth's AI resources.
- Reads credentials
In this repository6 other files it gives its agents.
- AGENTS.mdAGENTS.md
- dartmouth-brandingSkill
- dartmouth-chatSkill
- decision-modelsSkill
- presentation-designSkill
- research-container-deploymentSkill
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 35
When in doubt about a parameter or behavior, check the API documentation or read the source.
- Very specific: line 53
Every class also accepts the key explicitly (dartmouth_chat_api_key=...
- Distinctive: line 65
Always discover model names at runtime instead of guessing — model lists change:
- Very specific: line 165
Ask (or infer) whether the user has their keys set up (DARTMOUTH_CHAT_API_KEY, and DARTMOUTH_API_KEY only if using DartmouthLLM).
- Very specific: line 166
Call .list() (or have the user run it) to pick real model names instead of inventing them.
- Very specific: line 167
Default to ChatDartmouth; reach for DartmouthLLM only for base completion models, and for DartmouthDecisions when the task is a judgment …
- Distinctive: line 169
When behavior surprises, check the API documentation or the source on GitHub before guessing.
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
langchain_dartmouth
langchain_dartmouth connects LangChain to Dartmouth's generative AI resources: on-premises models (free, no per-token cost) and third-party cloud models (e.g. OpenAI GPT, Google Gemini) billed through the user's Dartmouth Chat token budget. All classes subclass standard LangChain base classes, so they drop in anywhere a LangChain model does.
References:
- Library source: https://github.com/dartmouth/langchain-dartmouth (
src/langchain_dartmouth/) - API documentation: https://dartmouth.github.io/langchain-dartmouth/
- Cookbook (worked notebooks): https://github.com/dartmouth/langchain-dartmouth-cookbook
- Rendered cookbook: https://dartmouth.github.io/langchain-dartmouth-cookbook/
When in doubt about a parameter or behavior, check the API documentation or read the source; the cookbook notebooks show end-to-end patterns.
Authentication
Two different keys, kept as environment variables — never hard-code keys in code:
| Variable | Where to get it | Used by |
DARTMOUTH_CHAT_API_KEY | Dartmouth Chat | ChatDartmouth, DartmouthEmbeddings, DartmouthReranker, DartmouthDecisions |
DARTMOUTH_API_KEY | developer.dartmouth.edu | DartmouthLLM (on-prem TGI endpoints) |
For notebooks and scripts, load a .env file (gitignore it!) at the top:
from dotenv import find_dotenv, load_dotenv
load_dotenv(find_dotenv())Every class also accepts the key explicitly (dartmouth_chat_api_key=... or dartmouth_api_key=...). Base URLs can be overridden with LCD_*_BASE_URL environment variables (see definitions.py).
Choosing a model class
ChatDartmouth(llms.py) — the default for almost everything. Chat and instruction-tuned models, both on-prem (e.g.meta.llama-3.2-11b-vision-instruct,openai.gpt-oss-120b) and paid cloud (e.g.openai.gpt-4.1-mini-2025-04-14). SubclassesChatOpenAI; prompt templates are handled for you.DartmouthLLM(llms.py) — raw on-prem base (non-instruct) models likecodellama-13b-hffor text completion. It does not apply any chat template: the string you pass is exactly what the model receives. SubclassesHuggingFaceTextGenInference; usemax_new_tokens(notmax_tokens).DartmouthEmbeddings(embeddings.py) — embedding models, defaultbaai.bge-large-en-v1-5. SubclassesOpenAIEmbeddings; supportsdimensions.DartmouthReranker(retrievers/document_compressors.py) — reranks retrieved documents, defaultbge-reranker-v2-m3. Callcompress_documents(query=..., documents=[...]).DartmouthDecisions(decisions.py) — typed, calibrated judgments (binary/categorical/ordinal) instead of free-form text. See below.
Deprecated names DartmouthChatModel and ChatDartmouthCloud still work but emit warnings; map them to DartmouthLLM/ChatDartmouth.
Always discover model names at runtime instead of guessing — model lists change:
ChatDartmouth.list() # chat + cloud models, with feature/cost info
DartmouthLLM.list() # on-prem base models
DartmouthDecisions.list()Basic usage
from langchain_dartmouth.llms import ChatDartmouth
llm = ChatDartmouth(model_name="openai.gpt-oss-120b", temperature=0.7, max_tokens=512)
response = llm.invoke("Hi there!")
print(response.content)Quirks to know:
- OpenAI reasoning models (
openai.o*,openai.gpt-5*,openai_responses.*) forcetemperature=1and switch to the Responses API automatically (with a warning). Don't fight this. DartmouthLLMre-authenticates transparently on auth failures; a wrong model name surfaces asModelNotFoundError— the fix is to re-run the class'slist().
Chains, memory, RAG
Because the classes are standard LangChain components, use ordinary LangChain patterns — the rendered cookbook has complete worked examples for each task:
| Task | Recipe |
| Streaming | 04-streaming |
| Output parsing | 05-output-parsing |
| Messages & prompt basics | 06-prompt-basics |
| Prompt templates | 07-prompt-templates |
| Chains (LCEL) | 08-building-chains |
| Conversational memory | 09-conversational-memory |
| Embeddings | 10-embeddings |
| Similarity search | 11-similarity-search |
| RAG | 12-rag |
| Tool calling | 13-tool-calling |
| Agents | 14-agents |
| Structured output | 15-structured-output |
| LangGraph orchestration | 16-langgraph-orchestration |
| Multi-agent | 17-multi-agent |
Typical RAG shape (the 12-rag recipe has the full version):
from langchain_dartmouth.embeddings import DartmouthEmbeddings
from langchain_dartmouth.retrievers.document_compressors import DartmouthReranker
from langchain_text_splitters import CharacterTextSplitter
from langchain_community.document_loaders import TextLoader
from langchain_community.vectorstores import Chroma
docs = TextLoader("document.txt").load()
chunks = CharacterTextSplitter.from_tiktoken_encoder(
encoding_name="cl100k_base", chunk_size=512, chunk_overlap=0
).split_documents(docs)
vectorstore = Chroma.from_documents(chunks, DartmouthEmbeddings())
retriever = vectorstore.as_retriever()Insert a DartmouthReranker as a ContextualCompressionRetriever document compressor when the vector search needs a second-pass rerank.
Decision models
DartmouthDecisions asks typed questions about a piece of state and returns probabilities — no prompt-and-parse. Three question types:
Noul— binary yes/no, returns a probability (response.nouls[name].noul). Use when the probability itself drives logic.Choice— pick one label fromcriteria(dict of label → description); returnschoice, per-labelprobabilities, andconfidence. Use for routing/classification.Score— ordinal rubric (list of level descriptions, numbered from 0); returns an expected-valuescore(can be fractional),legend, andprobabilities. Use for severity/urgency-like spectra.
One invoke can combine several questions, and results arrive synchronously (invoke) or async (ainvoke):
from langchain_dartmouth.decisions import DartmouthDecisions, Choice, Score, Noul
decisions = DartmouthDecisions() # model_name defaults to "cloudflare.clef"
response = decisions.invoke({
"state": "Stripe fails whenever I connect my account.",
"questions": {
"department": Choice(
instructions="Which team should handle this request?",
criteria={
"billing": "Payment, invoice, or subscription issues.",
"technical": "Product bugs or integration failures.",
"sales": "Pricing or purchasing questions.",
},
),
"urgent": Noul(instructions="Does this need an urgent response?"),
},
})
print(response.choices["department"].choice, response.choices["department"].confidence)
print(response.nouls["urgent"].noul)Gate actions on confidence/probability thresholds and route low-confidence cases to humans. Errors map to InvalidKeyError, ModelNotFoundError, DecisionRateLimitError (carries retry_after_ms), and DecisionAPIError. The cookbook's 18-decision-models recipe has a full walkthrough.
Writing code with this library
- Ask (or infer) whether the user has their keys set up (
DARTMOUTH_CHAT_API_KEY, andDARTMOUTH_API_KEYonly if usingDartmouthLLM); scaffold.env+load_dotenvrather than inline keys. - Call
.list()(or have the user run it) to pick real model names instead of inventing them. - Default to
ChatDartmouth; reach forDartmouthLLMonly for base completion models, and forDartmouthDecisionswhen the task is a judgment that maps to Noul/Choice/Score rather than text generation. - Compose with stock LangChain/LangChain-Community pieces (loaders, splitters, vectorstores, parsers,
RunnableWithMessageHistory) — the Dartmouth classes are drop-ins. - When behavior surprises, check the API documentation or the source on GitHub before guessing.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

