Skip to content

IntegrationsAgent frameworks

LangGraph

Give LangGraph and LangChain agents Artiwright's tools, with one Artiwright session per thread.

LangGraph.md

The artiwright Python package gives LangGraph agents Artiwright’s tools as LangChain tools, through LangChain’s MCP adapters. Each LangGraph thread gets its own Artiwright session, so follow-up messages edit the same deck.

  • Python 3.10 or newer (prerequisites). Node.js isn’t needed: the package brings its own.
  • A chat model for LangChain, with its API key (for example OPENAI_API_KEY or GOOGLE_API_KEY).
pip install "artiwright[langgraph]"

Add the LangChain package for your model, for example langchain-openai or langchain-google-genai. On first use Artiwright downloads its JavaScript dependencies into ~/.cache/artiwright; run artiwright-setup to do it ahead of time.

  1. Create the agent with Artiwright’s tools:

    agent.py
    import asyncio
    from langgraph.prebuilt import create_react_agent
    from artiwright.langgraph import INSTRUCTION, agent_tools, compact_messages, get_tools
    async def main():
    tools = agent_tools(await get_tools(root="./artiwright-sessions", session="demo"))
    agent = create_react_agent(
    "openai:gpt-6-luna", # or "google_genai:gemini-3.8-flash"
    tools,
    prompt=INSTRUCTION,
    pre_model_hook=compact_messages,
    )
    result = await agent.ainvoke(
    {"messages": [("user", "Make a three-slide summary of Q3: revenue up 18% to $4.2M, and a plan for Q4.")]},
    {"recursion_limit": 150},
    )
    print(result["messages"][-1].content)
    asyncio.run(main())
  2. Run it:

    python agent.py
  3. Find the file under ./artiwright-sessions/demo/outputs/. The agent’s last message names it.

  • get_tools(root, session=...) starts Artiwright’s MCP server over stdio and returns its tools. Use the thread id as session so every turn in a thread works on the same documents.
  • agent_tools(tools) keeps the tools an agent that writes code needs, and leaves out artiwright_apply (for clients that can’t run code), so its schema isn’t sent with every request.
  • INSTRUCTION teaches the working loop: plan, build, render, lint, fix, finalize.
  • compact_messages is a pre_model_hook: it sends older tool calls and results in short form, a few at a time so the model provider’s prompt cache keeps working. Every model call resends the conversation, so this keeps a long deck’s cost down; the graph state still keeps every message.
  • recursion_limit: a deck can take a few dozen tool calls, and LangGraph counts about three steps per call. Allow enough (150 is a good start); “need more steps” means the limit was hit.

Make the Artiwright agent one node of your graph and give it facts from your other agents, for example by passing a retrieval tool alongside Artiwright’s:

documents = create_react_agent(
model,
[*agent_tools(await get_tools(root="/srv/artiwright-sessions", session=thread_id)), search_knowledge_base],
prompt=INSTRUCTION + "\nUse search_knowledge_base for every number you put on a slide.",
pre_model_hook=compact_messages,
name="artiwright_agent",
)

Add to INSTRUCTION rather than replacing it, and add what the agent can’t know (audience, house style, where the facts are), not rules that shorten its build, look, check, fix loop: see instructions that help, and ones that hurt.

get_tools(...) takes:

Option Default What it does
root required Folder for sessions and finished files
session None ("default") The Artiwright session; use the thread id
theme None Theme for new files: preset name, template path, or {"brand": "#…"}
sandbox True Run the agent’s code in Artiwright’s sandbox

connection(...) takes the same options and returns the stdio connection, for your own MultiServerMCPClient.

pip says it can’t find a version of mcp

Your Python is older than 3.10, often macOS’s built-in 3.9. Create the virtual environment with a newer Python (prerequisites).

Dependency conflict on mcp

LangChain’s MCP adapters 0.3 need mcp below 2.0. Artiwright works with either, so let pip pick a version that satisfies the adapters.