agentleFS
dartmouthdartmouth/dartmouth-skills/skills/langchain-dartmouth/SKILL.md

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

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
  1. Distinctive:

    When in doubt about a parameter or behavior, check the API documentation or read the source.

    line 35
  2. Very specific:

    Every class also accepts the key explicitly (dartmouth_chat_api_key=...

    line 53
  3. Distinctive:

    Always discover model names at runtime instead of guessing — model lists change:

    line 65
  4. Very specific:

    Ask (or infer) whether the user has their keys set up (DARTMOUTH_CHAT_API_KEY, and DARTMOUTH_API_KEY only if using DartmouthLLM).

    line 165
  5. Very specific:

    Call .list() (or have the user run it) to pick real model names instead of inventing them.

    line 166
  6. Very specific:

    Default to ChatDartmouth; reach for DartmouthLLM only for base completion models, and for DartmouthDecisions when the task is a judgment …

    line 167
  7. Distinctive:

    When behavior surprises, check the API documentation or the source on GitHub before guessing.

    line 169

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

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:

VariableWhere to get itUsed by
DARTMOUTH_CHAT_API_KEYDartmouth ChatChatDartmouth, DartmouthEmbeddings, DartmouthReranker, DartmouthDecisions
DARTMOUTH_API_KEYdeveloper.dartmouth.eduDartmouthLLM (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). Subclasses ChatOpenAI; prompt templates are handled for you.
  • DartmouthLLM (llms.py) — raw on-prem base (non-instruct) models like codellama-13b-hf for text completion. It does not apply any chat template: the string you pass is exactly what the model receives. Subclasses HuggingFaceTextGenInference; use max_new_tokens (not max_tokens).
  • DartmouthEmbeddings (embeddings.py) — embedding models, default baai.bge-large-en-v1-5. Subclasses OpenAIEmbeddings; supports dimensions.
  • DartmouthReranker (retrievers/document_compressors.py) — reranks retrieved documents, default bge-reranker-v2-m3. Call compress_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.*) force temperature=1 and switch to the Responses API automatically (with a warning). Don't fight this.
  • DartmouthLLM re-authenticates transparently on auth failures; a wrong model name surfaces as ModelNotFoundError — the fix is to re-run the class's list().

Chains, memory, RAG

Because the classes are standard LangChain components, use ordinary LangChain patterns — the rendered cookbook has complete worked examples for each task:

TaskRecipe
Streaming04-streaming
Output parsing05-output-parsing
Messages & prompt basics06-prompt-basics
Prompt templates07-prompt-templates
Chains (LCEL)08-building-chains
Conversational memory09-conversational-memory
Embeddings10-embeddings
Similarity search11-similarity-search
RAG12-rag
Tool calling13-tool-calling
Agents14-agents
Structured output15-structured-output
LangGraph orchestration16-langgraph-orchestration
Multi-agent17-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 from criteria (dict of label → description); returns choice, per-label probabilities, and confidence. Use for routing/classification.
  • Score — ordinal rubric (list of level descriptions, numbered from 0); returns an expected-value score (can be fractional), legend, and probabilities. 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

  1. Ask (or infer) whether the user has their keys set up (DARTMOUTH_CHAT_API_KEY, and DARTMOUTH_API_KEY only if using DartmouthLLM); scaffold .env + load_dotenv rather than inline keys.
  2. Call .list() (or have the user run it) to pick real model names instead of inventing them.
  3. Default to ChatDartmouth; reach for DartmouthLLM only for base completion models, and for DartmouthDecisions when the task is a judgment that maps to Noul/Choice/Score rather than text generation.
  4. Compose with stock LangChain/LangChain-Community pieces (loaders, splitters, vectorstores, parsers, RunnableWithMessageHistory) — the Dartmouth classes are drop-ins.
  5. When behavior surprises, check the API documentation or the source on GitHub before guessing.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.