Engineering case study
Sudowrite Agentic Chat
An AI writing assistant that connects conversation with manuscript tools, preserving the author's intent through revisions, approvals, and interrupted work.
Software engineer
- TypeScript
- React
- XState
- Linear Temporal Logic
- Node.js
- Express
- TipTap
- ProseMirror
- Yjs
- PostgreSQL
- Redis
- Tamagui
Sudowrite helps fiction writers brainstorm, develop, write, and revise their stories. I worked across the frontend and backend of its agentic chat experience, connecting conversation with tools that read manuscripts, organized outlines, updated Story Bible information, generated prose, and worked with comments.
A writer could ask for feedback on a chapter, request several revisions, and then ask the assistant to apply one. Each step needed to preserve the right source text, document, instructions, and permissions, even when the writer changed direction.
The experience served thousands of writers, who used it to brainstorm, revise manuscripts, and update their Story Bibles. My work covered the interface, orchestration, manuscript editing, streaming requests, and the tools we used to evaluate and debug the system.
Shaping the Work
Alongside implementation, I led product and technical direction for the chat platform, working with product, design, support, and customers to decide what to focus on and improve. Customer feedback, support trends, product analytics, beta usage, and experiments helped connect architecture decisions to the problems writers were encountering.
The work evolved through repeated releases. Changes to context selection, execution, recovery, and evaluation came from observing where the experience broke down and checking whether a proposed improvement helped in practice.
Making Agent Activity Understandable
An agent could perform several operations before its answer was ready, especially for complex multi-document tasks. I worked on streaming progress displays, task lists, clarifications, and rewrite suggestion cards so writers could follow that activity in real time and respond when the assistant needed their input.
This included showing which documents the agent was reading, keeping proposed changes available across follow-up messages, and navigating between chat and manuscript passages. I also implemented features to stop generation, edit and resend messages (aka, branching), and collect feedback when something went wrong.
As the interface evolved, I helped move chat components into a shared Tamagui package that could be used across web and mobile, including the composer, Markdown rendering, thinking displays, and plan components. This substantially reduced the integration work needed to bring the web's agentic chat experience to the mobile app.
Preserving Intent Across Turns
Authors often brainstorm a few ideas with the agent and then send a short response like “yes” or “use the second one”, which depends on their previous messages. To be able to apply the changes to the document or Story Bible, the system needed to be able to identify the selected proposal, its destination, and whether the writer had authorized a document change.
To support this, I worked on structured tracking of goals, tasks, pending drafts, and approvals that allowed the agent to consistently perform single tasks or tasks that combined several activities, such as reviewing a chapter, suggesting a rewrite, and updating an outline all in one chat turn.
An important part of the work was replacing scattered text-matching rules with structured intent and explicit state transitions. I used XState for parts of the editing and placement lifecycle and worked on preserving task progress through clarification, cancellation, retries, and partial failures.
Our internal evaluation system helped set priorities when working on these features. Missed requests, failed actions, and lost context accounted for most of the serious problems it identified, so keeping the request connected to the agent's actions became a focus of the reliability work.
Coordinating Models and Tools
The system routed requests across models and specialized workflows according to the task's reasoning needs, quality, latency, and cost. I worked on structured tool output and runtime validation so malformed arguments could be caught before they became actions in a writer's project. Application code enforced authorization, project boundaries, and execution limits.
Some requirements depended on the order of operations. The agent needed to search before answering when a task required evidence, update memory only after an action succeeded, and report tool results only when those results existed. I reworked execution around state machines and Linear Temporal Logic (LTL) so those requirements could be checked in the execution trace instead of relying on the model to follow prompt instructions or declare itself finished.
This work brought turn-level problems from 40% down to about 15%, greatly improving the chat experience for authors.
I wrote more about these decisions in Why Your AI Agent Should Think in Temporal Logic and Why Agentic Chats Need a Verification Step.
Applying Changes to a Live Manuscript
Applying AI-generated revisions meant accounting for the manuscript's formatting, comments, and chapter boundaries, along with any changes the writer made while the agent was working. I worked on targeted editing through TipTap, ProseMirror, and Yjs so that revisions could fit into that existing structure while leaving the surrounding text intact.
Finding the intended passage wasn't always straightforward, though. A selection could be out of date, the same text could appear more than once, or a follow-up request could refer to a named chapter in a document other than the one currently open. To handle those cases, I worked on explicit document targeting and references that accounted for document revisions, then verified the changes that were actually applied. These checks helped keep edits within the requested scope, so a request to revise a paragraph wouldn't turn into a replacement of the entire manuscript.
Alongside identifying where an edit belonged, the system needed to track whether the writer had authorized it. That meant preserving the distinction between “Chat only” and “Allow edits” throughout the conversation, even when a discussion of possible revisions led to a request to apply one.
Telemetry showed a large volume of conversations involving manuscript and Story Bible edits, which made it important to keep conversation and document state coordinated throughout each request. These were instrumented interactions rather than counts of successful edits, so we used them to understand how the system was being used alongside separate quality evaluations.
Recovering Interrupted Work
A browser could disconnect while the server continued working. A worker could also stop after a document change had begun but before the final response reached the writer.
To reduce issues around interrupted work, I built durable tracking and recovery for agent document writes. Recording operations, using idempotency keys, and reconciling operation outcomes let the system check whether a change had been saved before retrying, helping avoid duplicate edits and requests that remained stuck.
Tracing stream timing, cancellation, and recovery made these failures easier to distinguish. We tracked reconnection attempts separately from verified recoveries, which helped us distinguish connection problems from failures to generate, deliver, or save work.
Grounding Answers in the Writer's Work
I expanded and refined access to manuscripts, Story Bible entries, comments, earlier conversations, and series context. Source references and navigation helped writers connect an answer to the material behind it.
Long manuscripts required pagination, summaries, and careful context management. I worked on incomplete-read detection, chapter coverage, bounded context, and retrieval performance so the agent could use relevant material without repeatedly loading unnecessary content.
Context selection also needed to follow the writer's current goal. I introduced intent-aware selection and compression that combined that goal with relevant conversation state, bounded document evidence, and retrieval or analysis results. This let a new request replace or refine earlier constraints without asking the model to infer every change from a growing transcript.
That mattered for editorial feedback: the agent needed to avoid presenting an assessment based on one chapter as a review of the entire novel.
I explored these ideas further in Conversation History Is Not State and Retrieval Is Not One Thing.
Measuring Reliability
My work contributed to a broader team effort to reduce consequential failures. Our observability tools evaluated sampled assistant turns and distinguished minor quality issues from problems that blocked the writer's task or caused more serious harm.
Across the evaluation periods we compared, the sampling-weighted rate of turns with serious problems fell substantially. Most of the improvement came from fewer Major problems, while Critical problems remained approximately flat. These results reflected the evolving product and the team's combined work, rather than the isolated effect of one change.
Our internal observability tool identified patterns worth investigating, while Raindrop exposed routing decisions, model calls, tool activity, and interruptions. Together, they helped us locate failures in the response, orchestration, persistence, or delivery.
I also contributed to an internal evaluation and replay interface for searching production conversations, filtering message-level errors, and rerunning a conversation from a selected starting point with changed models, prompts, tools, or configurations. It could load threads of 200+ messages, with virtualized rendering and incremental loading to keep them usable during an investigation.
Sentry, structured logs, traces, product metrics, Web Vitals, and session replay provided additional context. When a customer report could not be explained with the available signals, I added instrumentation to make the failure reproducible. We would isolate the affected context, tool, orchestration, model, or interface behavior, test a change against the original conversation and related regression cases, then monitor it after release.
Testing Promising Changes Against Real Usage
Additional validation in the agent loop sometimes rejected useful drafts, added delays, or caused repeated unnecessary recovery attempts. I worked on preserving usable output when secondary services failed, bounding retries, and making completion messages accurately describe partial success.
It wasn't always easy to tell from local testing if changes to the agent would improve its performance in the production app. One manuscript-delivery experiment substantially reduced its targeted failure rate in local testing, for example, but the live A/B test did not improve the Failed Action category or overall Turn Problem Rate. In cases like this, I would retire the candidate changes rather than rolling them out on the strength of the local result.
Performance work included reducing repeated manuscript conversions between formats, reusing chat history, improving text lookup, parallelizing independent preparation, and streaming draft previews earlier. I also developed debugging guidance and an agent skill for support and on-call engineers, connecting customer reports with traces, impact assessment, regression tests, and experiments.
Adoption and Customer Feedback
As the product evolved, chat daily active use increased by 6x to more than 6,000 users, and in-app customer satisfaction scores increased by 35%. Those outcomes reflected the broader product effort, alongside the reliability and interface work described here.
The experience reinforced the value of giving models a bounded reasoning task while keeping state, permissions, evidence, and recovery explicit in software. Writers needed the assistant's actions and completion messages to stay connected to what had actually happened in their manuscripts.
For related architecture and projects, see the Reliable AI Agents guide, the Accessible Plugin Generator case study, and the Bend Neighborhood Development Agent.
About the Measurements
Usage and recovery observations came from product analytics and execution telemetry with different instrumentation and reporting windows. I kept those distinctions in mind when interpreting the results, since message events, unique users, and successful edits measured different things.
Our internal observability tool's historical analysis included staff and canceled turns and used sampling weights. The periods also differed in runtime, request mix, judging, and judgment coverage. The results showed an observed quality trend, not controlled attribution to individual engineering changes.