агенты: добавить поиск инструментов по каталогу
This commit is contained in:
@@ -398,6 +398,116 @@ async fn creates_binds_and_publishes_agent() {
|
||||
assert_eq!(published["published_version"], 1);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
#[serial]
|
||||
async fn saves_and_previews_versioned_agent_tool_search_policy() {
|
||||
let registry = test_registry().await;
|
||||
let storage_root = test_storage_root("agent_tool_search");
|
||||
let upstream_base_url = spawn_upstream_server().await;
|
||||
let base_url = spawn_admin_api(build_test_app(registry, storage_root)).await;
|
||||
let client = authorized_client(&base_url).await;
|
||||
|
||||
let operation = assert_success_json(
|
||||
client
|
||||
.post(format!("{base_url}/operations"))
|
||||
.json(&test_operation_payload(
|
||||
&upstream_base_url,
|
||||
"finance_create_invoice",
|
||||
))
|
||||
.send()
|
||||
.await
|
||||
.unwrap(),
|
||||
)
|
||||
.await;
|
||||
let operation_id = operation["operation_id"].as_str().unwrap().to_owned();
|
||||
assert_success_json(
|
||||
client
|
||||
.post(format!("{base_url}/operations/{operation_id}/publish"))
|
||||
.json(&json!({"version": 1}))
|
||||
.send()
|
||||
.await
|
||||
.unwrap(),
|
||||
)
|
||||
.await;
|
||||
|
||||
let agent = assert_success_json(
|
||||
client
|
||||
.post(format!("{base_url}/agents"))
|
||||
.json(&json!({
|
||||
"slug": "finance-agent",
|
||||
"display_name": "Finance Agent",
|
||||
"description": "Finance workflows",
|
||||
"instructions": {},
|
||||
"tool_selection_policy": {}
|
||||
}))
|
||||
.send()
|
||||
.await
|
||||
.unwrap(),
|
||||
)
|
||||
.await;
|
||||
let agent_id = agent["agent_id"].as_str().unwrap().to_owned();
|
||||
let catalog = json!({
|
||||
"bindings": [{
|
||||
"operation_id": operation_id,
|
||||
"operation_version": 1,
|
||||
"tool_name": "finance_create_invoice",
|
||||
"tool_title": "Create Lead",
|
||||
"tool_description_override": "Creates an invoice for a customer",
|
||||
"enabled": true
|
||||
}],
|
||||
"tool_selection_policy": {
|
||||
"mode": "search",
|
||||
"groups": [{
|
||||
"id": "finance",
|
||||
"name": "Finance",
|
||||
"description": "Invoices and payments",
|
||||
"tool_names": ["finance_create_invoice"]
|
||||
}],
|
||||
"search": {"max_results": 5}
|
||||
}
|
||||
});
|
||||
let saved = assert_success_json(
|
||||
client
|
||||
.post(format!("{base_url}/agents/{agent_id}/bindings"))
|
||||
.json(&catalog)
|
||||
.send()
|
||||
.await
|
||||
.unwrap(),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(saved["snapshot"]["tool_selection_policy"]["mode"], "search");
|
||||
|
||||
let preview = assert_success_json(
|
||||
client
|
||||
.post(format!("{base_url}/agents/tool-search/preview"))
|
||||
.json(&json!({
|
||||
"query": "create invoice",
|
||||
"group_ids": ["finance"],
|
||||
"bindings": catalog["bindings"],
|
||||
"tool_selection_policy": catalog["tool_selection_policy"]
|
||||
}))
|
||||
.send()
|
||||
.await
|
||||
.unwrap(),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(
|
||||
preview["items"][0]["tool"]["name"],
|
||||
"finance_create_invoice"
|
||||
);
|
||||
|
||||
let published = assert_success_json(
|
||||
client
|
||||
.post(format!("{base_url}/agents/{agent_id}/publish"))
|
||||
.json(&json!({"version": 1}))
|
||||
.send()
|
||||
.await
|
||||
.unwrap(),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(published["published_version"], 1);
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
#[serial]
|
||||
async fn agent_publish_skips_draft_operation_bindings_and_preserves_draft() {
|
||||
|
||||
Reference in New Issue
Block a user