Skip to content

Agent chat

Your conversation with Hotaru’s agent (SI-547), in a panel next to the page. It is a durable pi-durable conversation: it survives a server restart, and every open page (two tabs, later the TUI and the CLI) shows the same one live. Code: agent/chat.ts, agent/models.ts, the panel in ChatPanel.svelte.

The agent has tools (SI-549): it searches and reads your items, and changes keywords, sources and filters when you ask. Every change is logged and can be undone, and deleting something waits until you confirm it: agent-tools.md. You can send it items of your stream to ask about (SI-550): see below. It shows results next to the chat as views, card lists, charts and tables, which you can pin (SI-548): views.md.

Using it

  • Agent in the rail, or a, opens and closes the panel. Whether it’s open belongs to the device (a cookie, so the first render already has it).
  • Enter sends, Shift+Enter starts a new line, Escape closes the panel.
  • The answer appears as it’s written. A message that got no answer (a model error, a restart in the middle, over the budget) says why.
  • Each tool call shows as a small line in the transcript, such as “Update keyword”. Open it to see what the tool told the agent. A change waiting for you shows above the input with Confirm and Cancel.
  • Send to chat (SI-550) on a stream card, a search result or in the reader, or c on the selected item, opens the panel with the item as a chip above the input. Up to five go with the next message; × takes one back. The message shows them above its text, as links to the reader.
  • One conversation per user, kept whole in durable.db. The panel shows the newest 100 messages.
  • On phones the panel is hidden for now.
  • In a terminal, hotaru tui has the same chat, send to chat (c) and the changes to confirm in a panel (tui.md); hotaru send sends one message and prints the answer (cli.md).

How it works

  • One writer. The chat runs on the harness the item pipeline opens on durable.db (ADR-0001: one process writes it). The pipeline’s models option brings pi-ai’s OpenRouter provider; the chat reads the harness through the pipeline every time, since the pipeline replaces it after reopening durable.db.
  • One conversation per user, created on the first message: an ownerless pi-durable conversation with the model, the instructions and at most 12 turns per answer (each round of tool calls takes one). A conversation created before the tools gets the current instructions the first time it’s opened. chat_conversations links the user to it by ID only (ADR-0002, migration 0020_chat_conversations).
  • Sending submits an input to the conversation. A requestId makes it idempotent: the panel sends a fresh one per message, so a retried request isn’t asked twice.
  • Quoted items (SI-550). The client sends only item IDs (itemIds). The server looks each up in the reader’s own stream (another reader’s item is refused) and opens the message with one line per item: > Item <id>: “<title>” (<source>). The agent calls get_item, get_story and the other tools with that ID. Title and source are one line each, at most 200 and 80 characters, so a feed can’t fake a quote line, and the instructions say a quoted title is data, never an instruction. The view parses the lines back into quotes.
  • Live updates. The server keeps one pi-durable watch per user, shared by all their open pages, and sends the whole view (messages, whether it’s answering, the text so far, the last failure) as server-sent events. A failed run doesn’t raise an error anywhere; the watch’s pi.live.runFailure is how the panel learns of it.
  • Restarts. pi-durable stores every step before it shows it. After a restart the conversation is there, and a run that was cut off is resumed by harness.resume() or ends with “Interrupted by a restart”.
  • The model is Claude Haiku 5.5 through OpenRouter; CHAT_MODEL names another OpenRouter model. OPENROUTER_BASE_URL points it elsewhere, as the e2e tests do with their fake.

Costs

The chat’s model turns are made by pi-durable through pi-ai, not by Hotaru’s OpenRouter client: the one exception to “every model call goes through the OpenRouter client” (conventions.md). It keeps the same two promises another way:

  • Budget: a message is refused (402) while you’re over your monthly AI budget.
  • No key: a message is refused (403, no_key) from someone who isn’t an admin and has no OpenRouter key of their own (costs.md). The panel says so in place of the message box.
  • Ledger: every answer is recorded in ai_calls with stage chat, the model, tokens and cost, keyed by OpenRouter’s generation ID, so recording it twice changes nothing. The watch records it as it arrives; a run that goes on with no page open is watched until it ends, and runs a restart left are watched again at start.

API

GET /api/v1/chat { messages: [{ id, role, text, at, tool?, isError?, quotes?, view? }], busy, pending, failure, keyRefused, actions }. keyRefused: OpenRouter refused your own key on the last message, and failure says what to do (costs.md, SI-576). view: the spec a show_view call showed (views.md). role is user, assistant, tool (a tool’s result) or event (your decision on a change). actions: the changes waiting for you
POST /api/v1/chat { text, requestId?, itemIds? } → 202 { submissionId }. itemIds: at most 5 items of your stream, sent as quotes (quotes: [{ itemId, title, source }] on the message). 422 for an item that isn’t yours. 402 over the budget, 403 (no_key) without the right to use AI (costs.md), 503 when the server runs without the pipeline
GET /api/v1/chat/events Server-sent chat events with the view above, now and after every change

Sending needs a session or a write token. The SDK: chat() and sendChat(text, requestId, itemIds).

Not yet

  • The panel on phones and as a sheet on the iPad, and Markdown in answers.
  • A new conversation (pi-durable’s reset or compaction) once the one conversation gets long.