Build custom AI agents and scripted LLM workflows as plain text files.
Ochat is an OCaml toolkit for building reproducible, composable, tool-using LLM workflows without locking the workflow into a single UI or heavyweight framework.
Instead of hiding prompts, tool permissions, transcript state, and orchestration inside an application, Ochat keeps them in static, diffable files that you can version-control, review, branch, and run in different hosts.
If you like tools like Claude Code or Codex, Ochat operates at a more fundamental level: it gives you the building blocks to create your own prompt packs, agents, and workflow systems.
- Why Ochat exists
- Design Principles
- Ochat in one minute
- What is Ochat?
- What makes Ochat different?
- How Ochat compares
- Who Ochat is for
- Quick start
- What can I do with Ochat?
- Common use cases
- First 10 minutes with Ochat
- Example ChatMD prompts
- Build from source
- Core concepts
- Architecture overview
- Documentation
- OCaml integration
- Future directions
- Project status
Most LLM tools today either:
- hide workflows inside polished UIs,
- require you to rebuild everything in a code-first framework, or
- make prompts and agent state hard to inspect, reproduce, and evolve.
Ochat exists to make LLM workflows feel more like engineering artifacts.
With Ochat, prompts, tools, transcript state, and orchestration live in plain text files that you can:
- version-control
- diff and review
- branch and resume
- compose into larger workflows
- run in the terminal, scripts, CI, or over MCP
The goal is simple: make agent workflows explicit, inspectable, portable, and reproducible.
Ochat is built around a few core principles:
- Everything important should be inspectable
- Workflows should be versionable
- Agent runs should be reproducible
- Tools should be explicit
- Custom workflows should not depend on a single UI
- Advanced orchestration should remain auditable
- A workflow is usually a
.mdfile written in ChatMarkdown (ChatMD). - That file can contain the prompt, model config, tool permissions, transcript, and execution artifacts.
- The same workflow can run in the TUI, the CLI, or over MCP.
- Workflows can call tools, other workflows, and an optional host-managed ChatML script.
- Because everything is stored as text, runs are diffable, reproducible, resumable, and easy to version-control.
Ochat is a toolkit for building agent workflows and orchestrations as static files.
Its core format is ChatMarkdown (ChatMD), a Markdown + XML dialect for defining and running agents. A single ChatMD file can contain:
- model and generation parameters
- tool declarations and permissions
- developer and user instructions
- the full conversation history
- tool calls and tool results
- imported artifacts such as documents or images
- optional host-managed scripting for orchestration and moderation
In Ochat, an agent is often just a .md file.
That file is not only a prompt — it can also be:
- the execution log of a run,
- a reusable workflow component,
- a tool callable by another agent,
- a portable artifact you can inspect and refine over time.
Because everything is captured in text files, workflows become:
- reproducible – the exact config and transcript are version-controlled
- diffable – reviews show exactly what changed and what the model did
- composable – workflows can call other workflows (prompt-as-tool)
- portable – prompts are plain text, not locked into one interface
- editable – use any text editor, IDE, or terminal workflow
- LLM-friendly – the XML structure is easy for models to parse and generate
The same .md workflow definition can be executed in multiple hosts:
- the terminal UI (
chat_tui) for interactive work - scripts and CI via
ochat chat-completion - a remote MCP server via
mcp_server, so IDEs and other applications can call agents over stdio or HTTP/SSE
The ChatMD language provides a rich set of features for prompt engineering in a modular way, supporting workflows from simple prompts to more advanced orchestrations. See the language reference.
ChatMD prompts can also embed a single host-managed ChatML moderation script:
- declare it with
<script language="chatml" kind="moderator" ...> - keep it invisible to the model request itself
- prepend, append, replace, or delete effective transcript items
- inspect and construct structured items through the
Itembuiltin module - moderate tool calls by approving, rejecting, rewriting, or redirecting them
- persist only serializable runtime state between resumed sessions
- request another ordinary model turn after
turn_endviaRuntime.request_turn() - schedule idle follow-up turns after background internal events or startup work
- orchestrate additional model-backed work via
Model.callandModel.spawn - defer user steering submitted during streaming until a safe model-input boundary
Prompts without a <script> keep the baseline behavior: the shared drivers, chat_tui, export flow, and nested agent execution continue to work without the moderation layer.
Ochat is implemented in OCaml, but the workflows themselves are language-agnostic. Tools exchange JSON, prompts are plain files, and the system makes no assumptions about the kinds of applications your workflows target.
Current provider support: nativley uses OpenAI Responses API format.
The architecture is designed to support additional providers in the future. To use other providers right now you can use a proxy-server and set the enviorment url API_URL to the proxy url
Ochat is not just:
- a coding assistant,
- a prompt playground,
- an orchestration framework,
- or an MCP wrapper.
It is a text-first workflow toolkit built around a few core ideas:
-
Prompt-as-program
A workflow can live in a single file that contains config, tools, transcript state, and execution artifacts. -
Transcript-as-artifact
Runs are inspectable, diffable, branchable, and resumable. -
Prompt packs instead of fixed apps
Build your own Claude Code/Codex-style workflows instead of being limited to a single built-in agent UX. -
Composable agents
Mount one prompt as a tool inside another workflow. -
Host-managed control logic
Use ChatML scripts to moderate tool calls, manage workflow state, and orchestrate multi-step behavior. -
Run anywhere
Use the same workflow in the TUI, the CLI, or through MCP.
Ochat occupies a different niche in the LLM tooling landscape than most agent tools.
Tools like Claude Code, Codex-style CLIs, or Aider are polished agent applications for working in a repo.
Ochat is more fundamental: it is a toolkit for building your own agent workflows as plain files. Instead of shipping a single hard-coded agent experience, Ochat lets you define prompts, tools, transcript state, and orchestration explicitly.
Frameworks like LangGraph and similar Python agent stacks are typically code-first: you build workflows in application code.
Ochat is artifact-first: workflows live as text files that can be version-controlled, diffed, composed, resumed, and run in different hosts.
Platforms like LangSmith, PromptLayer, or Humanloop focus on tracing, evaluation, and hosted prompt management.
Ochat focuses on authoring and running workflows locally as inspectable artifacts. It is not primarily a dashboard or hosted prompt registry.
MCP provides a protocol for exposing tools and resources to models and clients.
Ochat supports MCP, but it is broader than that. It is a workflow system with:
- ChatMD prompt files
- transcript persistence
- prompt-as-tool composition
- host-managed scripting
- TUI and CLI execution
- local indexing and retrieval tools
If other tools are:
- agent apps
- Python orchestration frameworks
- hosted observability platforms
- or protocol/tool adapters
then Ochat is best thought of as:
a text-first toolkit for reproducible, composable LLM workflows
Ochat is for developers and power users who want:
- custom AI agents instead of fixed app behavior
- workflows they can version-control and diff
- explicit tool and transcript state
- reproducible runs across local, development, and CI environments
- a local-first, text-first workflow model
Ochat is probably not the best fit if you just want the simplest possible chat UI with minimal setup and no interest in workflow artifacts.
New to OCaml?
If you do not already have an OCaml environment set up, start here:
Ochat uses the standard OCaml tooling stack:
- opam for package management and compiler switches
- dune for builds and tests
Once your OCaml environment is installed, you can build and run Ochat as follows.
Build and run a minimal ChatMD prompt.
opam switch create .
opam install . --deps-only
dune buildCreate prompts/hello.md:
<config model="gpt-5.2" reasoning_effort="medium"/>
<developer>
You are a helpful assistant.
</developer>
<user>
Say hello and explain what Ochat is in one sentence.
</user>dune exec chat_tui -- -file prompts/hello.mdochat chat-completion \
-prompt-file prompts/hello.md \
-output-file .chatmd/hello-run.mdThe output file captures the run as a plain text artifact that you can inspect, diff, resume, or share.
A simple way to get a feel for Ochat:
-
Set up OCaml tooling
If needed, install OCaml, opam, and the toolchain: -
Build the project
opam switch create . opam install . --deps-only dune build
-
Run a minimal prompt Create
prompts/hello.mdand run it in the TUI:dune exec chat_tui -- -file prompts/hello.md -
Try a tool-using prompt Run the refactor example:
dune exec chat_tui -- -file prompts/refactor.md -
Inspect the workflow artifact Export or save the run and open the resulting
.md/.chatmdfile to see:- the prompt
- the transcript
- tool calls and results
- the exact workflow state captured as text
-
Try a non-interactive run
ochat chat-completion \ -prompt-file prompts/hello.md \ -output-file .chatmd/hello-run.md
-
Explore deeper features From there, try:
- agent-as-tool composition
- MCP export via
mcp_server - retrieval/indexing tools
- ChatML moderator scripts
Write agents as .md files using ChatMD. A file can act as both:
- a reusable prompt definition
- the execution log of a run
That means prompts, tool calls, results, and transcripts can all be version-controlled and diffed like code.
Combine:
- ChatMD prompt instructions
- built-in tools
- shell wrappers
- remote MCP tools
- other agents mounted as tools
Built-in tools include capabilities such as:
- repo-safe editing via
apply_patch - filesystem access via
read_dirandread_file - web ingestion via
webpage_to_markdown - retrieval over docs via
index_markdown_docsandmarkdown_search - retrieval over OCaml code via
index_ocaml_codeandquery_vector_db - image import via
import_image
See Tools – built-ins, custom helpers & MCP.
Build Claude Code/Codex-style applications out of multiple prompts:
- planning agents
- coding agents
- test agents
- documentation agents
- orchestration agents
Because prompts can be mounted as tools, you can create modular multi-agent systems without hard-coding everything into one app.
Use:
chat_tuifor interactive workochat chat-completionfor scripts, CI, and cronmcp_serverto expose prompts as tools to IDEs and other clients
Create indexes over docs or source trees and let prompts query them using natural language. See Search, indexing & code intelligence.
Use the mp-refine-run binary to generate, evaluate, and improve prompts and tool descriptions through iterative meta-prompting.
Because conversation state is stored in text files, you can export full runs, branch them, resume them later, and review exactly what changed.
Ochat is useful anywhere you want LLM workflows to be explicit, reproducible, and easy to evolve.
Typical use cases include:
-
Repo-aware coding assistants
Build agents that inspect a codebase, read files, propose patches, and run in a controlled local workflow. -
Documentation agents
Create prompts that summarize docs, update documentation, or answer questions over local documentation sets. -
Planning / review / test workflows
Compose multiple prompts into planning, implementation, review, and test stages. -
Prompt packs for internal tools
Define reusable sets of prompts and tools for domain-specific workflows without burying them inside a UI. -
Retrieval-grounded assistants
Index local docs or source trees and let prompts query them with natural language. -
CI and scripted runs
Run prompts non-interactively in scripts, CI jobs, or recurring automation tasks. -
MCP-exposed prompt tools
Publish prompts as MCP tools so IDEs and other hosts can call them over stdio or HTTP/SSE.
Create prompts/hello.md:
<config model="gpt-5.2" reasoning_effort="medium"/>
<developer>
You are a helpful assistant.
</developer>
<user>
Say hello and explain what Ochat is in one sentence.
</user>Run it:
dune exec chat_tui -- -file prompts/hello.mdOr:
ochat chat-completion \
-prompt-file prompts/hello.md \
-output-file .chatmd/hello-run.mdTurn a .md file into a refactoring bot that reads files and applies patches under your control.
Create prompts/refactor.md:
<config model="gpt-5.2" reasoning_effort="medium"/>
<tool name="read_dir"/>
<tool name="read_file"/>
<tool name="apply_patch"/>
<developer>
You are a careful refactoring assistant. Work in small, reversible steps.
Before calling apply_patch, explain the change you want to make and wait for
confirmation from the user.
</developer>
<user>
We are in a codebase. Look under ./lib, find a small improvement and
propose a patch.
</user>Open it in the TUI:
dune exec chat_tui -- -file prompts/refactor.mdFrom there you can ask the assistant to rename a function, extract a helper, or
update documentation. It will use read_dir and read_file to inspect the
code, then generate apply_patch diffs and apply them.
Export a .md file as a remote tool that other MCP-compatible clients can call.
Create prompts/hello.md:
<config model="gpt-5.2" reasoning_effort="medium"/>
<tool name="read_dir"/>
<tool name="read_file"/>
<developer>You are a documentation assistant.</developer>
<user>
List the files under docs-src/ and summarize what each top-level folder is for.
</user>Start the MCP server so it exports hello.md as a tool:
dune exec mcp_server -- --http 8080Any MCP client can now discover the hello tool via tools/list and call it
with tools/call over JSON-RPC. For example:
curl -s http://localhost:8080/mcp \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'The response includes an entry for hello whose JSON schema is inferred from
the ChatMD file.
You can attach one ChatML moderator script to a prompt and keep it host-managed.
Create prompts/review.chatmd:
<config model="gpt-5.2" reasoning_effort="medium"/>
<tool name="read_file"/>
<tool name="apply_patch"/>
<script language="chatml" kind="moderator" id="main">
type state =
{ reminded : bool }
type event =
[ `Session_start
| `Session_resume
| `Turn_start
| `Item_appended(item)
| `Pre_tool_call(tool_call)
| `Post_tool_response(tool_result)
| `Turn_end
]
let initial_state : state =
{ reminded = false }
let on_event : context -> state -> event -> state task =
fun ctx st ev ->
match ev with
| `Session_start ->
let* () =
Turn.prepend_system(
"Before calling apply_patch, explain the change briefly."
)
in
Task.pure(st)
| _ ->
Task.pure(st)
</script>
<developer>
You are a careful code assistant.
</developer>
<user>
Review lib/example.ml and suggest a small safe improvement.
</user>This example prepends a system instruction at session start, requiring the assistant to explain changes briefly before using apply_patch.
Run it in the TUI or CLI:
dune exec chat_tui -- -file prompts/review.chatmdochat chat-completion \
-prompt-file prompts/review.chatmd \
-output-file .chatmd/review-run.chatmdFor a richer end-to-end example, see:
By default, moderator scripts get the Item, Tool_call, and Context
helper modules on the installed moderator surface, so common transcript,
tool-call, and context queries do not need raw record or JSON plumbing.
Moderator scripts receive ctx.items, where each item has the shape:
type item =
{ id : string
; value : json
}The Item module provides helpers so scripts do not need to hand-author raw
JSON for common cases:
Item.id(item)returns the stable item id used by overlay operationsItem.value(item)returns the underlying structured JSON payloadItem.kind(item)reads the serialized item"type"field when presentItem.role(item)extracts a message role when the item has oneItem.text_parts(item)collects text fragments from common message-like itemsItem.text(item)returns the first text fragment when one is presentItem.input_text_message(id, role, text)builds a structured input messageItem.output_text_message(id, text)builds a structured assistant messageItem.user_text(id, text),Item.assistant_text(id, text),Item.system_text(id, text), andItem.notice(id, text)are convenience constructors over those message shapesItem.is_user(item),Item.is_assistant(item),Item.is_system(item),Item.is_tool_call(item), andItem.is_tool_result(item)are predicate helpers over the serialized role/kind fieldsItem.create(id, value)wraps arbitrary structured JSON as an item
The default moderator surface also exposes pure inspector helpers for tool calls and the current moderation context:
Tool_call.arg(call, name)returns the raw JSON argument when it is presentTool_call.arg_string(call, name),Tool_call.arg_bool(call, name), andTool_call.arg_array(call, name)returnOption.none()when the argument is missing or has the wrong JSON shapeTool_call.is_named(call, name)andTool_call.is_one_of(call, names)match against the serialized tool name using exact string equalityContext.last_item(ctx),Context.last_user_item(ctx),Context.last_assistant_item(ctx),Context.last_system_item(ctx),Context.last_tool_call(ctx), andContext.last_tool_result(ctx)return the last matching item inctx.itemsContext.find_item(ctx, id)uses exact item-id equalityContext.items_since_last_user_turn(ctx)andContext.items_since_last_assistant_turn(ctx)return the suffix beginning at the matching boundary item, or the full item list when no such boundary existsContext.items_by_role(ctx, role)uses exact role-string equalityContext.find_tool(ctx, name)andContext.has_tool(ctx, name)inspectctx.available_toolsusing exact tool-name equality
Example:
let first_text : string array -> string =
fun parts ->
if Array.length(parts) == 0 then "" else Array.get(parts, 0)
let on_event : context -> state -> event -> state task =
fun ctx st ev ->
match ev with
| `Item_appended(item) ->
let summary =
Item.id(item)
++ ":"
++ Option.get_or(Item.role(item), "unknown")
++ ":"
++ first_text(Item.text_parts(item))
in
Task.bind(Turn.append_item(Item.output_text_message("summary", summary)), fun ignored ->
Task.pure(st))
| _ ->
Task.pure(st)Prefer Turn.append_item, Turn.replace_item, and Turn.delete_item.
The older append_message, replace_message, and delete_message names are
still accepted as aliases.
Additional Phase 1 script helpers:
Turn.replace_or_append(target_id_opt, item)replaces whentarget_id_optisOption.some(id)and appends when it isOption.none()Turn.append_notice(text)appends a synthetic system notice item using a stablesystem:-prefixed id derived from the notice textModel.call_text(recipe, text)is shorthand forModel.call(recipe,String(text))`Model.call_json(recipe, payload)is a named alias forModel.call(recipe, payload)when the payload is already structured JSONModel.spawn_text(recipe, text)is shorthand forModel.spawn(recipe,String(text))`
When a prompt runs in chat_tui, moderation is split across three layers:
Moderator_managerowns durable moderator state, overlay state, and queued internal events.In_memory_streamowns one active model/tool turn.chat_tuiowns the session controller that drains wakeups while idle, refreshes visible transcript state, and schedules follow-up turns without creating fake user messages.
The visible transcript in the UI is a projection of canonical history through
the moderator overlay. During streaming, chat_tui still applies token and
tool patches directly for responsiveness, then reprojects the visible
transcript at safe points such as:
- idle/background moderator drains,
- the end of a streamed turn,
- the end of compaction,
- startup or resume moderation.
For the concrete host/session-controller contract behind those behaviors, see ChatML host session-controller contract.
For the canonical safe-point and effective-history semantics behind request preparation, overlay projection, deferred steering, restore, and visible history refresh, see ChatML safe-point and effective-history semantics.
For a consolidated overview of the moderator runtime layers, builtin surfaces, event types, helper modules, runtime requests, internal events, and UI-only capabilities, see ChatML moderator runtime guide.
For the concrete budget contract that bounds self-triggered turns, idle
internal-event drains, automatic follow-up scheduling, and the ownership of
max_spawned_jobs, see
ChatML budget policy.
For the end-to-end async completion and wakeup path behind Model.spawn,
queued moderator internal events, idle drains, and the current Job deferral,
see
ChatML async completion lifecycle.
For the optional UI-only notification and ask-user capability layer used by
interactive hosts such as chat_tui, see
ChatML UI host capabilities.
That UI layer adds Ui.notify, Approval.ask_text, and
Approval.ask_choice only on the dedicated UI surface.
Ui.notify is a host-local notice path: it does not mutate canonical history
and does not append transcript items automatically. The Approval.ask_* flow
is live-session-only: it pauses the current script, exposes one pending UI
request to the host, and resumes the same script execution from that call site
when the UI submits a validated response. It is not the same as deferred
safe-point steering input, and pending approvals are not persisted across
restart or snapshot restore.
Two host behaviors are especially important:
-
Idle async wakeups
Background producers such as
Model.spawncompletions may enqueue moderator internal events while no turn is active. The host wakes the session controller, drains those internal events, refreshes visible transcript state, and may schedule an idle follow-up turn if the moderator requests one. -
Deferred steering notes
If the user submits steering text while a turn is already streaming, the host does not splice a new canonical user message into the in-flight model request. Instead it stores a deferred steering note and injects it only at the next safe model-input boundary. This preserves the current reasoning and tool workflow while still letting the user steer the next request.
An end-to-end idle async completion looks like this:
- a moderator script previously calls
Model.spawn(...) - the spawned job finishes and is reinjected as an internal event
- the idle
chat_tuisession receives a moderator wakeup - the reducer drains queued internal events through
Moderator_manager - any overlay changes are reprojected into the visible transcript
- if the moderator emitted
Runtime.request_turn(), the host starts one more ordinary turn from the current session state
An end-to-end deferred-steering flow during a tool run looks like this:
- the assistant is in the middle of a streamed turn or tool workflow
- the user submits steering text
- the host records a deferred steering note instead of appending a canonical user item mid-turn
- the current turn reaches a safe point and eventually completes
- the next request is prepared from moderator-effective history
- the deferred steering note is appended as transient system input for that request only
Install dependencies, build, and run tests:
opam switch create .
opam install . --deps-only
dune build
dune runtestOn Apple Silicon (macOS arm64), Owl's OpenBLAS dependency can sometimes fail to build during
opam install. If you see BLAS/OpenBLAS errors while installing dependencies or runningdune build, see Build & installation troubleshooting for a proven workaround.
Run an interactive session with the terminal UI:
dune exec chat_tui -- -file prompts/interactive.mdOr run a non-interactive chat completion over a ChatMD prompt as a smoke test:
ochat chat-completion \
-prompt-file prompts/hello.md \
-output-file .chatmd/smoke.mdFor more on ochat chat-completion (flags, exit codes, ephemeral runs), see
docs-src/cli/chat-completion.md.
-
ChatMarkdown (ChatMD)
A Markdown + XML dialect that stores model config, tool declarations, and the full conversation (including tool calls, reasoning traces, and imported artifacts) in a single.mdfile. See the language reference. -
Tools
Functions the model can call, described by explicit JSON schemas. They can be built-ins, shell wrappers, other ChatMD agents, or remote MCP tools. See Tools – built-ins, custom helpers & MCP. -
chat_tui
A Notty-based terminal UI for editing and running.mdfiles. It turns each prompt into a terminal application with streaming output, persistent sessions, and export/branch workflows. See the chat_tui guide. -
CLI and helpers
Binaries likeochat,md-index, andmd-searchprovide script-friendly entry points for running prompts and building/querying indexes. -
MCP server
mcp_serverturns.mdfiles and selected tools into MCP resources and tools that other applications can list and call over stdio or HTTP/SSE. See the mcp_server binary doc. -
Search & indexing
Modules and binaries that build vector indexes over markdown docs and source code, powering tools likemarkdown_searchandquery_vector_db. See Search, indexing & code intelligence. -
Meta-prompting
A library and CLI (mp-refine-run) for generating, scoring, and refining prompts in a loop. See theMeta_promptingoverview.
At a glance, Ochat treats workflows as text artifacts executed by a host runtime.
ChatMD workflow file
┌──────────────────────────────────────────────┐
│ config │
│ tools │
│ prompt messages │
│ transcript / tool calls / tool results │
│ optional ChatML moderation script │
└──────────────────────────────────────────────┘
│
▼
┌──────────────────────────────────┐
│ Host runtime │
│ - `chat_tui` │
│ - `ochat chat-completion` │
│ - `mcp_server` │
└──────────────────────────────────┘
│ │
▼ ▼
┌───────────────┐ ┌──────────────────┐
│ Model backend │ │ Tool execution │
│ OpenAI today │ │ built-ins/shell/ │
│ more later │ │ MCP/other agents │
│ or use proxy │ └──────────────────┘
└───────────────┘ │
│ │
└──────────┬───────┘
▼
Updated ChatMD transcript/state
(diffable, reproducible, resumable)
At a high level, Ochat has two layers:
-
ChatMD is the workflow document format
It stores prompts, tools, transcript state, and execution artifacts. -
ChatML is the optional host-managed scripting layer
It adds workflow logic such as moderation, transcript editing, policy enforcement, and multi-step orchestration.
A typical flow looks like this:
- Load a ChatMD file
- Parse config, tools, transcript, and optional script
- Run it in a host (
chat_tui, CLI, or MCP) - Let the model call tools and produce output
- Optionally let a ChatML moderator inspect/modify the effective transcript or tool flow
- Persist the resulting workflow state back as text artifacts
This split keeps workflows inspectable while still allowing advanced control logic.
For moderated interactive sessions, the host runtime has a more specific role split:
Moderator_managerkeeps durable moderator state, overlay state, halted state, and queued internal events.In_memory_streamexecutes one active completion/tool-followup loop at a time and handles explicit safe points such as turn start, post-tool-result, and turn end.chat_tuiruns a single-threaded session controller over its reducer loop. That controller reacts to moderator wakeups while idle, defers wakeups while a turn is active, refreshes visible transcript state from moderator-effective history at safe points, and starts follow-up turns only when the UI is idle.
The concrete Phase 2 articulation of that host layer lives in docs-src/chatml-host-session-controller-contract.md.
Deep-dive docs live under docs-src/. Key entry points:
- ChatMarkdown language reference
- Built-in tools & custom tools
- chat_tui guide & key bindings
ochat chat-completionCLI- MCP server & protocol details
- Search, indexing & code intelligence
- Meta-prompting & Prompt Factory
- Real-world example session: updating the tools docs
- ChatML moderator runtime guide
- ChatML host session-controller contract
- ChatML safe-point and effective-history semantics
- ChatML budget policy
- ChatML async completion lifecycle
- ChatML UI host capabilities
| Binary | Purpose | Example |
|---|---|---|
chat_tui (chat-tui) |
interactive TUI | chat_tui -file notes.md |
ochat |
misc CLI (index, query, tokenise …) | ochat query -vector-db-folder _index -query-text "tail-rec map" |
mcp_server |
serve prompts & tools over JSON-RPC / SSE | mcp_server --http 8080 |
mp-refine-run |
refine prompts via recursive meta-prompting | mp-refine-run -task-file task.md -input-file draft.md |
md-index / md-search |
Markdown → index / search | md-index --root docs; md-search --query "streams" |
odoc-index / odoc-search |
(OCaml) odoc HTML → index / search | odoc-index --root _doc/_html |
Run any binary with -help for details.
bin/ – chat_tui, mcp_server, ochat …
lib/ – re-usable libraries (chatmd, functions, vector_db …)
docs-src/ – Markdown docs rendered by odoc & included here
prompts/ – sample ChatMD prompts served by the MCP server
dune-project – dune metadata
Ochat is implemented in OCaml. While the workflows themselves are language-agnostic, Ochat has first-class support for OCaml development workflows.
Ochat is heavy on:
- structured data and parsing
- symbolic transformations
- workflow state modeling
- reliability-sensitive orchestration
- compiler- and test-driven repair loops
These are all areas where OCaml is especially strong.
-
OCaml development environment guide
SeeDEVELOPMENT.mdfor a walkthrough that sets up local OCaml documentation, search indexes, and related workflows. -
OCaml API doc search
odoc-index/odoc-searchindex and search generated odoc HTML. -
Embedding as a library
Use the OCaml libraries directly. See Embedding Ochat in OCaml. -
OCaml indexing & code intelligence
Ochat can parse and index OCaml source directly (no LSP dependency) to build precise code search and code-aware agent workflows.
When you run Ochat against an OCaml repository, the usual dune build / dune runtest loop becomes a high-signal feedback channel for LLM-generated edits: let an agent propose apply_patch diffs, run the build and tests, then feed compiler errors or failing tests back into the next turn.
The repository ships an experimental language called ChatML: a small, expression-oriented ML dialect with Hindley–Milner type inference extended with row polymorphism for records and variants.
Today ChatML is integrated primarily as the host-managed moderation layer for ChatMD:
- a prompt may declare one
<script language="chatml" kind="moderator" ...> - the script runs through the shared moderation manager used by
chat_tui, file-backed drivers, nested agents, and MCP prompt wrappers - moderator scripts receive
ctx.itemswhere each item is{ id; value : json } - moderator scripts can modify transcript items and moderate tool calls
- moderator scripts can request another turn via
Runtime.request_turn() - moderator scripts can call host-registered model recipes via
Model.call - moderator scripts can spawn background model jobs via
Model.spawn
For the concrete async reinjection, wakeup, and safe-boundary lifecycle behind
Model.spawn, see
ChatML async completion lifecycle.
Outside that moderation integration, ChatML is also available through the experimental dsl_script binary and the Chatml_* library modules.
Phase 1 also exposes clearer OCaml entrypoints for embedders:
Chatml_runtimeis the public runtime wrapper overChatml_moderator_runtimeChat_response.Chatml_moderationis the structured moderation vocabulary wrapper overModerationChat_response.Chatml_moderatoris the durable effective-history and snapshot boundary overModerator_managerChat_response.Chatml_turn_driveris the public safe-point and turn-input helper layer overIn_memory_stream
The older module names still exist as implementation anchors inside the libraries, but new embedder-facing code should prefer the wrapper modules above.
For more details, see:
docs-src/guide/chatml-language-spec.mddocs-src/guide/chatml-match-semantics.mddocs-src/lib/chatml/chatml_lang.doc.mddocs-src/lib/chatml/chatml_parser.doc.mddocs-src/lib/chatml/chatml_resolver.doc.md
Ochat is intentionally agent-first: the roadmap focuses on making ChatMD, the runtime, and chat_tui more expressive for building and operating fleets of custom agents.
Planned and experimental directions include:
-
Explicit control-flow & policy in ChatMD
A design sketch for a rules layer over ChatMD that could express things like auto-compaction, tool validation policies, and declarative control flow without hiding logic from the transcript. -
Richer session tracking, branching, and evaluation
Better first-class support for branching conversations, long-term archives, and evaluation runs. -
Session data backed by Irmin
A planned per-session state and filesystem model with isolation, persistence, and versioning. -
Additional LLM providers
Today Ochat integrates with OpenAI; future work is intended to support additional backends while keeping ChatMD and tool contracts stable. You can use a proxy server that maps the Openai api Response endpoint format to your preferred providers format. Example: LiteLLm and set the enviorment url API_URL to the proxy url. -
Broader ChatML scripting roles
ChatML is currently focused on moderation and orchestration; the longer-term plan is to broaden that scripting role without sacrificing safety or auditability. -
Custom OCaml functions as tools via Dune plugins
A planned direction is to expose custom OCaml functions as tools via Dune plugins.
All of these directions share the same goal: make agents more reliable, composable, and expressive without sacrificing the “everything is a text file” property.
Ochat is a fast-moving project.
The core file-oriented workflow model is designed to stay stable, but APIs, tool schemas, and some higher-level design choices may continue to evolve as the project explores what works best.
Despite the experimental label, you can build real value today. The repository already enables powerful custom agent workflows for development, documentation, writing, and automation.
Please budget time for occasional refactors and breaking changes.
Bug reports, feature requests, and PRs are very welcome.
Documentation is also a work in progress. If you find gaps or rough edges, please open issues or PRs to help improve it.
All original source code is licensed under the terms stated in LICENSE.txt.