use serde_json::Value;
use super::schemas::{FunctionSchema, ToolChoice, ToolsSchema};
use crate::context::Message;
#[derive(Debug, Clone)]
pub struct LLMInvocationParams {
pub messages: Vec<Value>,
pub tools: Option<Vec<Value>>,
pub tool_choice: Option<Value>,
}
pub trait LLMAdapter: Send + Sync {
fn to_provider_tools_format(&self, tools: &ToolsSchema) -> Vec<Value>;
fn to_provider_tool_choice(&self, choice: &ToolChoice) -> Value;
fn convert_messages(&self, messages: &[Message]) -> Vec<Value>;
fn get_invocation_params(
&self,
messages: &[Message],
tools: Option<&ToolsSchema>,
tool_choice: Option<&ToolChoice>,
builtin_tools: &[FunctionSchema],
) -> LLMInvocationParams {
let converted_messages = self.convert_messages(messages);
let converted_tools = tools.map(|t| {
let effective = if builtin_tools.is_empty() {
t.clone()
} else {
t.merge_standard(builtin_tools)
};
self.to_provider_tools_format(&effective)
});
let converted_choice = tool_choice.map(|c| self.to_provider_tool_choice(c));
LLMInvocationParams {
messages: converted_messages,
tools: converted_tools,
tool_choice: converted_choice,
}
}
}