feat(cli)!: add agent-first chat and session ask output modes
This commit is contained in:
@@ -17,8 +17,8 @@ one wastes turns or returns the wrong shape. Use the decision table.
|
||||
|
||||
| Your goal | Command | LLM synthesis? | Returns |
|
||||
|---|---|---|---|
|
||||
| Natural-language **answer** grounded in a KB | `chat "<q>" --kb <kb>` | yes | streaming answer + references |
|
||||
| Answer via a **custom agent** (its own KB scope, tools, web search) | `session ask --agent <id> "<q>"` | yes (+ tools) | streaming answer + tool events |
|
||||
| Natural-language **answer** grounded in a KB | `chat "<q>" --kb <kb>` | yes | bounded answer events; `--reference` adds citations; `--verbose` adds execution detail |
|
||||
| Answer via a **custom agent** (its own KB scope, tools, web search) | `session ask --agent <id> "<q>"` | yes (+ tools) | bounded answer events; `--reference` adds citations; `--verbose` adds execution detail |
|
||||
| **Raw context chunks** to reason over yourself (no answer) | `search chunks "<q>" --kb <kb>` | no | ranked chunk list |
|
||||
| Which **documents** match a keyword (title/filename) | `search docs "<q>" --kb <kb>` | no | document list |
|
||||
| Find a **knowledge base** by name | `search kb "<q>"` | no | KB list |
|
||||
@@ -33,9 +33,9 @@ one wastes turns or returns the wrong shape. Use the decision table.
|
||||
<id>` = invoke a *configured custom agent* (it may scope its own KBs, call
|
||||
tools, do web search). If the user set up an agent for this, prefer it
|
||||
(`weknora agent list` to find ids); otherwise `chat`.
|
||||
3. **One-shot vs multi-turn.** Both `chat` and `session ask` print an `init`
|
||||
event with a `session_id`. Pass `--session <id>` on the next call to continue
|
||||
the conversation. See `references/chat.md`.
|
||||
3. **One-shot vs multi-turn.** Both `chat` and `session ask` return a
|
||||
`data.session_id` in default JSON output. Pass `--session <id>` on the next
|
||||
call to continue the conversation. In NDJSON mode, read it from `init`.
|
||||
|
||||
## Safety / Gotchas
|
||||
|
||||
@@ -44,12 +44,14 @@ one wastes turns or returns the wrong shape. Use the decision table.
|
||||
If none resolves it's exit 1 (`local.kb_id_required`); a bad name is exit 1
|
||||
(`local.kb_not_found`). Resolve names with `weknora kb list` / `search kb`.
|
||||
(`search kb` / `search sessions` are tenant-wide and take no `--kb`.)
|
||||
- `chat` / `session ask` stream **NDJSON** by default. Parse line-by-line; keep
|
||||
the `init` event's `session_id` **and** `message_id`. Use `--format text` only
|
||||
for a human transcript.
|
||||
- `chat` / `session ask` return one buffered JSON envelope with answer
|
||||
events by default. Add `--reference` for indexed citations and `--verbose`
|
||||
for execution detail; use `--format ndjson` for raw events or `--format
|
||||
text` for the live human-readable projection.
|
||||
- A stalled stream is not stopped by Ctrl-C (that just drops your local
|
||||
connection; the server keeps generating + billing). Stop it server-side:
|
||||
`weknora session stop <session-id> --message <message-id>` (ids from `init`).
|
||||
`weknora session stop <session-id> --message <message-id>` (session_id from
|
||||
`data.session_id`, or from `init` under `--format ndjson`).
|
||||
Re-attach to a stream with `weknora session continue-stream <session-id>
|
||||
--message <message-id>`.
|
||||
- `search chunks --limit` defaults to **8** (tuned for an LLM context window);
|
||||
@@ -66,7 +68,7 @@ weknora search chunks "retry backoff policy" --kb engineering --limit 12
|
||||
# grounded answer (human transcript)
|
||||
weknora chat "How do we handle retries?" --kb engineering --format text
|
||||
|
||||
# continue the conversation (session id from the prior init event)
|
||||
# continue the conversation (session id from data.session_id above)
|
||||
weknora chat "And the max attempts?" --kb engineering --session sess_abc
|
||||
|
||||
# answer via a custom agent
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# `chat` and `session ask` — streaming RAG
|
||||
# `chat` and `session ask` — RAG answers and raw streams
|
||||
|
||||
Both stream an NDJSON event log (one JSON object per line) by default. They share
|
||||
the same event vocabulary; `chat` does plain KB RAG, `session ask` invokes a
|
||||
custom agent.
|
||||
Both return one buffered JSON envelope with answer events by default.
|
||||
`--reference` adds lookup-index references; `--verbose` adds execution events.
|
||||
They share the raw SSE vocabulary under `--format ndjson`; `chat` does plain KB
|
||||
RAG, `session ask` invokes a custom agent.
|
||||
|
||||
## Commands & flags
|
||||
|
||||
@@ -13,15 +14,20 @@ weknora session ask "<query>" --agent <agent-id> [--session <id>]
|
||||
|
||||
- `--kb` (chat) is required name-or-id. `--agent` (session ask) is required.
|
||||
- `--session <id>` continues an existing conversation; omit to start a new one.
|
||||
- `--format text` renders a human transcript instead of NDJSON; `--format json`
|
||||
/ `--format ndjson` both produce the NDJSON stream (identical here).
|
||||
- `--format json` returns one `{ok,data:{events:[...]}}` envelope; `--format
|
||||
text` streams the same projection as readable text; `--format ndjson` emits
|
||||
the raw event stream.
|
||||
- `--reference` adds bounded reference indexes to JSON/text.
|
||||
- `--verbose` adds thinking, reflection, tool, metadata, and lifecycle events.
|
||||
- Combine them when both provenance and execution detail are needed.
|
||||
|
||||
## Event stream
|
||||
## Event stream (`--format ndjson`)
|
||||
|
||||
The CLI emits an `init` line first, then passes SDK events through verbatim:
|
||||
Under `--format ndjson`, the CLI emits an `init` line first, then passes SDK
|
||||
events through verbatim:
|
||||
|
||||
```jsonc
|
||||
{"event":"init","session_id":"sess_abc","message_id":"msg_xyz","profile":"prod"}
|
||||
{"type":"init","session_id":"sess_abc","kb_id":"…","profile":"prod"} // session ask: agent_id instead of kb_id
|
||||
{"response_type":"thinking","content":"…"}
|
||||
{"response_type":"tool_call","tool_calls":[…]} // agent only
|
||||
{"response_type":"tool_result","content":"…"} // agent only
|
||||
@@ -32,9 +38,9 @@ The CLI emits an `init` line first, then passes SDK events through verbatim:
|
||||
|
||||
- Accumulate `response_type:"answer"` `content` pieces for the final answer.
|
||||
- `knowledge_references` carry the grounding chunks (source attribution).
|
||||
- **Keep `init.session_id` and `init.message_id`**: `session_id` continues the
|
||||
chat (`--session`); `message_id` is needed to `session stop` or
|
||||
`session continue-stream` that specific message.
|
||||
- **Keep `init.session_id`** to continue the chat (`--session`). The
|
||||
`assistant_message_id` needed for `session stop` / `session continue-stream`
|
||||
rides on the SDK's `agent_query` frame, not on `init` — scan for it.
|
||||
- On failure mid-stream you get `response_type:"error"`; a transport/HTTP error
|
||||
surfaces as the normal error envelope on stderr with a typed code.
|
||||
|
||||
|
||||
@@ -57,9 +57,11 @@ Default output is `--format json`: a single envelope.
|
||||
- `error.type` is a **stable typed code** (e.g. `local.kb_not_found`,
|
||||
`input.invalid_argument`, `input.confirmation_required`, `server.error`).
|
||||
Branch on it; `error.hint` usually tells you the next action.
|
||||
- `--format text` = human output. Streaming commands (`chat`, `session ask`,
|
||||
`session continue-stream`) emit **NDJSON event lines** by default — expect a
|
||||
stream, not one blob; use `--format text` for a rendered transcript.
|
||||
- `--format text` = a live human-readable projection. `chat` and `session ask`
|
||||
buffer a bounded answer-event projection into one JSON envelope by default;
|
||||
pass `--reference` for indexed citations, `--verbose` for execution detail,
|
||||
or `--format ndjson` for raw event lines. `session continue-stream` remains
|
||||
an NDJSON streaming command.
|
||||
- `--jq '<expr>'` filters the envelope (e.g. `weknora kb list --jq '.data[].id'`).
|
||||
- Exception: `weknora auth token` emits the **raw token** by default (it's a
|
||||
scripting helper); pass `--format json` for the `{token, mode, profile}` envelope.
|
||||
@@ -165,5 +167,5 @@ that to learn a command without scraping the human help table.
|
||||
| `weknora auth login` before any profile exists | `profile add <n> --host <url> --use` first (§1) |
|
||||
| Expecting `auth login --host/--name` flags | Gone — host comes from the profile; use global `--profile` |
|
||||
| Auto-adding `-y` to clear an exit-10 | Never; get user approval first (§5) |
|
||||
| `weknora chat "..."` prints "garbled" stream | NDJSON by default; use `--format text` for a transcript |
|
||||
| Need the raw `chat` event stream | pass `--format ndjson`; use `--format text` for a live projected transcript |
|
||||
| `search chunks "q"` → exit 1 `local.kb_id_required` | Pass `--kb <name-or-id>`, set `WEKNORA_KB_ID`, or `weknora link` the dir |
|
||||
|
||||
Reference in New Issue
Block a user