aKode: integrazione della memoria di imeAI (plugin memoria)
- nuovo crate ext/memoria: aggiunge le istruzioni del plugin (instructions.md) come developer policy solo se il plugin memoria è abilitato e il suo server MCP è pronto; nessuna modifica alle istruzioni di base, [features] memories resta spento - pollutes_memory configurabile per server MCP (predefinito true) - project_header per i server HTTP: progetto ricavato dalla cartella della sessione (origin come host/owner/repo, altrimenti la cartella), connessioni separate per progetto - token Bearer dei server MCP anche dal portachiavi di aKode, solo sotto mcp:<server> (mai le chiavi dei provider dei modelli) - tool namespace (MCP, multi-agente) appiattiti in <namespace>__<tool> per i server compatibili OpenAI che accettano solo function tool (llama.cpp, ik_llama.cpp, vLLM li scartavano); capacità del provider tool_namespaces - prove: parsing e propagazione, intestazione del progetto, iniezione solo se attivo e connesso, appiattimento e mappatura delle chiamate, chiavi dei provider mai consegnate ai server MCP Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -92,4 +92,6 @@ pub use tool_spec::ResponsesApiWebSearchUserLocation;
|
||||
pub use tool_spec::ToolSpec;
|
||||
pub use tool_spec::create_tools_json_for_responses_api;
|
||||
pub use tool_spec::create_tools_json_for_responses_lite;
|
||||
pub use tool_spec::FLAT_NAMESPACE_SEPARATOR;
|
||||
pub use tool_spec::create_flat_tools_raw_json_for_responses_api;
|
||||
pub use tool_spec::create_tools_raw_json_for_responses_api;
|
||||
|
||||
@@ -142,6 +142,36 @@ pub fn create_tools_json_for_responses_lite(
|
||||
}
|
||||
|
||||
/// Returns raw JSON that can be embedded directly in a Responses API request.
|
||||
/// Separator between namespace and tool name in flattened function names.
|
||||
pub const FLAT_NAMESPACE_SEPARATOR: &str = "__";
|
||||
|
||||
/// Like [`create_tools_raw_json_for_responses_api`], but every `namespace` tool is expanded into
|
||||
/// plain `function` tools named `<namespace>__<tool>`. OpenAI-compatible servers that only accept
|
||||
/// function tools (llama.cpp, ik_llama.cpp, vLLM) silently drop `namespace` entries, which would
|
||||
/// hide MCP tools from the model.
|
||||
pub fn create_flat_tools_raw_json_for_responses_api(
|
||||
tools: &[ToolSpec],
|
||||
) -> Result<Arc<RawValue>, serde_json::Error> {
|
||||
let mut out = Vec::new();
|
||||
for tool in tools {
|
||||
let value = serde_json::to_value(tool)?;
|
||||
if value.get("type").and_then(serde_json::Value::as_str) != Some("namespace") {
|
||||
out.push(value);
|
||||
continue;
|
||||
}
|
||||
let namespace = value.get("name").and_then(serde_json::Value::as_str).unwrap_or_default();
|
||||
for member in value.get("tools").and_then(serde_json::Value::as_array).into_iter().flatten() {
|
||||
let mut member = member.clone();
|
||||
if let Some(name) = member.get("name").and_then(serde_json::Value::as_str) {
|
||||
let flat = format!("{namespace}{FLAT_NAMESPACE_SEPARATOR}{name}");
|
||||
member["name"] = serde_json::Value::String(flat);
|
||||
}
|
||||
out.push(member);
|
||||
}
|
||||
}
|
||||
serde_json::value::to_raw_value(&out).map(Arc::from)
|
||||
}
|
||||
|
||||
pub fn create_tools_raw_json_for_responses_api(
|
||||
tools: &[ToolSpec],
|
||||
) -> Result<Arc<RawValue>, serde_json::Error> {
|
||||
|
||||
@@ -10,6 +10,7 @@ use crate::ResponsesApiNamespaceTool;
|
||||
use crate::ResponsesApiTool;
|
||||
use crate::create_tools_json_for_responses_api;
|
||||
use crate::create_tools_json_for_responses_lite;
|
||||
use crate::create_flat_tools_raw_json_for_responses_api;
|
||||
use crate::create_tools_raw_json_for_responses_api;
|
||||
use akode_protocol::config_types::WebSearchContextSize;
|
||||
use akode_protocol::config_types::WebSearchFilters as ConfigWebSearchFilters;
|
||||
@@ -411,3 +412,36 @@ fn tool_search_tool_spec_serializes_expected_wire_shape() {
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flat_tools_expand_namespaces_into_prefixed_functions() {
|
||||
let raw = create_flat_tools_raw_json_for_responses_api(&[
|
||||
ToolSpec::Function(responses_lite_function("exec_command")),
|
||||
ToolSpec::Namespace(ResponsesApiNamespace {
|
||||
name: "mcp__memoria".to_string(),
|
||||
description: "Memory tools".to_string(),
|
||||
tools: vec![
|
||||
ResponsesApiNamespaceTool::Function(responses_lite_function("memory_recall")),
|
||||
ResponsesApiNamespaceTool::Function(responses_lite_function("memory_propose")),
|
||||
],
|
||||
}),
|
||||
])
|
||||
.expect("serialize flat tools");
|
||||
let value: serde_json::Value = serde_json::from_str(raw.get()).expect("json");
|
||||
let names: Vec<(&str, &str)> = value
|
||||
.as_array()
|
||||
.expect("array")
|
||||
.iter()
|
||||
.map(|t| (t["type"].as_str().unwrap_or(""), t["name"].as_str().unwrap_or("")))
|
||||
.collect();
|
||||
assert_eq!(
|
||||
names,
|
||||
vec![
|
||||
("function", "exec_command"),
|
||||
("function", "mcp__memoria__memory_recall"),
|
||||
("function", "mcp__memoria__memory_propose"),
|
||||
]
|
||||
);
|
||||
// No namespace entries survive: servers that only accept function tools would drop them.
|
||||
assert!(!raw.get().contains("\"namespace\""));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user