assistant2: Allow creating agent profiles via settings (#27216)
This PR adds support for creating new agent profiles via the settings:
```json
{
"assistant": {
"profiles": {
"lua": {
"name": "Lua",
"tools": {
"lua-interpreter": true
}
},
"lua-thinking": {
"name": "Lua + Thinking",
"tools": {
"lua-interpreter": true,
"thinking": true
}
}
}
}
}
```
Release Notes:
- N/A
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use collections::HashMap;
|
||||
use gpui::SharedString;
|
||||
|
||||
/// A profile for the Zed Agent that controls its behavior.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AgentProfile {
|
||||
/// The name of the profile.
|
||||
pub name: SharedString,
|
||||
pub tools: HashMap<Arc<str>, bool>,
|
||||
#[allow(dead_code)]
|
||||
pub context_servers: HashMap<Arc<str>, ContextServerPreset>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct ContextServerPreset {
|
||||
#[allow(dead_code)]
|
||||
pub tools: HashMap<Arc<str>, bool>,
|
||||
}
|
||||
|
||||
impl AgentProfile {
|
||||
pub fn read_only() -> Self {
|
||||
Self {
|
||||
name: "Read-only".into(),
|
||||
tools: HashMap::from_iter([
|
||||
("diagnostics".into(), true),
|
||||
("fetch".into(), true),
|
||||
("list-directory".into(), true),
|
||||
("now".into(), true),
|
||||
("path-search".into(), true),
|
||||
("read-file".into(), true),
|
||||
("regex-search".into(), true),
|
||||
("thinking".into(), true),
|
||||
]),
|
||||
context_servers: HashMap::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn code_writer() -> Self {
|
||||
Self {
|
||||
name: "Code Writer".into(),
|
||||
tools: HashMap::from_iter([
|
||||
("bash".into(), true),
|
||||
("delete-path".into(), true),
|
||||
("diagnostics".into(), true),
|
||||
("edit-files".into(), true),
|
||||
("fetch".into(), true),
|
||||
("list-directory".into(), true),
|
||||
("now".into(), true),
|
||||
("path-search".into(), true),
|
||||
("read-file".into(), true),
|
||||
("regex-search".into(), true),
|
||||
("thinking".into(), true),
|
||||
]),
|
||||
context_servers: HashMap::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
mod active_thread;
|
||||
mod agent_profile;
|
||||
mod assistant_configuration;
|
||||
mod assistant_model_selector;
|
||||
mod assistant_panel;
|
||||
|
||||
@@ -1,23 +1,34 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use assistant_settings::{AgentProfile, AssistantSettings};
|
||||
use assistant_tool::{ToolSource, ToolWorkingSet};
|
||||
use collections::HashMap;
|
||||
use gpui::Entity;
|
||||
use scripting_tool::ScriptingTool;
|
||||
use settings::Settings as _;
|
||||
use ui::{prelude::*, ContextMenu, PopoverMenu, Tooltip};
|
||||
|
||||
use crate::agent_profile::AgentProfile;
|
||||
|
||||
pub struct ToolSelector {
|
||||
profiles: Vec<AgentProfile>,
|
||||
profiles: HashMap<Arc<str>, AgentProfile>,
|
||||
tools: Arc<ToolWorkingSet>,
|
||||
}
|
||||
|
||||
impl ToolSelector {
|
||||
pub fn new(tools: Arc<ToolWorkingSet>, _cx: &mut Context<Self>) -> Self {
|
||||
Self {
|
||||
profiles: vec![AgentProfile::read_only(), AgentProfile::code_writer()],
|
||||
tools,
|
||||
pub fn new(tools: Arc<ToolWorkingSet>, cx: &mut Context<Self>) -> Self {
|
||||
let settings = AssistantSettings::get_global(cx);
|
||||
let mut profiles = settings.profiles.clone();
|
||||
|
||||
let read_only = AgentProfile::read_only();
|
||||
if !profiles.contains_key(read_only.name.as_ref()) {
|
||||
profiles.insert(read_only.name.clone().into(), read_only);
|
||||
}
|
||||
|
||||
let code_writer = AgentProfile::code_writer();
|
||||
if !profiles.contains_key(code_writer.name.as_ref()) {
|
||||
profiles.insert(code_writer.name.clone().into(), code_writer);
|
||||
}
|
||||
|
||||
Self { profiles, tools }
|
||||
}
|
||||
|
||||
fn build_context_menu(
|
||||
@@ -31,7 +42,7 @@ impl ToolSelector {
|
||||
let icon_position = IconPosition::End;
|
||||
|
||||
menu = menu.header("Profiles");
|
||||
for profile in profiles.clone() {
|
||||
for (_id, profile) in profiles.clone() {
|
||||
menu = menu.toggleable_entry(profile.name.clone(), false, icon_position, None, {
|
||||
let tools = tool_set.clone();
|
||||
move |_window, cx| {
|
||||
@@ -44,6 +55,10 @@ impl ToolSelector {
|
||||
.filter_map(|(tool, enabled)| enabled.then(|| tool.clone()))
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
|
||||
if profile.tools.contains_key(ScriptingTool::NAME) {
|
||||
tools.enable_scripting_tool();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user