name: rye-agent-ops description: Operate Rye data safely for LLM agents. Use when implementing or executing agent read/write flows, connecting domain tables, selecting assertion keys, enforcing provenance, and applying agent-safe SQL patterns for context retrieval and auditable writes.
Rye Agent Ops
Session Setup (Required)
Before any query, set the session context. On stateless connections (Supabase MCP, serverless, transaction-mode poolers), this must be done in every call:
SELECT set_config('app.current_role', 'admin', false);
SELECT set_config('app.current_user_id', 'user-123', false);
SELECT set_config('app.current_teams', 'engineering', false);
Without this, RLS will block access. Use set_config() (not SET syntax) for portability.
Orient
- Run
SELECT rye_catalog()to see what's in the instance — node types, edge types, assertion types, tracked tables, and totals. - Use
agent_node_summary(node_id, max_items)for compact context on a specific node.
Connect Domain Tables
- Use
link_record(schema, table, id, node_type, label, properties)to connect a domain table row to the graph. Idempotent. - Use
track_table(schema, table)to attach CDC triggers that capture INSERT/UPDATE/DELETE as graph events.
Write Events
Use record_event(...) for all event creation:
SELECT record_event(
p_event_type := 'meeting',
p_summary := 'Weekly sync',
p_participant_ids := ARRAY[node1, node2]::uuid[],
p_participant_roles := ARRAY['organizer', 'attendee']
);
Do not insert into events and event_participants separately.
Write Assertions
- Insert assertions directly (subject to RLS).
- For single-valued facts:
assertion_key = 'default', supersede withsupersede_assertion(...). - For multi-valued facts: use stable domain keys in
assertion_key. - Do not run direct
UPDATE assertions.
Knowledge Candidates and Promotion
Use the candidate workflow when source material has plausible facts, tasks, decisions, risks, procedures, preferences, or semantic edges but the knowledge has not been accepted yet.
- Create proposed candidates with
create_knowledge_candidate(...). - Link candidates to source evidence with
supported_byand to import/run context withderived_fromusing the helper function parameters. - Keep candidate status as
proposedorneeds_reviewuntil a user or trusted reviewer accepts, rejects, marks duplicate, or asks for promotion. - Promote accepted candidates only through:
promote_candidate_to_assertion(...)promote_candidate_to_task(...)promote_candidate_to_edge(...)
- Store candidate provenance in promoted assertion/edge/task attrs. The helper functions already preserve candidate and source refs.
- If source accounts or containers are still
needs_confirmation, do not rely on their default context to promote knowledge. Use only item-level evidence and explicit reviewer decisions.
Candidate statuses are:
proposedacceptedrejectedneeds_reviewduplicatesuperseded
Do not bulk-promote a candidate queue just because a parser generated it. A bulk promotion must have an explicit approval decision, target shape, and provenance policy.
Provenance
- Log agent queries with
log_agent_query(agent_id, query, summary, node_ids). - Attach
source_event_idto assertions when the fact came from an event.
Safety
- Keep reads scoped and ranked.
- Avoid dumping full history to the model by default.
- Gate high-risk actions behind explicit user confirmation.