SDK for TESAIoT Dev Kit
API reference & tutorials (ModusToolbox)
Loading...
Searching...
No Matches
nus_agent.h
Go to the documentation of this file.
1/*******************************************************************************
2 * File Name: nus_agent.h
3 *
4 * Description: Desktop -> Device agent stream handlers for the LLM-side loop
5 * that runs inside Bento Desktop Buddy. The device originates a
6 * bento.agent.ask (from the LCD ASK submode), then the desktop
7 * streams back bento.agent.token frames, optional
8 * bento.agent.tool_call notifications (log-only on the device),
9 * and finally a bento.agent.done frame carrying the full answer.
10 *
11 * Contract:
12 * 1. One in-flight request id at a time. Token frames whose id
13 * doesn't match the latest ask are silently dropped.
14 * 2. Accumulator is bounded (256 chars) — overflow truncates.
15 * 3. On .done, the final text is forwarded to the CM55 page via
16 * IPC_CMD_BUDDY_AGENT_RESPONSE so the ASK submode can render.
17 * 4. .tool_call is observability-only: we emit a hint-text IPC
18 * so the scrolling marquee shows which tool is running.
19 *
20 ******************************************************************************/
21
22#ifndef NUS_AGENT_H
23#define NUS_AGENT_H
24
25#include <stddef.h>
26#include <stdint.h>
27
28#include "vendor/jsmn.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34/* Returns the number of bytes currently buffered for the in-flight agent ask.
35 * 0 when idle. Exposed for telemetry + host unit tests. */
37
38/* Reset the accumulator — called when the LCD user leaves the ASK submode or
39 * when a new ask is issued. Discards any partial text. Safe to call from any
40 * task context (simple memset; single-reader single-writer on the BLE task). */
41void nus_agent_reset(void);
42
43/* Record a new in-flight ask id so subsequent token/done frames can be matched.
44 * Called from page_bento_buddy before (or in parallel with) the IPC-originated
45 * bento.agent.ask emission. Truncates ids longer than the internal buffer. */
46void nus_agent_note_ask(const char *id);
47
48/* Handle bento.agent.token — appends the "delta" string to the in-flight
49 * request's accumulator. Returns 0 if accepted, -1 if the id doesn't match the
50 * current ask (silently dropped) or the delta field is missing. */
51int nus_agent_handle_token(const char *json, const jsmntok_t *toks, int n_toks);
52
53/* Handle bento.agent.done — emits the final text to the CM55 UI via
54 * IPC_CMD_BUDDY_AGENT_RESPONSE and resets the accumulator. Returns 0 on
55 * success. The "text" field is authoritative; if missing, the accumulated
56 * deltas are forwarded instead. */
57int nus_agent_handle_done(const char *json, const jsmntok_t *toks, int n_toks);
58
59/* Handle bento.agent.tool_call — log-only on the device (tool execution
60 * happens desktop-side). Emits a short hint-text IPC to the CM55 marquee so
61 * the user sees which tool is running. Returns 0. */
62int nus_agent_handle_tool_call(const char *json, const jsmntok_t *toks, int n_toks);
63
64#ifdef __cplusplus
65}
66#endif
67
68#endif /* NUS_AGENT_H */
struct jsmntok jsmntok_t
Definition bento_fw.h:33
int nus_agent_handle_done(const char *json, const jsmntok_t *toks, int n_toks)
Forward the final text to the CM55 page over IPC and reset; "text" is authoritative.
int nus_agent_handle_tool_call(const char *json, const jsmntok_t *toks, int n_toks)
Observability only — a short hint-text IPC so the CM55 marquee shows which tool runs.
size_t nus_agent_buffer_len(void)
Bytes buffered for the in-flight ask; a telemetry probe, not a synchronisation primitive.
int nus_agent_handle_token(const char *json, const jsmntok_t *toks, int n_toks)
Append a "delta" to the accumulator; -1 on id mismatch (silently dropped).
void nus_agent_reset(void)
Clear the in-flight ask id and the accumulator; no init, no locking, no return.
void nus_agent_note_ask(const char *id)
Record the in-flight ask id; a NULL or empty id resets the agent. No caller anywhere.