sop

Scalable Objects Persistence


Project maintained by SharedCode Hosted on GitHub Pages — Theme by mattgraham

AI Copilot User Guide

The SOP AI Copilot is a powerful, conversational interface for interacting with your SOP databases. It allows you to query data, perform CRUD operations, and automate complex workflows using natural language.

Core Philosophy: Stateless vs. Stateful

To ensure system stability and prevent “dangling transactions,” the Copilot operates in two distinct modes:

  1. Stateless (Interactive & Recording): Every prompt is an independent unit of work.
    • If you ask “Select all users”, the Copilot opens a transaction, reads the data, and immediately closes the transaction.
    • This applies even when Recording. Each step you record is executed and committed immediately.
  2. Stateful (Playback): When Playing a Script, the Copilot can maintain a transaction across multiple steps.
    • This allows scripts to perform complex, multi-step atomic operations (e.g., “Transfer funds: Debit A, Credit B”).
    • If any step fails, the entire script transaction can be rolled back.

1. Natural Language Data Access

You can ask the Copilot to retrieve data using plain English. It translates your intent into optimized B-Tree lookups.

Listing Resources

Selecting Data

The select tool is powerful and supports filtering and field selection.

Finding Specific Records

Querying Rules & Expectations

To ensure accurate results, it’s important to understand how the AI Copilot and API interpret your queries, particularly regarding case sensitivity.

Schema Names (Case-Insensitive)

Field names and JSON keys are Case-Insensitive.

Data Values (Case-Sensitive)

Actual data values used in comparisons are Case-Sensitive.

Entity Names (Case-Insensitive)

Names of Databases, Stores, and Scripts are Case-Insensitive.

Efficient Query Scenarios

SOP is a high-performance database that uses B-Trees. To get the maximum speed (especially on large datasets), structure your questions to leverage the Index (Key) structure.

How to write fast queries: The “Index” is defined by the Key fields of your store.

Scenario Index (Key) Structure Query Example Status
Exact Match [Region, Dept] “Find employees in ‘US’ ‘Sales’” Fast
Prefix Match [Region, Dept] “Find employees in ‘US’” Fast
Natural Sort [Region, Dept] “Find ‘US’ employees, ordered by Dept” Fast
Skip Prefix [Region, Dept] “Find employees in ‘Sales’” (Skipped Region) 🐢 Slow (Full Scan)
Sort Conflict [Region, Dept] “Find ‘US’ employees, ordered by Dept DESC” (If index is ASC) 🐢 Slower (Buffered)

2. CRUD Operations

You can modify data directly.

Adding Data

Updating Data

Deleting Data

Note: In Stateless Mode, these operations commit immediately. If you need to do multiple updates atomically, consider using a Script.


4. Memory & Learning: The Self-Correcting Copilot

The AI is designed to evolve. It possesses two distinct types of memory, allowing it to adapt to your specific environment and business logic over time.

Short-Term Memory ( The “Session” Context)

This is the Working Memory. It holds the immediate context of your current conversation, active transaction, and recent query results.

Long-Term Memory (The “System Knowledge”)

This is the Enterprise Brain. It persists facts, business rules, and corrections across all sessions and users. It effectively turns the AI into a “Self-Correcting” system.

Why this matters: You don’t need to write perfect prompts every time. If the AI gets it wrong, you fix it once, and it stays fixed—for you and your team.


5. Script Management (Automation)

Scripts allow you to record a sequence of actions and replay them later. This is “Natural Language Programming.”

Recording a Script

  1. Start: Type /record my_new_script.
    • Default (Compiled): Records the exact actions (tools) you perform. When played back, it executes these actions directly (fast, deterministic).
    • Interactive Mode: Type /record my_new_script --ask. Records your prompts. When played back, it asks the AI again (slower, but adapts to new data/context).
  2. Teach: Perform your actions step-by-step.
    • “Select users where role is admin.”
    • “For each user, check their last login.”
    • “If last login is > 30 days, set status to inactive.”
  3. Stop: Type /stop.

The script is saved incrementally after every step. If you crash or disconnect, your progress is safe!

Playing a Script

Managing Scripts


4. Advanced Features

Explicit Transaction Management

For complex, multi-step manual operations without creating a script, you can manually control the transaction:

Swarm Computing (Async)

When defining scripts manually (or asking the Assistant to edit them), you can mark steps as is_async: true. This allows the Assistant to execute multiple heavy tasks in parallel (e.g., “Summarize these 50 documents”).


5. Session Tools


Example Session

```text User: /record onboard_user Copilot: Recording started for script ‘onboard_user’.

User: Add a user to ‘users’ with key ‘new_guy’ and status ‘pending’. Copilot: Added user ‘new_guy’. (Step recorded)

User: Add a log entry to ‘audit_logs’ saying “User new_guy created”. Copilot: Added log entry. (Step recorded)

User: /stop Copilot: Recording stopped. Script ‘onboard_user’ saved with 2 steps.

User: /play onboard_user Copilot: Executing ‘onboard_user’…

  1. Added user…
  2. Added log entry…

6. Mobile & Small Device Support (“Pocket Admin”)

The SOP AI Copilot is designed with a Mobile-First responsiveness philosophy, turning your smartphone or tablet into a full-featured “Pocket Admin” console.

Optimized UI

The chat interface automatically adapts to smaller screens:

You are not limited to “read-only” views on mobile. You can perform all system operations via chat:

The Copilot essentially acts as a highly capable CLI (Command Line Interface) wrapped in a chat bubble, ensuring you have full control over your infrastructure without needing a laptop.