> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agentium.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Admin Storage

> Configure persistence backends for admin-created agents, teams, and workflows.

# Admin Storage

The admin package persists entity blueprints to a `StorageDriver`, ensuring they survive server restarts. Any storage backend supported by `@agentium/core` works.

***

## Storage Backends

<Tabs>
  <Tab title="In-Memory (Dev)">
    ```typescript theme={null}
    import { InMemoryStorage } from "@agentium/core";
    import { createAdminRouter } from "@agentium/admin";

    const { router, hydrate } = createAdminRouter({
      storage: new InMemoryStorage(),
    });
    ```

    <Warning>Data is lost on server restart. Use for development only.</Warning>
  </Tab>

  <Tab title="SQLite">
    ```bash theme={null}
    npm install better-sqlite3
    ```

    ```typescript theme={null}
    import { SqliteStorage } from "@agentium/core";
    import { createAdminRouter } from "@agentium/admin";

    const { router, hydrate } = createAdminRouter({
      storage: new SqliteStorage("agentium.db"),
    });

    await hydrate();
    ```
  </Tab>

  <Tab title="PostgreSQL">
    ```bash theme={null}
    npm install pg
    ```

    ```typescript theme={null}
    import { PostgresStorage } from "@agentium/core";
    import { createAdminRouter } from "@agentium/admin";

    const { router, hydrate } = createAdminRouter({
      storage: new PostgresStorage("postgresql://localhost:5432/agentium"),
    });

    await hydrate();
    ```
  </Tab>

  <Tab title="MongoDB">
    ```bash theme={null}
    npm install mongodb
    ```

    ```typescript theme={null}
    import { MongoDBStorage } from "@agentium/core";
    import { createAdminRouter } from "@agentium/admin";

    const { router, hydrate } = createAdminRouter({
      storage: new MongoDBStorage("mongodb://localhost:27017/agentium"),
    });

    await hydrate();
    ```
  </Tab>
</Tabs>

***

## How It Works

The admin layer uses four namespaces to organize data:

| Namespace                        | Contents                                        |
| -------------------------------- | ----------------------------------------------- |
| `agentium:admin:agents`          | `AgentBlueprint` objects                        |
| `agentium:admin:teams`           | `TeamBlueprint` objects                         |
| `agentium:admin:workflows`       | `WorkflowBlueprint` objects                     |
| `agentium:admin:toolkit-configs` | `ToolkitConfig` objects (credentials, settings) |

Each record is stored as a plain JSON object keyed by the entity's `name` (or `instanceName` for toolkit configs). No class instances or functions are persisted — only serializable configuration.

<Warning>
  Toolkit configs may contain sensitive values (API keys, tokens). These are stored as-is in the storage driver. Use an encrypted-at-rest storage backend (e.g., PostgreSQL with disk encryption) for production deployments. API responses always mask secret fields.
</Warning>

***

## Hydration Flow

On server startup, call `hydrate()` to restore entities:

```text theme={null}
Server starts
    │
hydrate()
    │
ToolkitManager.hydrate()  →  Instantiate enabled toolkit configs  →  Tools available
ConfigStore.listAgents()   →  EntityFactory.createAgent()          →  registry.add()
ConfigStore.listTeams()    →  EntityFactory.createTeam()           →  registry.add()
    │
Transport layer discovers all entities via registry
    │
Ready to serve requests
```

Toolkit configs are hydrated first (so their tools are available), then agents (which may reference those tools), then teams (which reference agents). Entities already in the registry are skipped.

***

## Sharing Storage

The admin storage can use the same `StorageDriver` instance as your agents' memory and sessions. Namespaces prevent collisions:

```typescript theme={null}
const storage = new PostgresStorage("postgresql://localhost:5432/agentium");

// Admin uses agentium:admin:* namespaces
const { router, hydrate } = createAdminRouter({ storage });

// Agents use agentium:sessions:*, agentium:memory:* namespaces
const agent = new Agent({
  name: "bot",
  model: openai("gpt-4o"),
  memory: { storage },
});
```
