Skip to content

Agent Mode

ZhengY-LI edited this page Jul 1, 2026 · 3 revisions

How Agent Mode starts

Users enter Agent Mode from the editor toolbar. The editor swaps in the chat panel while keeping the same document state and preview.

Before the agent can run, the user must provide LLM configuration. The config includes a base URL, API key, and model name. It is saved in localStorage so the user can reuse it later.

What happens when the user sends a message

When the user sends a chat message, the chat panel starts the agent stream.

The agent request is built from the system prompt, current document state, example style context, clarification scope, project instructions, retrieved file excerpts, prior chat messages, and the latest user message.

The current document state is always treated as the source of truth. This matters when the user edits the form manually between chat turns.

Structured editing tools

The model does not edit the document by returning raw JSON. It calls tools.

Tool definitions use LangChain DynamicStructuredTool. Each tool has a Zod schema. When a tool call succeeds, the executor applies the update to a pure document object, then the editor receives the new content through onChange.

This keeps edits controlled. The agent can update resume sections, academic CV sections, and cover letter sections through specific tools.

Tool loop

Agent Mode runs a small loop. The model may respond with tool calls. The app executes those tools, appends tool results back into the model conversation, then asks the model to continue.

The loop stops when the model gives a final reply, asks for clarification, or reaches the loop limit.

If a tool succeeds but the model does not send final text, CVForge creates a short fallback completion message so the user still gets a clear result.

Clarification flow

The agent should ask focused questions only when a required detail is missing, ambiguous, and unsafe to infer.

This is handled through the ask_user tool. When the model calls it, the chat panel opens a clarification dialog instead of treating the question as normal chat text.

Clarification is scoped. If the user asked about one section, the question must stay inside that section. If the request is whole document polish or spans multiple sections, the app disables ask_user for that turn and asks the model to proceed with safe edits or ask in normal chat.

The app allows only a small number of clarification rounds. Once the user answers, the chat panel builds a continuation message that includes the original task, the answer, the prior question, and the section scope. The agent then continues the original edit.

There is also a defensive fallback. If the model writes a plain text question that looks like a blocking clarification, the UI can convert it into the same clarification dialog.

Inference recording

The agent may make high confidence low risk inferences, such as normalizing a well known university name or city. It should not infer risky personal facts like grades, dates, awards, job titles, metrics, or publication details.

When it writes an inferred value, it uses the record_inference tool. The final assistant reply then discloses what was inferred in a concise sentence.

Project instructions

The context dialog includes project instructions. These are persistent user preferences for the current editor session.

They are stored in agent session state and included as system context on future turns. They guide replies and document edits, but they do not override higher priority rules or the current user message.

This is useful for preferences like tone, target role, or how strongly to use an uploaded job description.

Uploaded context files

Users can upload PDF, Markdown, or plain text files as reference context. The limit is five files, with each file up to six megabytes.

The upload flow checks unsupported formats, duplicate files, file size, empty files, password protected PDFs, invalid PDFs, and PDF worker failures.

PDFs are read with PDF.js. CVForge assumes the PDF contains selectable text. It does not perform OCR. Text is read page by page and page labels are added so the agent can refer to the source more clearly.

The full extracted text is stored in sessionStorage and can be previewed by the user.

Context retrieval

Uploaded files are not injected into the model in full.

CVForge chunks the extracted text, indexes the chunks with MiniSearch, and searches them with the current user message. The agent receives only the most relevant excerpts, with source name and chunk number.

This keeps the prompt smaller, reduces unrelated noise, and makes long reference files more usable.

If the user message is too broad or no good match is found, the app falls back to a small set of early chunks instead of sending everything.

Uploaded files are treated as untrusted reference material. If a file contains instructions like ignore previous rules, the prompt tells the agent to ignore those instructions and use the file only as factual source material.

Context usage indicator

The chat panel estimates context usage from the system prompt, document state, example style context, project instructions, retrieved file excerpts, and chat history.

The estimate is model aware. It uses known context window sizes for common model families and a fallback window for unknown models.

This gives users a practical signal when the conversation is becoming large.

Compact chat context

Users can compact chat history from the chat panel.

Compaction sends the prior conversation and current document state to the configured model and asks for a durable memory note. The result becomes a special context summary message.

Compaction affects chat history only. It does not remove uploaded files or project instructions.

Change tracking and review highlights

When tools update the document, CVForge records a before and after signature. It builds an agent change object and shows a change card in chat.

The preview can highlight changed text so the user sees what the agent touched. This is especially useful after larger polish tasks.

Undo

The user can undo the last agent edit if the current document still matches the recorded after state. This guard prevents undo from accidentally overwriting manual edits made after the agent change.

Cancel and errors

While the agent is running, the user can cancel the task. The app aborts the active request, stops streaming, and keeps any completed document updates that already happened.

Configuration errors clear the active config and ask the user to fix settings. File reading errors are shown inside the context dialog with user friendly messages.

Language handling

Agent Mode separates UI language from document language.

For resumes and academic CVs, document language can be English or Chinese. The prompt tells the agent to write document content in the selected document language and to use the example style for dates, location order, labels, and writing density.

Chinese output is normalized so punctuation and spacing stay consistent with the project style.

Why the design works

Agent Mode is powerful, but it stays bounded.

The model reasons and writes. Tools perform document updates. The browser owns the state. Uploaded files are searchable references, not hidden commands. Clarification is used only when it protects the document from bad guesses.

That balance keeps the feature useful without turning the editor into a black box.

Clone this wiki locally