Skip to content

Commit 7e21fa0

Browse files
committed
More WIP cleanup
1 parent 95fdf74 commit 7e21fa0

File tree

16 files changed

+548
-354
lines changed

16 files changed

+548
-354
lines changed

crates/agent/src/agent/agent_config/definitions.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ impl Config {
8888
}
8989
}
9090

91-
// TODO: use default implementation as an orchestrator agent
9291
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
9392
#[serde(rename_all = "camelCase")]
9493
#[schemars(description = "An Agent is a declarative way of configuring a given instance of q chat.")]
@@ -176,7 +175,7 @@ impl Default for AgentConfigV2025_08_22 {
176175
use_legacy_mcp_json: false,
177176

178177
resources: Default::default(),
179-
allowed_tools: Default::default(),
178+
allowed_tools: HashSet::from([BuiltInToolName::FileRead.to_string()]),
180179
}
181180
}
182181
}
@@ -382,6 +381,6 @@ mod tests {
382381
"description": "The orchestrator agent",
383382
});
384383

385-
let agent: Config = serde_json::from_value(agent).unwrap();
384+
let _: Config = serde_json::from_value(agent).unwrap();
386385
}
387386
}

crates/agent/src/agent/agent_config/mod.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ use crate::agent::util::error::{
4949
#[derive(Debug, Clone)]
5050
pub struct AgentConfig {
5151
/// Where the config was sourced from
52+
#[allow(dead_code)]
5253
source: ConfigSource,
5354
/// The actual config content
5455
config: Config,
@@ -260,16 +261,20 @@ async fn load_agents_from_dir(
260261
#[derive(Debug, Clone)]
261262
pub struct LoadedMcpServerConfig {
262263
/// The name (aka id) to associate with the config
263-
pub name: String,
264+
pub server_name: String,
264265
/// The mcp server config
265266
pub config: McpServerConfig,
266267
/// Where the config originated from
267268
pub source: McpServerConfigSource,
268269
}
269270

270271
impl LoadedMcpServerConfig {
271-
fn new(name: String, config: McpServerConfig, source: McpServerConfigSource) -> Self {
272-
Self { name, config, source }
272+
fn new(server_name: String, config: McpServerConfig, source: McpServerConfigSource) -> Self {
273+
Self {
274+
server_name,
275+
config,
276+
source,
277+
}
273278
}
274279
}
275280

@@ -303,8 +308,12 @@ impl LoadedMcpServerConfigs {
303308
if config.use_legacy_mcp_json() {
304309
let mut push_configs = |mcp_servers: McpServers, source: McpServerConfigSource| {
305310
for (name, config) in mcp_servers.mcp_servers {
306-
let config = LoadedMcpServerConfig { name, config, source };
307-
if configs.iter().any(|c| c.name == config.name) {
311+
let config = LoadedMcpServerConfig {
312+
server_name: name,
313+
config,
314+
source,
315+
};
316+
if configs.iter().any(|c| c.server_name == config.server_name) {
308317
overwritten_configs.push(config);
309318
} else {
310319
configs.push(config);
@@ -336,6 +345,10 @@ impl LoadedMcpServerConfigs {
336345
overridden_configs: overwritten_configs,
337346
}
338347
}
348+
349+
pub fn server_names(&self) -> Vec<String> {
350+
self.configs.iter().map(|c| c.server_name.clone()).collect()
351+
}
339352
}
340353

341354
/// Where an [McpServerConfig] originated from

crates/agent/src/agent/agent_config/parse.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Utilities for semantic parsing of agent config values
2+
13
use std::borrow::Cow;
24
use std::str::FromStr;
35

@@ -6,14 +8,7 @@ use crate::agent::protocol::AgentError;
68
use crate::agent::tools::BuiltInToolName;
79
use crate::agent::util::path::canonicalize_path;
810

9-
#[derive(Debug, Clone)]
10-
pub struct Resource {
11-
/// Exact value from the config this resource was taken from
12-
pub config_value: String,
13-
/// Resource content
14-
pub content: String,
15-
}
16-
11+
/// Represents a value from the `resources` array in the agent config.
1712
pub enum ResourceKind<'a> {
1813
File { original: &'a str, file_path: &'a str },
1914
FileGlob { original: &'a str, pattern: glob::Pattern },
@@ -22,7 +17,7 @@ pub enum ResourceKind<'a> {
2217
impl<'a> ResourceKind<'a> {
2318
pub fn parse(value: &'a str) -> Result<Self, String> {
2419
if !value.starts_with("file://") {
25-
return Err("Only file schemes are supported now".to_string());
20+
return Err("Only file schemes are currently supported".to_string());
2621
}
2722

2823
let file_path = value.trim_start_matches("file://");

crates/agent/src/agent/agent_loop/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ impl AgentLoop {
322322
self.loop_event_tx.send(ev).await.ok();
323323
}
324324

325-
Ok(AgentLoopResponse::Metadata(metadata))
325+
Ok(AgentLoopResponse::Metadata(Box::new(metadata)))
326326
},
327327
}
328328
}
@@ -679,7 +679,7 @@ impl AgentLoopHandle {
679679
.await
680680
.unwrap_or(Err(AgentLoopResponseError::AgentLoopExited))?
681681
{
682-
AgentLoopResponse::Metadata(md) => Ok(md),
682+
AgentLoopResponse::Metadata(md) => Ok(*md),
683683
other => Err(AgentLoopResponseError::Custom(format!(
684684
"unknown response getting execution state: {:?}",
685685
other,

crates/agent/src/agent/agent_loop/model.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,23 +87,23 @@ impl Model for Models {
8787
}
8888
}
8989

90-
#[derive(Debug, Clone)]
90+
#[derive(Debug, Clone, Default)]
9191
pub struct TestModel {}
9292

9393
impl TestModel {
9494
pub fn new() -> Self {
95-
Self {}
95+
Self::default()
9696
}
9797
}
9898

9999
impl Model for TestModel {
100100
fn stream(
101101
&self,
102-
messages: Vec<Message>,
103-
tool_specs: Option<Vec<ToolSpec>>,
104-
system_prompt: Option<String>,
105-
cancel_token: CancellationToken,
102+
_messages: Vec<Message>,
103+
_tool_specs: Option<Vec<ToolSpec>>,
104+
_system_prompt: Option<String>,
105+
_cancel_token: CancellationToken,
106106
) -> Pin<Box<dyn Stream<Item = Result<StreamEvent, StreamError>> + Send + 'static>> {
107-
todo!()
107+
panic!("unimplemented")
108108
}
109109
}

crates/agent/src/agent/agent_loop/protocol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub enum AgentLoopResponse {
5959
ExecutionState(LoopState),
6060
StreamMetadata(Vec<StreamMetadata>),
6161
PendingToolUses(Option<Vec<ToolUseBlock>>),
62-
Metadata(UserTurnMetadata),
62+
Metadata(Box<UserTurnMetadata>),
6363
}
6464

6565
#[derive(Debug, Clone, Serialize, Deserialize, thiserror::Error)]

crates/agent/src/agent/mcp/actor.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ use crate::agent::util::request_channel::{
4141
/// Represents a message from an MCP server to the client.
4242
#[derive(Debug)]
4343
pub enum McpMessage {
44-
ToolsResult(Result<Vec<RmcpTool>, ServiceError>),
45-
PromptsResult(Result<Vec<RmcpPrompt>, ServiceError>),
46-
ExecuteToolResult { request_id: u32, result: ExecuteToolResult },
44+
Tools(Result<Vec<RmcpTool>, ServiceError>),
45+
Prompts(Result<Vec<RmcpPrompt>, ServiceError>),
46+
ExecuteTool { request_id: u32, result: ExecuteToolResult },
4747
}
4848

4949
#[derive(Debug)]
5050
pub struct McpServerActorHandle {
51-
server_name: String,
51+
_server_name: String,
5252
sender: RequestSender<McpServerActorRequest, McpServerActorResponse, McpServerActorError>,
5353
event_rx: mpsc::Receiver<McpServerActorEvent>,
5454
}
@@ -172,8 +172,8 @@ pub enum McpServerActorEvent {
172172
pub struct McpServerActor {
173173
/// Name of the MCP server
174174
server_name: String,
175-
/// Config the server was launched with
176-
config: McpServerConfig,
175+
/// Config the server was launched with. Kept for debug purposes.
176+
_config: McpServerConfig,
177177
/// Tools
178178
tools: Vec<ToolSpec>,
179179
/// Prompts
@@ -203,7 +203,7 @@ impl McpServerActor {
203203
tokio::spawn(async move { Self::launch(server_name_clone, config, req_rx, event_tx).await });
204204

205205
McpServerActorHandle {
206-
server_name,
206+
_server_name: server_name,
207207
sender: req_tx,
208208
event_rx,
209209
}
@@ -223,7 +223,7 @@ impl McpServerActor {
223223
Ok((service_handle, launch_md)) => {
224224
let s = Self {
225225
server_name,
226-
config,
226+
_config: config,
227227
tools: launch_md.tools.unwrap_or_default(),
228228
prompts: launch_md.prompts.unwrap_or_default(),
229229
service_handle,
@@ -292,9 +292,7 @@ impl McpServerActor {
292292
})
293293
.await
294294
.map_err(McpServerActorError::from);
295-
let _ = message_tx
296-
.send(McpMessage::ExecuteToolResult { request_id, result })
297-
.await;
295+
let _ = message_tx.send(McpMessage::ExecuteTool { request_id, result }).await;
298296
});
299297
self.executing_tools.insert(self.curr_tool_execution_id, tx);
300298
Ok(McpServerActorResponse::ExecuteTool(rx))
@@ -309,19 +307,19 @@ impl McpServerActor {
309307
return;
310308
};
311309
match msg {
312-
McpMessage::ToolsResult(res) => match res {
310+
McpMessage::Tools(res) => match res {
313311
Ok(tools) => self.tools = tools.into_iter().map(Into::into).collect(),
314312
Err(err) => {
315313
error!(?err, "failed to list tools");
316314
},
317315
},
318-
McpMessage::PromptsResult(res) => match res {
316+
McpMessage::Prompts(res) => match res {
319317
Ok(prompts) => self.prompts = prompts.into_iter().map(Into::into).collect(),
320318
Err(err) => {
321319
error!(?err, "failed to list prompts");
322320
},
323321
},
324-
McpMessage::ExecuteToolResult { request_id, result } => match self.executing_tools.remove(&request_id) {
322+
McpMessage::ExecuteTool { request_id, result } => match self.executing_tools.remove(&request_id) {
325323
Some(tx) => {
326324
let _ = tx.send(result);
327325
},
@@ -337,22 +335,24 @@ impl McpServerActor {
337335
}
338336

339337
/// Asynchronously fetch all tools
338+
#[allow(dead_code)]
340339
fn refresh_tools(&self) {
341340
let service_handle = self.service_handle.clone();
342341
let tx = self.message_tx.clone();
343342
tokio::spawn(async move {
344343
let res = service_handle.list_tools().await;
345-
let _ = tx.send(McpMessage::ToolsResult(res)).await;
344+
let _ = tx.send(McpMessage::Tools(res)).await;
346345
});
347346
}
348347

349348
/// Asynchronously fetch all prompts
349+
#[allow(dead_code)]
350350
fn refresh_prompts(&self) {
351351
let service_handle = self.service_handle.clone();
352352
let tx = self.message_tx.clone();
353353
tokio::spawn(async move {
354354
let res = service_handle.list_prompts().await;
355-
let _ = tx.send(McpMessage::PromptsResult(res)).await;
355+
let _ = tx.send(McpMessage::Prompts(res)).await;
356356
});
357357
}
358358
}

0 commit comments

Comments
 (0)