ContextGuides
LangChain and LangGraph
One middleware for create_agent / createAgent; loaded skills live in graph state and survive checkpoints.
skills = context.load_skills("../quickstart/skills", tools=[lookup_order, issue_refund, search_docs])
model = scripted_model(script(load("refunds"), call("lookup_order", order_id="A-1001"), say("Refunded.")))
agent = create_agent(model, tools=[], middleware=[with_skills(skills)], checkpointer=InMemorySaver())
config = {"configurable": {"thread_id": "customer-42"}}
out = await agent.ainvoke({"messages": [{"role": "user", "content": "My order A-1001 arrived damaged."}]}, config)const skills = await loadSkills("../quickstart/skills", { tools: [lookupOrder, issueRefund, searchDocs] });
const model = scriptedModel(script(load("refunds"), call("lookup_order", { order_id: "A-1001" }), say("Refunded.")));
const agent = createAgent({ model, tools: [], middleware: [withSkills(skills)], checkpointer: new MemorySaver() });
const config = { configurable: { thread_id: "customer-42" } };
const out = await agent.invoke({ messages: [{ role: "user", content: "My order A-1001 arrived damaged." }] }, config);with_skills(skills) / withSkills(skills) returns a LangChain v1 agent middleware that:
- adds a private
_skillskey to the graph state, persisted by your checkpointer perthread_id. Private keys are not part of the agent's input or output schema, so the agent's input cannot set which skills are loaded (read it withagent.get_state(config)/agent.getState(config)). Thread state can still be written from outside the graph (update_state, a server's thread state endpoint), so withouttrust_state=True/trustState: trueonly model loads are restored from it: input triggers replay from the messages, the router runs again over the user messages in every model and tool call (so earlier turns' picks come back), and atool_calledtrigger load is not restored (the tools it gates are not usable after its call). Set it when clients cannot write thread state; - registers
load_skilland every bindable tool, so the tool node can execute them, and filters the tools the model sees on each model call to the bound ones; - adds Context's system prompt after yours;
- answers
load_skillwith aCommandthat updates bothskillsandmessages.
It composes with other middleware and with the agent's own tools.
Custom graphs. Keep the skills field out of your graph's input schema (whatever can write it decides which
skills are loaded). Use the skills state field (skills_reducer / skillsField()), skills_session(skills, state)
to rebuild the session in a node, and skills_delta(before, session) to return what changed.