Skip to main content
Glama

query_memory

Query a semantic memory graph using SPARQL to retrieve only formally proven facts, verifying what the system knows with certainty.

Instructions

Query the semantic memory graph using SPARQL. Returns ONLY facts that are formally proven (either explicitly added by user or inferred by SPARQL rules).

CRITICAL - Your Role as Assistant:

  • You can make SOFT deductions based on language understanding (e.g., 'knows → probably acquaintances')

  • BUT you MUST distinguish between YOUR deductions and FORMALLY PROVEN facts

  • Use this tool to CHECK if your soft reasoning is formally proven

  • If not proven, use verify_inference() to confirm, then suggest_rule() to formalize

When to use:

  • To verify if a fact exists in the graph

  • To check what the system KNOWS FOR CERTAIN (not what you deduce)

  • To explore relationships and connections

Query Guidelines:

  • ALWAYS scope queries to user namespace with ':' prefix (e.g., ':User', ':Alice')

  • Use LIMIT to avoid overwhelming results (max 1000 auto-injected)

  • Common predicates: foaf:knows, schema:worksFor, schema:colleague, rdf:type

Example workflow 1 (Simple check):

  1. User: 'Is Alice my friend?'

  2. You think: 'Hmm, I see :User foaf:knows :Alice, so maybe friends?'

  3. You call: verify_inference(':User', 'foaf:friend', ':Alice')

  4. Result: 'Not formally proven'

  5. You tell user: 'You know Alice, but friendship is not formally established. Should I create a rule?'

Example workflow 2 (Proactive rule learning):

  1. User asks: 'Can Gilles vote?'

  2. You query: ASK { :Gilles :canVote ?x } → False

  3. You think: 'Voting requires age ≥ 18. Do I know Gilles' age? No.'

  4. You query: ASK { :Gilles :hasDrivingLicense ?x } → True

  5. YOU IMMEDIATELY CALL: suggest_rule( rule_id='driving_license_implies_adult', description='Having a driving license implies being an adult (≥18)', sparql_pattern='CONSTRUCT { ?person :isAdult true } WHERE { ?person :hasDrivingLicense ?license }' )

  6. After user approves, you can then infer :Gilles :isAdult true → can vote

Output format:

  • SELECT: Returns table of results as list of dicts

  • ASK: Returns boolean (True/False)

  • CONSTRUCT/DESCRIBE: Returns graph triples

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSPARQL query to execute. Common prefixes (rdf, rdfs, foaf, schema, owl, sem) are auto-added.
output_formatNoOutput format (default: table for SELECT, turtle for CONSTRUCT)
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It discloses that only formally proven facts are returned, distinguishes soft deductions, mentions auto-injected LIMIT (max 1000), and describes output formats for different SPARQL query types.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is long but well-structured with bold headings and examples. It is front-loaded with the core purpose. The example workflows are somewhat verbose, but they serve the guidance purpose; still, a few sentences could be trimmed without loss.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (SPARQL over a semantic graph) and the absence of an output schema, the description fully covers return value formats (SELECT, ASK, CONSTRUCT/DESCRIBE), query scoping, prefixes, and limits, making it self-sufficient for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, but the description adds significant meaning: auto-added SPARQL prefixes, default output format behavior, and query scoping guidelines with namespace prefix examples. This goes well beyond the schema fields.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Query the semantic memory graph using SPARQL' with a specific verb and resource. It is distinct from siblings like search_entity and verify_inference by emphasizing formal proof and SPARQL execution.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Contains an explicit 'When to use' section and provides alternatives: if not proven, use verify_inference() then suggest_rule(). Example workflows illustrate when to query vs when to verify or suggest rules.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/MauriceIsrael/SmartMemory'

If you have feedback or need assistance with the MCP directory API, please join our Discord server