AgenticAI — a WebView2 agent UI

Source: samples/AgenticAI/agenticai.prg (+ agenticai.hbp, build.bat)

AgenticAI is a FiveWin GUI front-end for the ccharbour agentic engine. It runs the same streaming chat + tool-calling loop that powers the console cc.exe (CC_Client / CC_AgentRun), but renders it as a modern web chat panel hosted in an embedded Edge WebView2 (TWebView2) that fills a resizable dialog — no RichEdit, no .rc.

flowchart LR U[User types in webview] -->|SendToFWH| P[OnJsMessage queues prompt] P --> T[TTimer launches turn] T --> A[CC_AgentRun] A -->|libcurl transport| L[LLM SSE stream] L -->|events| E[OnEvent] E -->|oWeb:Eval JS| W[Chat panel updates live] A -->|tool_call| G[Permission gate] G -->|permit/reject card| W

What the panel shows

PRG ↔ page bridge

PRG drives the page with oWeb:Eval( jsFunc(...) ); the page calls back with SendToFWH( action, text ), delivered to TWebView2:bOnBind. The full local tool set (read / write / edit / glob / grep / shell / web_search / web_fetch / memory) is registered and wrapped in a permission gate.

Three gotchas worth remembering

ProblemCause & fix
Permit / ask / stop click deadlocks mid-turn WebView2 does not deliver a second bound-function call while the first bOnBind is still on the stack. So send only queues the prompt; a TTimer launches the turn from WM_TIMER, outside any bOnBind, where the nested permit/ask/stop clicks are delivered.
Accents / emoji mojibake WebView2_Eval converts its argument from the ANSI codepage. Pass every non-ASCII codepoint as a pure-ASCII \uXXXX-escaped JS string literal (surrogate pairs for emoji) so it is codepage-independent.
The whole <script> silently failed A Harbour TEXT INTO block is C-escape-processed: '\n' inside JS became a real line feed and broke the string. Keep the embedded JS backslash-free — use String.fromCharCode(10) and character-class regexes ([0-9], [ ]) instead of \n, \d, \s.

Build & run

Multi-module (GUI prg + ccharbour core), so it is built with its own build.bat (hbmk2 + agenticai.hbp), not samples/build_new.bat. It needs the WebView2 runtime installed and an LLM key (env DEEPSEEK_API_KEY … or /key at runtime).

cd /d C:\fwteam\samples\AgenticAI
build.bat

See Also