Connecting Conversation and UI with Hermes: The Architecture of an AI Dialogue Plugin
DEV Community

Connecting Conversation and UI with Hermes: The Architecture of an AI Dialogue Plugin

I built a Hermes plugin that opens a form in the chat when you talk to it, helps you fill in the values through a GUI, and then runs the request through an SDK behind the scenes.

Purpose 🎯

  • An overview of the architecture I landed on
  • Problems I ran into along the way, and how I fixed them

I will not go into the SDK itself (the mechanics of sending funds).

1. How the model, the user, and the UI work together 🧩

There are three players:

Player Role
User Tells the chat what they want. Fills in the form and decides when to run it
Model Reads the conversation and decides what to do
UI Renders a form in the chat. Calls the SDK from the submit button

The model can only produce text and tool calls. Hermes therefore provides three mechanisms that connect the model to the outside world.

flowchart LR
U([User]) -- chat --> M[Model]
M -- 1.1 call a tool --> P[Plugin logic<br/>Python]
P -- return value + afterCall --> M
S[1.2 SKILL.md<br/>playbook] -. only when loaded .-> M
M -- 1.3 write a directive in the reply --> H[Hermes]
H -- replace with a component --> UI[Form<br/>React]
U -- input / submit --> UI
UI -- run --> SDK[(SDK)]
Mechanism Purpose Direction
tool Lets the model invoke processing Model ⇄ plugin logic
SKILL.md Teaches the model the procedure → Model
directive Hermes replaces it with a UI component Model → Hermes → UI

1.1 tool: a function the model can call

A tool is a function the model can call. The developer registers the name, the shape of the arguments, and the handler. The handler is written in Python.

ctx.register_tool(
  name='create_draft',
  schema={
    'name': 'create_draft',
    'description': 'Create a draft for a transfer',
    'parameters': {
      'type': 'object',
      'properties': {
        'kind': {'type': 'string', 'enum': ['send', 'deposit', ...]},
        'fields': {
          'type': 'object',
          'properties': {
            'network': {'type': ['string', 'null'], 'enum': ['polygon', 'base', ..., None]},
            'token': {'type': ['string', 'null'], 'enum': ['USDC', 'JPYC', ..., None]},
            'amount': {'type': ['string', 'null']},
            'to': {'type': ['string', 'null']},
          },
          'additionalProperties': False,
        },
      },
      'required': ['kind', 'fields'],
    },
  },
  handler=create_handler,
)

The only thing visible to the model is the schema. Every field allows null, and the allowed values are listed in an enum.

If the user says "I want to send 0.01 USDC," the model calls the tool with arguments in this shape. Fields the user did not mention are left as null rather than guessed.

{ "kind": "send", "fields": { "network": null, "token": "USDC", "amount": "0.01", "to": null } }

Hermes runs the handler and returns the result to the model. The model reads that result and writes its next reply.

This is where afterCall comes in. You put "rules to follow after the call" in the return value. Because the return value always reaches the model immediately after the tool is called, it is a good place for instructions that must not be skipped.

In practice, with a local model (qwen3.6), I saw it invent directive names, pass along unverified information, or skip the form I had prepared. I now put those same reminders in afterCall.

Here is a typical example:

{ "directive": "::draft-card{id=\"…\"}", "afterCall": "In your next reply, write the directive above on its own line, exactly as is. Do not ask for missing values in the chat. Collect input through the card." }

1.2 SKILL.md: a playbook you give the model

SKILL.md is a playbook you have the model read. You write "when asked to send funds, proceed like this" in Markdown.

---
name: send
description: "Start a transfer and report the result."
---
Do not ask for the network, token, amount, or destination in the chat. The form already has input fields. Write a short sentence, then put the directive on the next line.

The only thing that always goes into the system prompt is the one-line description. The body enters the conversation only when the model decides "I need this skill" and loads it.

The upside is that you can write a long procedure and still keep the everyday prompt short. The downside is that if the model never reads it, the procedure never arrives.

In other words, whether it gets read is up to the model. This comes up again in the wrap-up.

1.3 directive: one line in the reply becomes UI

A directive is a mechanism that replaces one line in the model's reply with a React component. On the UI side, you register a name and a component.

ctx.register(
  {
    area: TRANSCRIPT_DIRECTIVE_AREA, // a constant from the Hermes Plugin SDK
    data: {
      name: 'draft-card',
      render: (props) => <DraftCard {...props} />,
    },
  }
)

When the model replies like this, Hermes replaces the ::draft-card{...} line with a card. The contents of the curly braces are passed to the component as attrs.

I've opened a transfer form. Please fill in the rest.

::draft-card{token="USDC" amount="0.01"}

The model does not draw the screen. It just writes one line that means "put this component here."

The flow that connects tools and directives:

sequenceDiagram
actor U as User
participant M as Model
participant T as tool (Python)
participant H as Hermes
participant UI as Form (React)
participant SDK as SDK
U->>M: I want to send 0.01 USDC
M->>T: call create_draft
T-->>M: directive and afterCall
M->>H: write the directive in the reply
H->>UI: replace the directive line with a form
U->>UI: fill in the rest and submit
UI->>SDK: send funds

That was enough to get "talk to it and a form opens" working. But once the values had been passed from the directive attributes into the form, they existed only in React state (inside the screen). That is where the trouble started 😅

The problems

You cannot change the values in conversation while the form is open. Even if the user says "actually, make it 0.02," the model cannot read the form values, and it cannot edit them either. If it emits a new directive and opens a different form, the destination the user already typed in disappears.

After submit, the result never reaches the model. It is the UI that runs the operation. Only the UI knows the operation ID and the result. If the user asks "what happened to that transfer?", the model has nothing to answer with.

There is a risk of double submission. A flag in the UI can stop a button from being mashed, but it cannot stop the same form being opened twice, or a retry after the app is restarted.

All three have the same root cause: where the values live. If you put them in the reply, the UI cannot edit them. If you put them in UI state, the model cannot read them.

So I decided to put them somewhere that is neither of those places. That somewhere is SQLite.

2. Introducing SQLite 🗄️

2.1 Architecture with SQLite

flowchart LR
U([User]) -- chat --> M[Model]
M -- create / read / update / cancel --> T[tool<br/>Python]
T -- return value + afterCall + directive --> M
T <--> DB[(Draft<br/>SQLite)]
M -- "::draft-card{id=…}" --> H[Hermes]
H -- replace with a component --> UI[Card<br/>React]
UI <-- plugin REST API --> DB
U -- input / submit --> UI
UI -- send funds --> SDK[(SDK)]

Each chat session holds one draft row. The model reads and writes that same row through tools; the UI does it through the plugin's REST API.

The table actually looks like this (only the columns needed for this explanation):

CREATE TABLE drafts (
  id TEXT PRIMARY KEY,
  session_id TEXT NOT NULL,
  kind TEXT NOT NULL,
  fields TEXT NOT NULL, -- input values (JSON)
  revision INTEGER NOT NULL, -- incremented by 1 whenever a value changes
  state TEXT NOT NULL, -- editing / sending / consumed / cancelled
  claim_token TEXT,
  operation_id TEXT,
  outcome TEXT,
  ...
);

To summarize, I chose SQLite for these two reasons:

  • The data has to survive across conversation turns. A tool runs and exits every time it is called, so the data cannot live in memory.
  • Both the Python side and the UI side need to reach it. The file lives on the Python side, and the UI goes through an API.

There is only one table, so I skipped an ORM and manage the schema version with PRAGMA user_version. The only thing the directive now passes is the ID. Every time the card opens, it reads the latest saved values.

3. Summary 🧭

  • A tool is the path the model uses to invoke processing and receive a result. With afterCall in the return value, you can reliably deliver reminders immediately after the call.
  • SKILL.md is a playbook. It only arrives when the model actually loads it.
  • A directive is a mechanism that turns one line of a reply into UI.
  • If you keep values inside the screen, you cannot edit them in conversation, report results after submit, or prevent double submission. I solved this by putting them in a SQLite draft, which the model reads and writes through tools and the UI reads and writes through an API.

That said, I ran into one more wall. When the text a plugin adds to the system prompt (the prompt section) exceeds 4,000 characters, a local model (qwen3.6) did not load it at all. The plugin cannot raise this limit.

As I added more transfer types, it grew to 4,482 characters, and the model stopped calling tools entirely and started answering everything in the chat 😅

I also tried moving the procedure out into SKILL.md. But that model (qwen3.6) did not read the skill, and started asking for the destination in the chat. It was exactly the "if it does not read it, it never arrives" problem I described in 1.2.

For now, I write only a short one-line "when to use this" for each type, and push the detailed rules into the tool schema, afterCall, and validation on the card, so everything stays under the limit. If the number of types keeps growing, though, we will run out of room eventually. I am still thinking about how to handle that.

References

  • Source code of the Hermes plugin SDK (tool registration, directives, prompt sections)
  • SQLite: UPDATE, Partial Indexes, PRAGMA user_version
Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.