Skip to content

Commit f0ddd52

Browse files
committed
Add resource tool for LLM to provide unified view
- Create new resource tool that handles both pinned and indexed resources - Add resource tool to Tool enum and all match statements - Register resource tool in tool_manager.rs - LLM can now use 'resource' tool instead of just 'context' - Provides unified interface for both storage types
1 parent 183b686 commit f0ddd52

File tree

3 files changed

+382
-0
lines changed

3 files changed

+382
-0
lines changed

crates/chat-cli/src/cli/chat/tool_manager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ use crate::cli::chat::tools::fs_read::FsRead;
7878
use crate::cli::chat::tools::fs_write::FsWrite;
7979
use crate::cli::chat::tools::gh_issue::GhIssue;
8080
use crate::cli::chat::tools::context::Context;
81+
use crate::cli::chat::tools::resource::Resource;
8182
use crate::cli::chat::tools::thinking::Thinking;
8283
use crate::cli::chat::tools::use_aws::UseAws;
8384
use crate::cli::chat::tools::{
@@ -1066,6 +1067,7 @@ impl ToolManager {
10661067
"report_issue" => Tool::GhIssue(serde_json::from_value::<GhIssue>(value.args).map_err(map_err)?),
10671068
"thinking" => Tool::Thinking(serde_json::from_value::<Thinking>(value.args).map_err(map_err)?),
10681069
"context" => Tool::Context(serde_json::from_value::<Context>(value.args).map_err(map_err)?),
1070+
"resource" => Tool::Resource(serde_json::from_value::<Resource>(value.args).map_err(map_err)?),
10691071
// Note that this name is namespaced with server_name{DELIMITER}tool_name
10701072
name => {
10711073
// Note: tn_map also has tools that underwent no transformation. In otherwords, if

crates/chat-cli/src/cli/chat/tools/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pub mod fs_read;
44
pub mod fs_write;
55
pub mod gh_issue;
66
pub mod context;
7+
pub mod resource;
78
pub mod thinking;
89
pub mod use_aws;
910

@@ -30,6 +31,7 @@ use fs_read::FsRead;
3031
use fs_write::FsWrite;
3132
use gh_issue::GhIssue;
3233
use context::Context;
34+
use resource::Resource;
3335
use serde::{
3436
Deserialize,
3537
Serialize,
@@ -78,6 +80,7 @@ pub enum Tool {
7880
Custom(CustomTool),
7981
GhIssue(GhIssue),
8082
Context(Context),
83+
Resource(Resource),
8184
Thinking(Thinking),
8285
}
8386

@@ -95,6 +98,7 @@ impl Tool {
9598
Tool::Custom(custom_tool) => &custom_tool.name,
9699
Tool::GhIssue(_) => "gh_issue",
97100
Tool::Context(_) => "context",
101+
Tool::Resource(_) => "resource",
98102
Tool::Thinking(_) => "thinking (prerelease)",
99103
}
100104
.to_owned()
@@ -111,6 +115,7 @@ impl Tool {
111115
Tool::GhIssue(_) => PermissionEvalResult::Allow,
112116
Tool::Thinking(_) => PermissionEvalResult::Allow,
113117
Tool::Context(context) => context.eval_perm(agent),
118+
Tool::Resource(resource) => resource.eval_perm(agent),
114119
}
115120
}
116121

@@ -130,6 +135,7 @@ impl Tool {
130135
Tool::Custom(custom_tool) => custom_tool.invoke(os, stdout).await,
131136
Tool::GhIssue(gh_issue) => gh_issue.invoke(os, stdout).await,
132137
Tool::Context(context) => context.invoke(os, stdout, agent).await,
138+
Tool::Resource(resource) => resource.invoke(os, stdout, agent).await,
133139
Tool::Thinking(think) => think.invoke(stdout).await,
134140
}
135141
}
@@ -144,6 +150,7 @@ impl Tool {
144150
Tool::Custom(custom_tool) => custom_tool.queue_description(output),
145151
Tool::GhIssue(gh_issue) => gh_issue.queue_description(output),
146152
Tool::Context(context) => context.queue_description(os, output).await,
153+
Tool::Resource(resource) => resource.queue_description(os, output).await,
147154
Tool::Thinking(thinking) => thinking.queue_description(output),
148155
}
149156
}
@@ -158,6 +165,7 @@ impl Tool {
158165
Tool::Custom(custom_tool) => custom_tool.validate(os).await,
159166
Tool::GhIssue(gh_issue) => gh_issue.validate(os).await,
160167
Tool::Context(context) => context.validate(os).await,
168+
Tool::Resource(resource) => resource.validate(os).await,
161169
Tool::Thinking(think) => think.validate(os).await,
162170
}
163171
}

0 commit comments

Comments
 (0)