Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crates/rocm-dash-collectors/src/lemonade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ use rocm_dash_core::traits::{
};
use serde::Deserialize;

/// Lemonade's default OpenAI-compatible port. Mirrors `rocm_dash_tui::skills`
/// (defined locally to avoid a cross-crate dep from collectors → tui).
/// Lemonade's default OpenAI-compatible port. Mirrors the endpoint the
/// dash-tui chat probe uses (`rocm_dash_tui::llm`), defined locally to avoid a
/// cross-crate dep from collectors → tui.
pub const LEMONADE_PORT: u16 = 13305;
/// The runtime-stats path on the canonical `/api/v1` base.
pub const LEMONADE_STATS_PATH: &str = "/api/v1/stats";
Expand Down
54 changes: 29 additions & 25 deletions crates/rocm-dash-tui/src/agent/clients.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ pub fn build_messages(turns: &[ChatTurn]) -> Vec<rig::completion::Message> {
.collect()
}

/// Append a "via: tool, tool" annotation so the operator can see which Skills
/// Append a "via: tool, tool" annotation so the operator can see which tools
/// fired. Deduplicates, preserving first-seen order. Pure.
pub fn annotate_reply(reply: String, skills: &[String]) -> String {
if skills.is_empty() {
pub fn annotate_reply(reply: String, fired: &[String]) -> String {
if fired.is_empty() {
return reply;
}
let mut seen: Vec<String> = Vec::new();
for s in skills {
for s in fired {
if !seen.contains(s) {
seen.push(s.clone());
}
Expand All @@ -166,15 +166,15 @@ pub fn annotate_reply(reply: String, skills: &[String]) -> String {
}

/// Drive a built rig prompt request to completion under the shared
/// [`REQUEST_TIMEOUT`], then annotate the reply with the Skills that fired.
/// [`REQUEST_TIMEOUT`], then annotate the reply with the tools that fired.
///
/// The shared `complete()` tail, called from [`run_agent_request`] — the one
/// call site all three backends (RigAgentClient, ChatGptAgentClient,
/// AnthropicAgentClient) now go through. Their `req` types differ (rig
/// typestate), so this is generic over `IntoFuture<Output = Result<String, E>>`
/// with a `Display` error. A timeout maps to [`AgentError::Timeout`]; a backend
/// error maps to [`AgentError::Request`]; success is annotated with the fired
/// Skills. ONE definition of the tail.
/// tools. ONE definition of the tail.
///
/// `backend` tags the lifecycle trace events (request-start / completion /
/// error / timeout) so a hung or failing chat is traceable to a specific
Expand Down Expand Up @@ -214,20 +214,20 @@ where
}
Ok(Ok(reply)) => reply,
};
let skills = fired.lock().map(|g| g.clone()).unwrap_or_default();
let fired_tools = fired.lock().map(|g| g.clone()).unwrap_or_default();
info!(
backend,
elapsed_ms = started.elapsed().as_millis() as u64,
reply_len = reply.len(),
skills_fired = skills.len(),
skills_fired = fired_tools.len(),
"chat request complete"
);
Ok(annotate_reply(reply, &skills))
Ok(annotate_reply(reply, &fired_tools))
}

/// Drive one `complete()` call from a preamble'd `AgentBuilder` through to a
/// reply string: apply the sampling knobs, register the SAME three tool sets
/// (telemetry/skill, ROCm read, ROCm mutating) in the SAME order, build the
/// (telemetry, ROCm read, ROCm mutating) in the SAME order, build the
/// prompt request with the shared history/turn-limit, and hand off to
/// [`finish_agent_request`].
///
Expand Down Expand Up @@ -715,7 +715,7 @@ where

// Tool registration is delegated to run_agent_request, the single
// shared site all three backends (RigAgentClient, ChatGptAgentClient,
// AnthropicAgentClient) now call: the SAME telemetry/skill tools +
// AnthropicAgentClient) now call: the SAME telemetry tools +
// every ROCm read + mutating tool, so capability and approval
// behavior are uniform across backends.
let agent = self.client.agent(&self.model).preamble(&self.preamble);
Expand Down Expand Up @@ -745,7 +745,7 @@ struct MockApprovalTrigger {
}

/// Deterministic in-memory client for tests and the offline demo. Never touches
/// the network. Can emit a canned tool-calling-style answer (cites a Skill).
/// the network. Can emit a canned tool-calling-style answer (cites a tool).
pub struct MockAgentClient {
reply: String,
fail: bool,
Expand Down Expand Up @@ -849,7 +849,7 @@ mod tests {
use serde_json::{Value, json};

use crate::agent::{
ROCM_MUTATING_TOOL_NAMES, ROCM_READ_TOOL_NAMES, SKILL_NAMES, fixture_snapshot,
ROCM_MUTATING_TOOL_NAMES, ROCM_READ_TOOL_NAMES, TELEMETRY_TOOL_NAMES, fixture_snapshot,
};

/// A throwaway, never-pre-existing directory for
Expand Down Expand Up @@ -956,16 +956,16 @@ mod tests {
}

#[test]
fn annotate_reply_appends_deduped_skills() {
fn annotate_reply_appends_deduped_tools() {
let r = annotate_reply("hi".into(), &["gpu_status".into(), "gpu_status".into()]);
assert!(r.contains("hi"));
assert!(r.contains("via: gpu_status"));
// No skills → unchanged.
// No fired tools → unchanged.
assert_eq!(annotate_reply("hi".into(), &[]), "hi");
}

#[tokio::test]
async fn mock_tool_calling_answer_cites_skill() {
async fn mock_tool_calling_answer_cites_tool() {
// The offline "what's GPU-2 doing?" demo path — no live LLM.
let agent =
MockAgentClient::with_tool_call("GPU-2 is at 87% util, 71°C, 250 W.", "gpu_status");
Expand All @@ -977,7 +977,7 @@ mod tests {
assert!(reply.contains("87% util"));
assert!(
reply.contains("gpu_status"),
"reply cites the Skill that fired"
"reply cites the tool that fired"
);
}

Expand Down Expand Up @@ -1693,7 +1693,7 @@ mod tests {
#[test]
fn all_backends_register_same_rocm_tools() {
// Contract: every backend's complete() registers the SAME three tool
// sets — telemetry/skill (register_telemetry_tools), read ROCm
// sets — telemetry (register_telemetry_tools), read ROCm
// (register_rocm_read_tools), and mutating ROCm
// (register_rocm_mutating_tools) — so capability + approval parity holds
// across local/openai/anthropic. This enumerates the canonical sets that
Expand All @@ -1704,12 +1704,16 @@ mod tests {
// asserts those tools are actually sent on the wire from that one site.
//
// Telemetry set: register_telemetry_tools registers exactly the
// SKILL_NAMES tools (GpuStatus, ListInstances, BenchSummary,
// tools in TELEMETRY_TOOL_NAMES (GpuStatus, ListInstances, BenchSummary,
// TokensPerWatt). Pinning the size here means the telemetry
// registration can't silently diverge from the canonical set.
assert_eq!(SKILL_NAMES.len(), 4, "canonical telemetry set size");
for n in SKILL_NAMES {
assert!(!n.is_empty(), "empty telemetry/skill tool name");
assert_eq!(
TELEMETRY_TOOL_NAMES.len(),
4,
"canonical telemetry set size"
);
for n in TELEMETRY_TOOL_NAMES {
assert!(!n.is_empty(), "empty telemetry tool name");
// Telemetry tools are disjoint from both ROCm sets.
assert!(
!ROCM_READ_TOOL_NAMES.contains(&n),
Expand Down Expand Up @@ -1807,7 +1811,7 @@ mod tests {
// outside the three name tables (the retired `list_skills` and
// `skill_plan` included), and nothing in them left unregistered. A new
// tool is added to its table in the same change, which keeps this true.
let expected_tool_names: std::collections::BTreeSet<&str> = SKILL_NAMES
let expected_tool_names: std::collections::BTreeSet<&str> = TELEMETRY_TOOL_NAMES
.iter()
.chain(ROCM_READ_TOOL_NAMES.iter())
.chain(ROCM_MUTATING_TOOL_NAMES.iter())
Expand Down Expand Up @@ -1884,7 +1888,7 @@ mod tests {

assert!(
reply.contains("⚙ via: gpu_status"),
"reply should carry the fired-skill annotation: {reply}"
"reply should carry the fired-tool annotation: {reply}"
);

let requests = recorded.requests();
Expand Down Expand Up @@ -1921,7 +1925,7 @@ mod tests {
));

// The snapshot `run_agent_request` hands to `register_telemetry_tools`
// reaches `gpu_status`'s own output, not just the fired-skill log: the
// reaches `gpu_status`'s own output, not just the fired-tool log: the
// second request (after the tool call) must carry the tool result
// derived from `fixture_snapshot()`'s GPUs, not an empty/default one.
let second = requests
Expand Down
4 changes: 2 additions & 2 deletions crates/rocm-dash-tui/src/agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ pub use tools::{
ExamineRocmTool, GpuSnapshotRocmTool, GpuStatusArgs, GpuStatusTool, InstallEngineRocmTool,
InstallSdkDryRunRocmTool, InstallSdkRocmTool, LaunchServerRocmTool, ListInstancesTool,
NaturalLanguagePlanRocmTool, NoArgs, PathExistsRocmTool, PortStatusRocmTool,
ROCM_MUTATING_TOOL_NAMES, ROCM_READ_TOOL_NAMES, RocmCommandRocmTool, SKILL_NAMES,
ServiceLogsRocmTool, ServicesRocmTool, StopServerRocmTool, TokensPerWattTool, ToolError,
ROCM_MUTATING_TOOL_NAMES, ROCM_READ_TOOL_NAMES, RocmCommandRocmTool, ServiceLogsRocmTool,
ServicesRocmTool, StopServerRocmTool, TELEMETRY_TOOL_NAMES, TokensPerWattTool, ToolError,
UpdateCheckRocmTool, WatcherDisableRocmTool, WatcherEnableRocmTool,
};

Expand Down
45 changes: 24 additions & 21 deletions crates/rocm-dash-tui/src/agent/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: MIT

//! Rig `Tool` ("Skill") wrappers over the cached telemetry snapshot, plus the
//! Rig `Tool` wrappers over the cached telemetry snapshot, plus the
//! read-only and mutating ROCm machine-inspection tools and their registration
//! onto a Rig `AgentBuilder`.
//!
Expand Down Expand Up @@ -30,12 +30,12 @@ use super::snapshot::{
};

// ---------------------------------------------------------------------------
// Rig Tool ("Skill") wrappers. Each holds an `Arc<StateSnapshot>` (read-only)
// and a shared `fired` log so the reply can cite which Skills ran. `call` only
// reads the snapshot — no mutation, no network, no file I/O.
// Rig Tool wrappers for the telemetry tools. Each holds an `Arc<StateSnapshot>`
// (read-only) and a shared `fired` log so the reply can cite which tools ran.
// `call` only reads the snapshot — no mutation, no network, no file I/O.
// ---------------------------------------------------------------------------

/// Shared "which Skills fired" log, threaded into every tool struct below and
/// Shared "which tools fired" log, threaded into every tool struct below and
/// into the three real `AgentClient` backends via `agent::clients`.
pub(super) type FiredLog = Arc<Mutex<Vec<String>>>;

Expand Down Expand Up @@ -178,8 +178,8 @@ impl Tool for TokensPerWattTool {
}
}

/// All Skill names, for definition/uniqueness checks and docs.
pub const SKILL_NAMES: [&str; 4] = [
/// All telemetry tool names, for definition/uniqueness checks and docs.
pub const TELEMETRY_TOOL_NAMES: [&str; 4] = [
GpuStatusTool::NAME,
ListInstancesTool::NAME,
BenchSummaryTool::NAME,
Expand Down Expand Up @@ -427,7 +427,7 @@ rocm_read_tool!(
}
);

/// All read-only ROCm tool names (mirrors [`SKILL_NAMES`]).
/// All read-only ROCm tool names (mirrors [`TELEMETRY_TOOL_NAMES`]).
///
/// Used for uniqueness/registration checks and the parity map. Mutating tools
/// are intentionally absent. `natural_language_plan` is read-only: it plans but
Expand Down Expand Up @@ -786,17 +786,17 @@ mod tests {
use crate::agent::fixture_snapshot;

#[test]
fn skill_names_are_unique_and_non_empty() {
for n in SKILL_NAMES {
assert!(!n.is_empty(), "skill name must be non-empty");
fn telemetry_tool_names_are_unique_and_non_empty() {
for n in TELEMETRY_TOOL_NAMES {
assert!(!n.is_empty(), "telemetry tool name must be non-empty");
}
let mut sorted = SKILL_NAMES.to_vec();
let mut sorted = TELEMETRY_TOOL_NAMES.to_vec();
sorted.sort_unstable();
sorted.dedup();
assert_eq!(
sorted.len(),
SKILL_NAMES.len(),
"skill names must be unique"
TELEMETRY_TOOL_NAMES.len(),
"telemetry tool names must be unique"
);
}

Expand Down Expand Up @@ -860,7 +860,7 @@ mod tests {
// installs an engine, and no executor ever applied their plans. They
// must not come back in any tool set the model is offered.
for gone in ["list_skills", "skill_plan"] {
assert!(!SKILL_NAMES.contains(&gone), "{gone} is retired");
assert!(!TELEMETRY_TOOL_NAMES.contains(&gone), "{gone} is retired");
assert!(!ROCM_READ_TOOL_NAMES.contains(&gone), "{gone} is retired");
assert!(
!ROCM_MUTATING_TOOL_NAMES.contains(&gone),
Expand Down Expand Up @@ -1013,9 +1013,12 @@ mod tests {
"missing mutating tool: {expected}"
);
}
// Disjoint from read-only + skill names (iterates the registry itself).
// Disjoint from read-only + telemetry tool names (iterates the registry itself).
for n in ROCM_MUTATING_TOOL_NAMES {
assert!(!SKILL_NAMES.contains(&n), "collision with skill: {n}");
assert!(
!TELEMETRY_TOOL_NAMES.contains(&n),
"collision with telemetry tool: {n}"
);
// install_sdk_dry_run (read-only) must not clash with install_sdk.
assert!(
!ROCM_READ_TOOL_NAMES.contains(&n),
Expand Down Expand Up @@ -1204,7 +1207,7 @@ mod tests {
}

#[test]
fn rocm_read_tool_names_are_complete_and_disjoint_from_skills() {
fn rocm_read_tool_names_are_complete_and_disjoint_from_telemetry_tools() {
// Every expected read-only tool is registered…
for expected in [
"doctor",
Expand All @@ -1231,10 +1234,10 @@ mod tests {
}
// natural_language_plan is read-only (plans, never executes) — Phase 7.
assert!(ROCM_READ_TOOL_NAMES.contains(&"natural_language_plan"));
// The telemetry/skill tools are still present and disjoint from the new set.
assert!(SKILL_NAMES.contains(&"gpu_status"));
// The telemetry tools are still present and disjoint from the new set.
assert!(TELEMETRY_TOOL_NAMES.contains(&"gpu_status"));
for n in ROCM_READ_TOOL_NAMES {
assert!(!SKILL_NAMES.contains(&n), "name collision: {n}");
assert!(!TELEMETRY_TOOL_NAMES.contains(&n), "name collision: {n}");
}
}
}
6 changes: 3 additions & 3 deletions crates/rocm-dash-tui/src/ui/tabs/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ fn transcript_lines_from_turns<'a>(turns: &'a [ChatTurn], theme: &Theme) -> Vec<
ChatRole::Error => ("err ", theme.err),
ChatRole::System => ("·· ", theme.muted),
};
// Multi-line content (e.g. an answer plus a "⚙ via: …" Skill annotation)
// Multi-line content (e.g. an answer plus a "⚙ via: …" fired-tools annotation)
// renders one terminal line per segment; continuation lines are indented
// to align under the first line's content.
for (i, seg) in turn.content.split('\n').enumerate() {
Expand Down Expand Up @@ -445,7 +445,7 @@ mod tests {
}

#[test]
fn transcript_renders_skill_annotation_on_its_own_line() {
fn transcript_renders_tool_annotation_on_its_own_line() {
let mut s = AppState::new("t".into(), "default-dark".into());
// An agent reply carrying a tool-call surfacing annotation.
s.chat.push(ChatTurn::agent(
Expand All @@ -457,7 +457,7 @@ mod tests {
assert_eq!(lines.len(), 2, "answer + annotation render as two lines");
assert!(
format!("{lines:?}").contains("gpu_status"),
"the fired Skill is surfaced in the transcript"
"the fired tool is surfaced in the transcript"
);
}

Expand Down
2 changes: 1 addition & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ The old agent.rs was split (mechanical relocation — the shared seam types stay

- [`agent/mod.rs`](../crates/rocm-dash-tui/src/agent/mod.rs) — the `AgentClient` seam, `AgentError`, `StateSnapshot`, `InferenceParams`, `REQUEST_TIMEOUT`.
- [`agent/snapshot.rs`](../crates/rocm-dash-tui/src/agent/snapshot.rs) — pure JSON telemetry helpers with no `rig` dependency.
- [`agent/tools.rs`](../crates/rocm-dash-tui/src/agent/tools.rs) — the `rig::tool::Tool` "Skill" wrappers and ROCm read/mutating tool dispatch.
- [`agent/tools.rs`](../crates/rocm-dash-tui/src/agent/tools.rs) — the `rig::tool::Tool` wrappers for the four telemetry tools (`gpu_status`, `list_instances`, `bench_summary`, `tokens_per_watt`), their name table `TELEMETRY_TOOL_NAMES`, and the ROCm read/mutating tool dispatch.
- [`agent/clients.rs`](../crates/rocm-dash-tui/src/agent/clients.rs) — the `RigAgentClient`/`ChatGptAgentClient`/`AnthropicAgentClient`/`MockAgentClient` backends.

[`app/mod.rs`](../crates/rocm-dash-tui/src/app/mod.rs) is modularized (ROCMAI-84, Phase 4 of ROCMAI-27's sequencing) into an `app/` directory. [`app/types.rs`](../crates/rocm-dash-tui/src/app/types.rs), [`app/event_loop.rs`](../crates/rocm-dash-tui/src/app/event_loop.rs), [`app/scrollbar.rs`](../crates/rocm-dash-tui/src/app/scrollbar.rs), and [`app/actions.rs`](../crates/rocm-dash-tui/src/app/actions.rs) follow full domain extraction. [`app/chat.rs`](../crates/rocm-dash-tui/src/app/chat.rs), [`app/slash.rs`](../crates/rocm-dash-tui/src/app/slash.rs), and [`app/summary.rs`](../crates/rocm-dash-tui/src/app/summary.rs) were extracted earlier via mechanical relocation, the same convention the `agent/` split above follows. `quit_confirm`, `tool_approval`, `overlays`, `scroll` and `chat_state` each hold a further `impl AppState` block for one cohesive group of reducer methods:
Expand Down
Loading