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
|
|
@ -17,7 +17,7 @@ use std::time::{Duration, Instant};
|
|||
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::agent::tools::{ToolCall, ToolDef, FunctionCall};
|
||||
use crate::agent::tools::{self as agent_tools, ToolCall, FunctionCall};
|
||||
use crate::user::ui_channel::{UiMessage, UiSender};
|
||||
|
||||
/// A JoinHandle that aborts its task when dropped.
|
||||
|
|
@ -41,6 +41,12 @@ pub struct SamplingParams {
|
|||
// Stream events — yielded by backends, consumed by the runner
|
||||
// ─────────────────────────────────────────────────────────────
|
||||
|
||||
/// Build the tools JSON string from a slice of Tools.
|
||||
fn tools_to_json_str(tools: &[agent_tools::Tool]) -> String {
|
||||
let inner: Vec<String> = tools.iter().map(|t| t.to_json()).collect();
|
||||
format!("[{}]", inner.join(","))
|
||||
}
|
||||
|
||||
/// Events produced by the streaming API backends.
|
||||
/// The runner reads these and decides what to display where.
|
||||
pub enum StreamEvent {
|
||||
|
|
@ -98,7 +104,7 @@ impl ApiClient {
|
|||
pub fn start_stream(
|
||||
&self,
|
||||
messages: &[Message],
|
||||
tools: Option<&[ToolDef]>,
|
||||
tools: &[agent_tools::Tool],
|
||||
ui_tx: &UiSender,
|
||||
reasoning_effort: &str,
|
||||
sampling: SamplingParams,
|
||||
|
|
@ -109,7 +115,8 @@ impl ApiClient {
|
|||
let api_key = self.api_key.clone();
|
||||
let model = self.model.clone();
|
||||
let messages = messages.to_vec();
|
||||
let tools = tools.map(|t| t.to_vec());
|
||||
let tools_json = tools_to_json_str(tools);
|
||||
let tools_value: serde_json::Value = serde_json::from_str(&tools_json).unwrap_or_default();
|
||||
let ui_tx = ui_tx.clone();
|
||||
let reasoning_effort = reasoning_effort.to_string();
|
||||
let base_url = self.base_url.clone();
|
||||
|
|
@ -117,7 +124,7 @@ impl ApiClient {
|
|||
let handle = tokio::spawn(async move {
|
||||
let result = openai::stream_events(
|
||||
&client, &base_url, &api_key, &model,
|
||||
&messages, tools.as_deref(), &tx, &ui_tx,
|
||||
&messages, &tools_value, &tx, &ui_tx,
|
||||
&reasoning_effort, sampling, priority,
|
||||
).await;
|
||||
if let Err(e) = result {
|
||||
|
|
@ -131,7 +138,7 @@ impl ApiClient {
|
|||
pub async fn chat_completion_stream_temp(
|
||||
&self,
|
||||
messages: &[Message],
|
||||
tools: Option<&[ToolDef]>,
|
||||
tools: &[agent_tools::Tool],
|
||||
ui_tx: &UiSender,
|
||||
reasoning_effort: &str,
|
||||
sampling: SamplingParams,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue