Skip to content
Draft
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
3 changes: 2 additions & 1 deletion rust/contracts/rust-core-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,8 @@ or removing a command fails until the table changes in the same commit.
| `ai.inlineEdit.plan` | Plan a credential-free inline edit request |
| `ai.inlineEdit.decode` | Decode the replacement text of an inline edit response |
| `agents.configure` | Load the agents enabled plugins declare, with the permissions the user granted |
| `agents.catalog` | List the configured agents |
| `agents.catalog` | List the configured agents, with whether each checks for a newer CLI and its `install` (`{installers, url?}`: the IDs of the command installers that provide its tool and the install page it declares) |
| `agents.cliVersions` | Compare each named agent's installed CLI version with the newest one its plugin's `latestVersion` function reported, kept in memory per installation; `check` is `cached` (ask no plugin), `ifStale` (ask once an answer is six hours old, 15 minutes after a failure) or `now` (user requests only); answers each agent's `latest`, `comparison`, `updateAvailable` and `checkFailed`, and `updates`, the update commands of the agents behind, which the host runs in its terminal |
| `agents.sessions` | List the live agent sessions |
| `agents.start` | Start a native agent session the user asked for |
| `agents.prompt` | Send, queue or steer the user's prompt and attachments, retaining queued or unconfirmed input until its outcome |
Expand Down
23 changes: 22 additions & 1 deletion rust/crates/agent-runtime/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ const MAX_PLUGINS: usize = 1024;
/// One plugin's agents and grants.
#[derive(Debug, Clone)]
pub(crate) struct PluginAgents {
/// The plugin's own version, which tells a cached answer of an older
/// build of the plugin from one of this build.
pub version: String,
pub agents: Vec<AgentDeclaration>,
pub granted: BTreeSet<String>,
/// The command installers that provide each agent's tool, by agent ID.
pub installers: BTreeMap<String, Vec<String>>,
}

impl PluginAgents {
Expand All @@ -43,6 +48,8 @@ impl PluginAgents {
#[derive(Debug, Clone)]
pub(crate) struct CatalogAgent {
pub plugin_id: String,
/// The version of the plugin that declares the agent.
pub plugin_version: String,
pub agent: AgentDeclaration,
pub may_run: bool,
pub may_read_sessions: bool,
Expand Down Expand Up @@ -127,11 +134,18 @@ impl Catalog {
.into_iter()
.filter(|permission| declared.contains(permission.as_str()))
.collect();
let installers = manifest
.agents()
.iter()
.map(|agent| (agent.id.clone(), manifest.agent_installers(&agent.id)))
.collect();
plugins.insert(
manifest.id().to_string(),
PluginAgents {
version: manifest.version().to_string(),
agents: manifest.agents().to_vec(),
granted,
installers,
},
);
}
Expand All @@ -150,7 +164,11 @@ impl Catalog {
.iter()
.flat_map(|(plugin_id, plugin)| {
plugin.agents.iter().map(move |agent| {
let mut entry = catalog_entry(plugin_id, agent);
let installers = plugin
.installers
.get(&agent.id)
.map_or(&[][..], Vec::as_slice);
let mut entry = catalog_entry(plugin_id, agent, installers);
entry["mayRun"] = json!(plugin.may_run());
entry["mayReadSessions"] = json!(plugin.may_read_sessions());
if agent.configuration.is_some() {
Expand All @@ -169,6 +187,7 @@ impl Catalog {
let agent = plugin.agents.iter().find(|agent| agent.id == agent_id)?;
Some(CatalogAgent {
plugin_id: plugin_id.to_string(),
plugin_version: plugin.version.clone(),
agent: agent.clone(),
may_run: plugin.may_run(),
may_read_sessions: plugin.may_read_sessions(),
Expand All @@ -191,6 +210,7 @@ impl Catalog {
.flat_map(|(plugin_id, plugin)| {
plugin.agents.iter().map(move |agent| CatalogAgent {
plugin_id: plugin_id.clone(),
plugin_version: plugin.version.clone(),
agent: agent.clone(),
may_run: plugin.may_run(),
may_read_sessions: true,
Expand All @@ -214,6 +234,7 @@ impl Catalog {
.filter(|agent| agent.configuration.is_some())
.map(move |agent| CatalogAgent {
plugin_id: plugin_id.clone(),
plugin_version: plugin.version.clone(),
agent: agent.clone(),
may_run: plugin.may_run(),
may_read_sessions: plugin.may_read_sessions(),
Expand Down
14 changes: 11 additions & 3 deletions rust/crates/agent-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
//! covers Lithe's library of MCP servers, hooks, skills and instructions and
//! applies them to the agents' own configuration (the `library` module);
//! `agentProviders.*` reads and changes an agent's model, model providers
//! and profiles through the same staged copy. Backends reach it with
//! and profiles through the same staged copy. `agents.cliVersions` compares
//! each CLI the host found installed with the newest version its plugin
//! reports (the `versions` module). Backends reach it with
//! `lithe/host/agents/*` requests, which the engine hands to the installed
//! [`AgentHost`] and which never reach the host application.
//!
Expand Down Expand Up @@ -45,6 +47,7 @@ mod library;
mod live;
mod projection;
mod records;
mod versions;

#[cfg(test)]
mod tests;
Expand All @@ -62,15 +65,17 @@ use serde_json::Value;
use std::collections::BTreeMap;
use std::sync::{Arc, OnceLock};
use std::time::{SystemTime, UNIX_EPOCH};
use versions::Versions;

/// The agent catalog, the live sessions, the session records and the
/// agent library.
/// The agent catalog, the live sessions, the session records, the agent
/// library and the CLI versions.
pub(crate) struct Runtime {
pub link: Arc<dyn BackendLink>,
pub catalog: Catalog,
pub live: Live,
pub records: Records,
pub library: Library,
pub versions: Versions,
}

impl Runtime {
Expand All @@ -81,6 +86,7 @@ impl Runtime {
live: Live::default(),
records: Records::default(),
library: Library::default(),
versions: Versions::default(),
})
}

Expand All @@ -93,6 +99,7 @@ impl Runtime {
"agents.configure" => {
let answer = self.catalog.configure(payload)?;
self.live.queue.views.purge_unreadable(&self.catalog);
self.versions.retain(self);
// A session whose agent is gone or no longer granted ends.
self.live.end_where(|plugin_id, agent_id| {
self.catalog
Expand All @@ -102,6 +109,7 @@ impl Runtime {
Ok(answer)
}
"agents.catalog" => Ok(self.catalog.list()),
"agents.cliVersions" => self.versions.read(self, payload),
"agents.sessions" => Ok(self.live.list()),
"agents.start" => live::start(self, payload),
"agents.prompt" => live::prompt(self, payload),
Expand Down
1 change: 1 addition & 0 deletions rust/crates/agent-runtime/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2508,6 +2508,7 @@ fn chunk_lines_keep_byte_offsets_and_text_lines_drop_line_breaks() {
mod library;
mod providers;
mod sessions;
mod versions;

#[test]
fn turn_interaction_follows_the_shared_application_fixture() {
Expand Down
Loading