Skip to main content

langstage-codraft

The document stage for your LangGraph agent. Draft a document block by block on real pages. Tag your agent in comments, approve every change it suggests, and export exactly what you see.

Tests PyPI Python

Codraft editor: an agent suggestion shown as a diff on the block it changes

Dark mode

Codraft in dark mode

You own the thinking. Your agent owns the styling, and helps with drafting and research when you ask it to.

  • Blocks on pages. Text, headings, images, tables, Vega-Lite charts, callouts and an automatic references list. Pages come in Letter, A4, Legal, A5 or 16:9 slide, with 1–3 columns. You can also pin blocks so other blocks flow around them, repeat headers and logos on every page, and add cover and back pages. Pageless mode is available too.
  • The agent edits by suggestion. Every change the agent makes to your text arrives as a diff you accept or reject. A per-document switch turns on auto-apply.
  • Comments tag the agent. Queue comments for later or ask now. "Address all comments" handles them strictly top to bottom.
  • Nothing is overwritten. Each block keeps a version tree. Step back, step forward, and edit an old version to start a new branch.
  • Sources stay with each block. The agent cites as it writes, and a references block compiles them.
  • The agent sees the page. view_pages gives a vision model screenshots of the rendered pages, so it can fix layout problems you'd spot by eye.
  • Export matches the screen. PDF, PNG/JPG per page, or a self-contained HTML zip, all rendered by the same component as the editor (CI checks them pixel for pixel). Also Word (.docx, editable and reflowing), PowerPoint (.pptx, one slide per page, with editable text boxes where the paginator put them), and an animated GIF or MP4 page slideshow.
  • Sketch it, get an image. Draw on an image block; the agent looks at the sketch (view_sketch) and turns it into an image with its image tool, or says it can't.
  • Video and GIF blocks. They play in the editor and in the HTML export; PDF and images use the poster frame.
  • Write together, live. Everyone in a document sees each other's cursor block, edits from other tabs, people and agents arrive instantly, and a block someone is editing is soft-locked. If two people still edit the same block, both versions are kept as branches.
  • Any agent, over MCP. Claude Code, Cursor or any MCP client can co-author through the same approval-gated tools, at http://localhost:8060/mcp or langstage-codraft mcp (stdio).
  • Light and dark. The interface uses langstage-web's design system, so the two stages look like one product.

Quick start

pip install langstage-codraft
langstage-codraft install-browser          # Chromium for export and the agent's eyes (once)
langstage-codraft run --demo               # keyless scripted co-author, opens http://localhost:8060

With a real model:

export OPENROUTER_API_KEY=...              # or OPENAI_API_KEY / ANTHROPIC_API_KEY
langstage-codraft run                      # default agent: claude-haiku-5.5 via OpenRouter
langstage-codraft run -m openai:gpt-5-mini # any LangChain model spec
pip install "langstage-codraft[anthropic]"  # for ANTHROPIC_API_KEY / anthropic: models
pip install "langstage-codraft[video]"      # MP4 export (bundles ffmpeg)

Bring your own agent

Codraft is a LangStage stage: you bring the LangGraph agent and Codraft adds what it needs to work on documents. There are three ways to plug one in.

# my_agent.py  (needs OPENAI_API_KEY; any LangChain chat model works)
from langchain.agents import create_agent
from langchain_core.tools import tool
from langstage_codraft import CodraftMiddleware


@tool
def glossary(term: str) -> str:
    """Look up an internal term."""
    return {"pilot": "A time-boxed trial with a go/no-go review."}.get(term.lower(), "No entry.")


# 1. A graph that includes the middleware (it registers the tools and the co-author prompt,
#    and attaches page screenshots for vision models).
graph = create_agent("openai:gpt-5-mini", tools=[glossary], middleware=[CodraftMiddleware()])


# 2. Or a factory: Codraft calls it with its tools and middleware.
def make(tools, middleware):
    return create_agent("openai:gpt-5-mini", tools=[*tools, glossary], middleware=middleware)
langstage-codraft run --agent my_agent.py:graph    # or my_agent.py:make
langstage-codraft check --agent my_agent.py:graph  # preflight; --live runs one real turn

A graph built without the Codraft tools still chats, but it can't touch the document. check tells you when that's the case.

The agent's toolset (CODRAFT_TOOLS) has 20 tools. Each one reads and writes through the same API the editor uses, so the agent has no private path, and nothing the agent can do is out of the author's reach:

Read Write (suggestions) Style (applies directly) Other
get_document, read_blocks, search_document, read_upload, list_comments, get_block_history propose_edit, propose_insert, propose_delete, propose_move, insert_blocks, draw_figure set_block_layout, set_document_style, reserve_area reply_to_comment, compile_references, view_pages, view_sketch, view_upload

Each document has its own agent thread (the AG-UI thread id is the document id). Conversations are stored in SQLite and survive restarts. The same agent is also served at POST /agui for any AG-UI client.

Magazine-quality reports

Codraft lays out more than memos. Give examples/report_designer.py (an OpenRouter agent with image generation) a few pages of a report you like and a topic, and it builds a report with the same look: custom page size, justified three-column type with hyphenation, drop caps, pull quotes, page-anchored hero art that bleeds past the margins, framed figures (FIGURE 1, title, source line), running footers with {page} numbers that alternate left and right, and a hanging-indent reference list that flows across columns. Diagrams are drawn as SVG (draw_figure) so labels stay crisp; photos and illustrations come from an image model.

Two pages of a magazine-style feature on smart water networks, built by the report designer agent

export OPENROUTER_API_KEY=...
langstage-codraft run --agent examples/report_designer.py:make --approval auto
# upload reference pages (PNG/JPG), then ask: "Make a report like the attached pages about <topic>"

Every layout feature is available to people too (Block and Document panels) and to any agent: block styles (lead, pullquote, kicker, byline, footer, bio; headings display, section, rule; figure-box; hanging references; dark callouts), drop caps, custom page sizes, page-anchored pins, and reserved areas (reserve_area) that keep part of a page empty. Page numbers: put {page} (and {pages}) in a repeating footer; cover and closing pages are skipped unless you turn on "Number cover and closing pages", and any page can be left unnumbered.

Bring any agent: MCP

The same tools are served over MCP, so agents outside LangGraph can co-author too. Their edits are suggestions the author approves, exactly like the built-in co-author's.

# with `langstage-codraft run` going (view_pages works over HTTP):
claude mcp add --transport http codraft http://localhost:8060/mcp

# or stdio, for clients that launch a command:
langstage-codraft mcp --data-dir .codraft

MCP tools: list_documents, create_document, every CODRAFT_TOOLS tool with a doc_id argument, plus view_pages and view_sketch, which return images.

For deployers

Configuration follows the LangStage chain: defaults < langstage.toml < LANGSTAGE_* env < CLI flags.

# langstage.toml
[agent]
spec = "my_agent.py:graph"

[codraft]
model = "openrouter:anthropic/claude-haiku-5.5"   # used when no agent spec is set
approval = "required"                            # or "auto" for new documents
default_theme = "acme"
allowed_themes = ["acme", "academic"]
templates_dir = "templates"                      # *.json: settings + a block skeleton
data_dir = ".codraft"

[ui]
theme = "auto"                                   # app chrome: light | dark | auto

[codraft.themes.acme]
label = "Acme"
font_body = "Inter, system-ui, sans-serif"
font_heading = "Inter, system-ui, sans-serif"
color_accent = "#d9480f"

langstage-codraft run --show-config prints the resolved values and where each one came from.

There are seven built-in templates (ids in brackets): blank, report, proposal, memo, two-column academic paper (paper), marketing one-pager (one-pager), and a three-column newsletter with a repeating masthead (newsletter). Each new document records the author's brief (writing style, objective, platform, audience, language, output format), and the agent reads it before writing.

CLI

langstage-codraft run [--agent SPEC | --model SPEC | --demo] [--port 8060] [--approval auto]
langstage-codraft check [--live] [--json]
langstage-codraft new "Title" --template report
langstage-codraft list
langstage-codraft export DOC_ID -f pdf|docx|pptx|png|jpg|html|gif|mp4 -o out.pdf
langstage-codraft mcp [--data-dir DIR]          # Codraft over MCP (stdio)
langstage-codraft install-browser

How the layout works

Blocks are measured in the browser at the width they'll occupy. A pure function then paginates them (see frontend/src/layout/paginate.ts, which has its own unit tests):

  • Blocks flow column-major. A full-width block balances the columns above it.
  • A pinned block reserves a rectangle on the page instead of wrapping text around it.
  • Text splits only at paragraph or line boundaries, keeping at least two lines on each side.
  • A block taller than a page is flagged rather than looping forever.

The preview, the export and the agent's screenshots all print that same layout in headless Chromium. Chromium never paginates anything again, so the editor and the PDF can't disagree.

A three-column community newsletter page with a pinned masthead that repeats on every page

Part of LangStage

Stage Package
Web workspace langstage
Terminal langstage-cli
JupyterLab langstage-jupyter
VS Code langstage-vscode
Hermes langstage-hermes
Documents langstage-codraft
Shared host + AG-UI bridge langstage-core

Docs: https://dkedar7.github.io/langstage-docs/stages/codraft/

Development

uv venv && uv pip install -e ".[dev]"
cd frontend && npm ci && npm test && npm run build && cd ..
pytest                                   # unit + API + browser e2e (needs the built UI)
CODRAFT_LIVE=1 OPENROUTER_API_KEY=... pytest tests/live -s    # opt-in real-model checks

Run npm run dev in frontend/ alongside langstage-codraft run --demo --no-browser to get hot reload; Vite proxies /api to port 8060.

The design notes this started from are in docs/notes/, and the requirements are in docs/brainstorms/.

License

MIT

Metadata

Release files for langstage-codraft 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langstage-codraft 0.3.1
File Size Uploaded Provenance
langstage_codraft-0.3.1.tar.gz 5.1 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for langstage-codraft 0.3.1
File Interpreter ABI Platform
langstage_codraft-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.2 MB

Release files / langstage_codraft-0.3.1.tar.gz

Download URL langstage_codraft-0.3.1.tar.gz
Size 5.1 MB
Tags Source
SHA-256 checksum
How to use checksums
d74022dc273b4208f8b34eab9d75dc92dd6d2c61fceb2292731217b2e0a1a648
BLAKE2b-256 checksum
How to use checksums
f65ee151c93b562e9f137617be0f58b73fdf01a0124f7909f3ed94c8ff80686d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / langstage_codraft-0.3.1-py3-none-any.whl

Download URL langstage_codraft-0.3.1-py3-none-any.whl
Size 3.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
f7f4b8490dcabbea3b5fc37eda3d444d61ce01e1cfe859f94c95ec20e73bd28b
BLAKE2b-256 checksum
How to use checksums
af41b407290665050f39592cd725f6a9ce58b0b16147a7594281593f827b7846
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.15 {"installer":{"name":"uv","version":"0.11.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for langstage-codraft 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page