{"slug": "connecting-conversation-and-ui-with-hermes-the-architecture-of-an-ai-dialogue", "title": "Connecting Conversation and UI with Hermes: The Architecture of an AI Dialogue Plugin", "summary": "A developer built Hermes, an AI dialogue plugin that renders interactive forms directly in chat, letting a model call tools to create drafts while a React UI collects missing values and submits the request through an SDK. The architecture links the model to the outside world through three mechanisms: Python-registered tools with JSON schemas, a SKILL.md playbook loaded on demand, and directives that Hermes replaces with UI components. The developer reports that a local model (qwen3.6) sometimes invented directive names or skipped the form, prompting the use of an afterCall field to carry mandatory follow-up instructions back to the model.", "body_md": "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.\n\nI will not go into the SDK itself (the mechanics of sending funds).\n\nThere are three players:\n\n| Player | Role | \n|---|---|\n| User | Tells the chat what they want. Fills in the form and decides when to run it | \n| Model | Reads the conversation and decides what to do | \n| UI | Renders a form in the chat. Calls the SDK from the submit button | \n\nThe model can only produce text and tool calls. Hermes therefore provides three mechanisms that connect the model to the outside world.\n\n``` php\nflowchart LR\n    U([User]) -- chat --> M[Model]\n    M -- 1.1 call a tool --> P[Plugin logic<br/>Python]\n    P -- return value + afterCall --> M\n    S[1.2 SKILL.md<br/>playbook] -. only when loaded .-> M\n    M -- 1.3 write a directive in the reply --> H[Hermes]\n    H -- replace with a component --> UI[Form<br/>React]\n    U -- input / submit --> UI\n    UI -- run --> SDK[(SDK)]\n```\n\n| Mechanism | Purpose | Direction | \n|---|---|---|\n| tool | Lets the model invoke processing | Model ⇄ plugin logic | \n| SKILL.md | Teaches the model the procedure | → Model | \n| directive | Hermes replaces it with a UI component | Model → Hermes → UI | \n\nA 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.\n\n```\nctx.register_tool(\n  name='create_draft',\n  schema={\n    'name': 'create_draft',\n    'description': 'Create a draft for a transfer',\n    'parameters': {\n      'type': 'object',\n      'properties': {\n        'kind': {'type': 'string', 'enum': ['send', 'deposit', ...]},\n        'fields': {\n          'type': 'object',\n          'properties': {\n            'network': {'type': ['string', 'null'], 'enum': ['polygon', 'base', ..., None]},\n            'token':   {'type': ['string', 'null'], 'enum': ['USDC', 'JPYC', ..., None]},\n            'amount':  {'type': ['string', 'null']},\n            'to':      {'type': ['string', 'null']},\n          },\n          'additionalProperties': False,\n        },\n      },\n      'required': ['kind', 'fields'],\n    },\n  },\n  handler=create_handler,\n)\n```\n\nThe 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.\n\n```\n{\n  \"kind\": \"send\",\n  \"fields\": { \"network\": null, \"token\": \"USDC\", \"amount\": \"0.01\", \"to\": null }\n}\n```\n\nHermes runs the `handler` and returns the result to the model. The model reads that result and writes its next reply.\n\nThis 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.\n\nIn 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`.\n\nHere is a typical example:\n\n```\n{\n  \"directive\": \"::draft-card{id=\\\"…\\\"}\",\n  \"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.\"\n}\n```\n\n`SKILL.md` is a playbook you have the model read. You write \"when asked to send funds, proceed like this\" in Markdown.\n\n```\n---\nname: send\ndescription: \"Start a transfer and report the result.\"\n---\n\nDo not ask for the network, token, amount, or destination in the chat.\nThe form already has input fields. Write a short sentence, then put the directive on the next line.\n```\n\nThe 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.\n\nA 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.\n\n```\nctx.register({\n  area: TRANSCRIPT_DIRECTIVE_AREA, // a constant from the Hermes Plugin SDK\n  data: {\n    name: 'draft-card',\n    render: (props) => <DraftCard {...props} />,\n  },\n})\n```\n\nWhen 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`.\n\n```\nI've opened a transfer form. Please fill in the rest.\n\n::draft-card{token=\"USDC\" amount=\"0.01\"}\n```\n\nThe model does not draw the screen. It just writes one line that means \"put this component here.\"\n\n```\nsequenceDiagram\n    actor U as User\n    participant M as Model\n    participant T as tool (Python)\n    participant H as Hermes\n    participant UI as Form (React)\n    participant SDK as SDK\n\n    U->>M: I want to send 0.01 USDC\n    M->>T: call create_draft\n    T-->>M: directive and afterCall\n    M->>H: write the directive in the reply\n    H->>UI: replace the directive line with a form\n    U->>UI: fill in the rest and submit\n    UI->>SDK: send funds\n```\n\nThat 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 😅\n\nAll 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.\n\nSo I decided to put them somewhere that is neither of those places. That somewhere is SQLite.\n\n``` php\nflowchart LR\n    U([User]) -- chat --> M[Model]\n    M -- create / read / update / cancel --> T[tool<br/>Python]\n    T -- return value + afterCall + directive --> M\n    T <--> DB[(Draft<br/>SQLite)]\n    M -- \"::draft-card{id=…}\" --> H[Hermes]\n    H -- replace with a component --> UI[Card<br/>React]\n    UI <-- plugin REST API --> DB\n    U -- input / submit --> UI\n    UI -- send funds --> SDK[(SDK)]\n```\n\nEach 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):\n\n```\nCREATE TABLE drafts (\n  id TEXT PRIMARY KEY,\n  session_id TEXT NOT NULL,\n  kind TEXT NOT NULL,\n  fields TEXT NOT NULL,        -- input values (JSON)\n  revision INTEGER NOT NULL,   -- incremented by 1 whenever a value changes\n  state TEXT NOT NULL,         -- editing / sending / consumed / cancelled\n  claim_token TEXT,\n  operation_id TEXT,\n  outcome TEXT,\n  ...\n);\n```\n\nTo summarize, I chose SQLite for these two reasons:\n\nThere is only one table, so I skipped an ORM and manage the schema version with `PRAGMA user_version`.\n\nThe only thing the directive now passes is the **ID**. Every time the card opens, it reads the latest saved values.\n\n`afterCall` in the return value, you can reliably deliver reminders immediately after the call.`SKILL.md`\nThat 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 😅\n\nI 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.\n\nFor 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.", "url": "https://wpnews.pro/news/connecting-conversation-and-ui-with-hermes-the-architecture-of-an-ai-dialogue", "canonical_source": "https://dev.to/toshiya_matsumoto_ac94abe/connecting-conversation-and-ui-with-hermes-the-architecture-of-an-ai-dialogue-plugin-3kg6", "published_at": "2026-11-23 06:01:40+00:00", "updated_at": "2026-11-23 06:11:40.792693+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "large-language-models", "generative-ai"], "entities": ["Hermes", "qwen3.6"], "also_reported_by": [], "takeaway": "Returning an afterCall field alongside a tool result reliably forces a local model to emit the exact UI directive on the next turn, after qwen3.6 was observed inventing directive names and skipping the form.", "recommendation": {"advice": "Put mandatory post-tool instructions in the tool's return value (afterCall) rather than the system prompt, since the result always reaches the model immediately after the call.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/connecting-conversation-and-ui-with-hermes-the-architecture-of-an-ai-dialogue", "markdown": "https://wpnews.pro/news/connecting-conversation-and-ui-with-hermes-the-architecture-of-an-ai-dialogue.md", "text": "https://wpnews.pro/news/connecting-conversation-and-ui-with-hermes-the-architecture-of-an-ai-dialogue.txt", "jsonld": "https://wpnews.pro/news/connecting-conversation-and-ui-with-hermes-the-architecture-of-an-ai-dialogue.jsonld"}}