use saya_agent::{LocalStateEffect, ToolDefinition, ToolEffect};
pub(super) const MAX_TERMS: usize = 16;
pub(crate) fn definitions(allow_query_data: bool, has_state_store: bool) -> Vec<ToolDefinition> {
if !allow_query_data || !has_state_store {
return Vec::new();
}
let connection_prop = serde_json::json!({
"type": "string",
"description": "Optional. Name of the database connection (profile) whose local contract \
memory to read; defaults to the primary. Available connections are listed in the \
system context."
});
vec![
ToolDefinition {
name: "contract_search".into(),
description: "Search the local contract memory (confirmed claims the user remembered \
about their database objects) for objects matching the given terms. Returns \
bounded, confirmed summaries โ candidate claims are not included. A contract is \
derived from the user's database, so this tool is unavailable when database \
context sharing is disabled. Pass up to 16 search terms; matches on alias, the \
qualified name, or description text are returned, most relevant first."
.into(),
read_only: true,
parameters: serde_json::json!({
"type": "object",
"properties": {
"connection": connection_prop.clone(),
"terms": {
"type": "array",
"items": { "type": "string" },
"description": "Search terms (aliases, object names, or description text)."
}
},
"required": ["terms"],
"additionalProperties": false
}),
effect: ToolEffect {
database_data: true,
external_side_effect: false,
requires_approval: false,
local_state: LocalStateEffect::Read,
},
},
ToolDefinition {
name: "contract_read".into(),
description: "Read one object's exact contract from local memory by its fully \
qualified `catalog.schema.table` name. Returns that object's confirmed claims \
(each with its id, kind, origin, status, and value), schema state, and any \
conflicts. A contract is derived from the user's database, so this tool is \
unavailable when database context sharing is disabled. The `table` argument \
must be exactly three dot-separated parts: catalog.schema.object."
.into(),
read_only: true,
parameters: serde_json::json!({
"type": "object",
"properties": {
"connection": connection_prop,
"table": {
"type": "string",
"description": "Fully qualified object name: catalog.schema.object."
}
},
"required": ["table"],
"additionalProperties": false
}),
effect: ToolEffect {
database_data: true,
external_side_effect: false,
requires_approval: false,
local_state: LocalStateEffect::Read,
},
},
]
}