Skip to content

Agent integration

The integration between Omega Lisp and the Matrix Agent Platform runs in both directions: Matrix agents can $eval Omega code, and Omega code can call back into the Matrix bus through effects.

Direction 1: Matrix → Omega via $eval

Detailed in Matrix integration. The contract:

  • Caller invokes $eval on system.agents with omega-lisp source.
  • AgentActor looks up the session's repl_state, hydrates an OmegaSandbox, evaluates.
  • Result + updated REPL state are persisted; result also flows back as an activity frame.

Direction 2: Omega → Matrix via effects

Inside Omega, the (effect agent.spawn.op …) family of effects calls back into the Matrix Agent Platform:

lisp
;; Spawn an agent session
(define result (effect agent.spawn.op 'claude 'sonnet "your prompt here"))

;; Run a configured agent
(define run-result (effect agent.run.op my-agent-config))

These are dispatched by the Effect Backend wired to the Matrix bus when running inside a Matrix-embedded Omega instance. Outside that context (a standalone REPL), the same effects route through the driver registry directly.

The Lisp agents package

projects/omega-lisp/packages/agents/ ships a Lisp-level abstraction over agent selection:

lisp
;; lib/agents.lisp
(define-package "agents"
  :description "Agent delegation with amb-based selection"
  :exports '(agents)
  :effects '(agent.spawn.op agent.run.op)
  :requires '()
  :version "0.1.0"
)

(require 'agents/providers)
(require 'agents/selection)

(define (agents error-description)
  "Root package API: delegate to amb-based agent selection."
  (amb-agent-fix error-description))

agents/providers.lisp

A registry of provider/model pairs callable as agents. Conceptually:

lisp
;; (Provider names match the driver-registry names from @open-matrix/inference)
(define providers
  '((claude . (sonnet opus haiku))
    (codex  . (gpt-5.1-codex-max o3 gpt-4.1))
    (ollama . (llama3 mistral))))

The actual file may evolve; the structure is "provider → list of models."

agents/selection.lisp

amb-based selection: try a list of (provider, model) pairs, succeed on the first one whose result satisfies require. The pattern from CLAUDE.md § amb/require for Agent Selection:

lisp
(define (try-agents task)
  (let ((agent (amb 'claude-sonnet 'codex-o3 'claude-haiku)))
    (let ((result (effect agent.run task)))
      (require (result-valid? result))
      result)))

amb-agent-fix is the helper bound by agents/selection.lisp that runs the selection loop with sensible defaults.

Combining both directions

A useful pattern: a Matrix agent receives a prompt, evaluates Omega code that uses amb agent selection, and returns the chosen agent's answer.

Matrix system.agents.<target>     ← user prompt


$eval (omega code)

   ▼ omega: (try-agents task)

       ▼ effect agent.run.op claude-sonnet

            ▼ Matrix system.agents.<sub-target>

            ▼ Anthropic

            ▼ result, recurse if (require ...) fails

This is the "co-recursive tower" applied to multi-agent coordination.

See also

Source: projects/matrix-3/packages/agents/src/AgentsRoot.ts:95 ($eval), projects/omega-lisp/packages/agents/lib/agents.lisp (root entry), and the providers/selection sibling files. The amb/require pattern is documented in projects/omega-lisp/CLAUDE.md § amb/require for Agent Selection.