tools: each module exports only tool() or tools(), nothing else
Every tool module now has a clean interface: - read, write, edit, grep, glob, bash, vision: pub fn tool() -> Tool - web: pub fn tools() -> [Tool; 2] - memory: pub fn memory_tools() -> Vec<Tool> - channels: pub fn tools() -> Vec<Tool> - control: pub fn tools() -> Vec<Tool> Definition and handler functions are private to each module. mod.rs::tools() just chains the module exports. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
fdb8c989f5
commit
ed150df628
10 changed files with 65 additions and 36 deletions
|
|
@ -6,6 +6,13 @@ use serde_json::json;
|
|||
|
||||
use super::ToolDef;
|
||||
|
||||
pub fn tools() -> [super::Tool; 2] {
|
||||
[
|
||||
super::Tool { def: fetch_definition(), handler: |_a, v| Box::pin(async move { web_fetch(&v).await }) },
|
||||
super::Tool { def: search_definition(), handler: |_a, v| Box::pin(async move { web_search(&v).await }) },
|
||||
]
|
||||
}
|
||||
|
||||
// ── Fetch ───────────────────────────────────────────────────────
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
@ -13,7 +20,7 @@ struct FetchArgs {
|
|||
url: String,
|
||||
}
|
||||
|
||||
pub fn fetch_definition() -> ToolDef {
|
||||
fn fetch_definition() -> ToolDef {
|
||||
ToolDef::new(
|
||||
"web_fetch",
|
||||
"Fetch content from a URL and return it as text. \
|
||||
|
|
@ -31,7 +38,7 @@ pub fn fetch_definition() -> ToolDef {
|
|||
)
|
||||
}
|
||||
|
||||
pub async fn web_fetch(args: &serde_json::Value) -> Result<String> {
|
||||
async fn web_fetch(args: &serde_json::Value) -> Result<String> {
|
||||
let a: FetchArgs = serde_json::from_value(args.clone())
|
||||
.context("invalid web_fetch arguments")?;
|
||||
|
||||
|
|
@ -64,7 +71,7 @@ struct SearchArgs {
|
|||
|
||||
fn default_num_results() -> usize { 5 }
|
||||
|
||||
pub fn search_definition() -> ToolDef {
|
||||
fn search_definition() -> ToolDef {
|
||||
ToolDef::new(
|
||||
"web_search",
|
||||
"Search the web and return results. Use for finding \
|
||||
|
|
@ -86,7 +93,7 @@ pub fn search_definition() -> ToolDef {
|
|||
)
|
||||
}
|
||||
|
||||
pub async fn web_search(args: &serde_json::Value) -> Result<String> {
|
||||
async fn web_search(args: &serde_json::Value) -> Result<String> {
|
||||
let a: SearchArgs = serde_json::from_value(args.clone())
|
||||
.context("invalid web_search arguments")?;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue