Layi Docs

Architecture

Agents & Memory

Supervisor planners, specialist executors, and the memory fabric that keeps them grounded

Last updated: December 2025

🧑‍✈️ Roles & responsibilities

Layi agents follow a strict hierarchy. Supervisors plan and coordinate work, while specialists execute scoped tasks with tightly-controlled tools. Every org also receives an Org-Manager agent that audits performance and schedules improvements.

Supervisor / Orchestrator
Owns the mission state, emits plans, selects tools and sub-agents, enforces policy, and finalizes outputs.
Specialist Sub-Agents
Ephemeral skills (clarification, fetchers, execution) wrapped as tools so planners can call them deterministically.
Org-Manager
Persistent oversight agent that reviews rewards, kicks off follow-ups, and pushes procedural memory updates.

🏢 Org-Manager agent (default supervisor)

The Org-Manager agent is instantiated for every tenant at signup. It is separate from the human Org Manager portal and cannot create users or API keys. Instead, it manages every other agent on behalf of the organization.

  • Orchestration: delegates multi-agent workloads, invokes the Planner-Agent for new missions, and keeps the mission graph accurate.
  • Performance review: inspects run confidence scores daily, requests procedural learning when quality drops, and approves/declines refinements.
  • Notifications & escalations: monitors incidents, tool expirations, and escalations, then pages humans via notification tools.
  • Document & data management: keeps organizational documents up-to-date via doc manager APIs and confirms edits with humans.
  • Reporting: produces configurable org, department, and tool reports for stakeholders.
  • Quality assurance: fixes broken context, corrects logical errors, and blocks hallucinations before they spread.
  • Guardrails & security: enforces and overrides guardrails, ensuring confidential data stays scoped correctly.
  • Tool credential management: assigns or revokes tools based on department policy (e.g., HR agents never see finance tools).
  • Agent control: disables misbehaving agents or terminates tasks when safety requires it.
  • Monitoring & audits: watches progress, token usage, and audit logs; coordinates with humans for billing and continuous improvement.

The Org-Manager agent is highly autonomous but transparent: every action is logged, and it always routes human communication through approved channels.

📆 Task schedules & working hours

Agents execute tasks immediately, on a defined schedule, or in response to events. Temporal schedules, cron-like policies, and Working Hours windows keep them aligned with business calendars.

  • One-time missions: Trigger ad-hoc jobs (e.g., “audit the Q4 finance inbox”) that run to completion once and archive their artifacts.
  • Recurring schedules: Configure cron/interval rules such as “send weekly org report every Monday at 16:00” or “refresh vendor rosters on the first business day of the month.”
  • Working hours: Define local business hours (e.g., 5am–7pm PT). Agents automatically “wake up,” place calls, send emails, and pause outreach outside of compliant windows.
  • Event-driven: Hook schedules to signals (new ticket, stale invoice, voice hotline ring) so planners launch only when the upstream system emits an event.
  • Overrides & skips: Operators can pause, skip the next run, or reschedule within the dashboard without editing YAML/cron syntax.

Each scheduled run captures the plan, timezone metadata, and any SLA clocks so auditors know why the agent acted at that moment.

📋 Default sub-agent roster

Every organization is provisioned with a canonical roster so critical guardrails exist before custom agents are deployed. The Agent Creator workflow enforces the roster even when LLM output is incomplete.

Clarification-Agent
Triages inbound requests, elicits missing facts, and publishes a structured clarity payload.
Episodic & Procedural Fetchers
Pull recent conversations plus lessons-learned so planners can ground each plan.
RAG-Fetcher
Executes retrieval across the org knowledge base (Elasticsearch + LlamaIndex).
Planner-Agent
Premium model dedicated to plan generation, schema validation, and tool scheduling.
Task-Goal-Agent
Step-by-step executor that captures evidence for each tool call and streams thinking events.
Verification-Agent
Scores outputs, enforces evidence requirements, and emits reward payloads for the Org-Manager.

⚙️ Agent lifecycle

Agents are defined in Cassandra, hydrated at runtime, and continuously improved through nightly learning passes.

  1. Create: Org supplies prompts/templates or invokes Agent Creator. Configs are stored with UUID agent_ids inside the registry.
  2. Bootstrap: Org-Manager workflow registers mandatory sub-agents and schedules nightly audits.
  3. Execute: Supervisors load configs, attach tools, and run inside Temporal workflows with procedural memory streaming events.
  4. Observe: Each step records observability summaries, plan diffs, and procedural events for replay.
  5. Improve: Nightly learners read reward payloads, update procedural memory, and optionally request agent refinements.

🧠 Memory attachments

Agents keep context separated into specialized stores so retrieval stays fast and auditable.

Agent Registry
Cassandra tables hold prompts, capabilities, and workflow schemas per org.
Working & Workflow memory
Temporal workflow state plus Redis scratchpads keep current-step context.
Procedural memory
Durable event log of successful steps, stored without TTL for re-use across runs.
Episodic memory
Day-bucketed Cassandra + Elasticsearch stores capturing conversations and approvals.
Semantic knowledge
Docs, PDFs, DB exports indexed via Elasticsearch/LlamaIndex for RAG calls.
Toolbox metadata
Vault + Tool Gateway metadata describing credentials, rate limits, and availability.

📣 Org-Manager integration

`_record_post_run_feedback` persists reward payloads and decides whether to trigger the Org-Manager follow-up workflow. Reasons include severity, low scores, or verification failures. Temporal schedules also ensure nightly health checks per org.

  • Bootstrap: `OrgManagerCreatorWorkflow` seeds default configs, writes PostgreSQL mappings, and caches schedule guards.
  • Follow-ups: `trigger_org_manager_followup` launches ad-hoc audits with memoized reasons and reward snapshots.
  • Reports: Org-Manager agents persist findings to procedural + episodic memory and can escalate incidents via MCP tools.
  • Refinement loop: Recommendations can automatically update agent configs via `request_agent_refinement` helpers.

📞 Voice & chat surfaces

Every agent can expose a chat endpoint, SDK token, and LiveKit-powered voice line. Org Manager owns the routing table so you can assign a dedicated phone number per agent or share an org-wide entry point that dynamically forwards to the right specialist.

Phone numbers
Org Manager provisions Twilio numbers per agent or per org and maps them to ConversationRelay WebSocket endpoints.
Live voice pipeline
ConversationRelay → speech-to-text engine → LLM reasoning → synthesized voice streamed back over the same session.
Chat & SDK
Dashboard chat, mobile, and SDK clients reuse the same supervisor context so intent + memory stay consistent across channels.
Org Manager routing
Policies decide which agent handles each call, apply concurrency limits, and log usage for billing.
Dedicated sessions
Voice and chat maintain their own Temporal workflows so pausing/resuming a call never interferes with parallel chat runs.
Compliance
Call recordings, transcripts, and alerts feed back into procedural memory with masking + retention policies.

Agent Creation