tools: delete ToolDef and FunctionDef
ToolDef and FunctionDef are gone. Tool definitions are static strings on the Tool struct. The API layer builds JSON from Tool::to_json(). - ChatRequest.tools is now Option<serde_json::Value> - start_stream takes &[Tool] instead of Option<&[ToolDef]> - openai::stream_events takes &serde_json::Value for tools - memory_and_journal_tools() returns Vec<Tool> for subconscious agents - Subconscious agents filter by t.name instead of t.function.name No more runtime JSON construction for tool definitions. No more ToolDef::new(). No more FunctionDef. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
d195160b1e
commit
51e632c997
7 changed files with 33 additions and 78 deletions
|
|
@ -46,13 +46,12 @@ pub async fn call_api_with_tools(
|
|||
let (ui_tx, mut ui_rx) = crate::user::ui_channel::channel();
|
||||
|
||||
// All available native tools for subconscious agents
|
||||
let all_tools = agent_tools::memory_and_journal_definitions();
|
||||
// If agent header specifies a tools whitelist, filter to only those
|
||||
let tool_defs: Vec<_> = if tools.is_empty() {
|
||||
let all_tools = agent_tools::memory_and_journal_tools();
|
||||
let agent_tool_list: Vec<_> = if tools.is_empty() {
|
||||
all_tools
|
||||
} else {
|
||||
all_tools.into_iter()
|
||||
.filter(|t| tools.iter().any(|w| w == &t.function.name))
|
||||
.filter(|t| tools.iter().any(|w| *w == t.name))
|
||||
.collect()
|
||||
};
|
||||
// Provenance tracks which agent:phase is making writes.
|
||||
|
|
@ -83,7 +82,7 @@ pub async fn call_api_with_tools(
|
|||
};
|
||||
match client.chat_completion_stream_temp(
|
||||
&messages,
|
||||
Some(&tool_defs),
|
||||
&agent_tool_list,
|
||||
&ui_tx,
|
||||
&reasoning,
|
||||
sampling,
|
||||
|
|
|
|||
|
|
@ -295,13 +295,13 @@ fn run_one_agent_inner(
|
|||
_llm_tag: &str,
|
||||
log: &(dyn Fn(&str) + Sync),
|
||||
) -> Result<AgentResult, String> {
|
||||
let all_tools = crate::agent::tools::memory_and_journal_definitions();
|
||||
let all_tools = crate::agent::tools::memory_and_journal_tools();
|
||||
let effective_tools: Vec<String> = if def.tools.is_empty() {
|
||||
all_tools.iter().map(|t| t.function.name.clone()).collect()
|
||||
all_tools.iter().map(|t| t.name.to_string()).collect()
|
||||
} else {
|
||||
all_tools.iter()
|
||||
.filter(|t| def.tools.iter().any(|w| w == &t.function.name))
|
||||
.map(|t| t.function.name.clone())
|
||||
.filter(|t| def.tools.iter().any(|w| w == &t.name))
|
||||
.map(|t| t.name.to_string())
|
||||
.collect()
|
||||
};
|
||||
let tools_desc = effective_tools.join(", ");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue