Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Environment Map

Every callback an extension receives — :ext/activation-fn, :ext/prompt, :ext/nudge-fn, and the symbol hooks (:before-fn, :after-fn, :on-error-fn) — operates on the environment. This is the runtime map that represents one live conversation context.

All Keys

Conversation-scoped (set at create-environment time)

These keys exist on every environment for its entire lifetime:

KeyTypeDescription
:env-idstringUnique UUID string. Stable for the conversation lifetime. Use for log correlation.
:conversation-idjava.util.UUIDConversation entity ID in the DB (plain UUID, not a tagged pair). Every query/iteration/var is parented under this.
:db-infomapDatabase connection handle ({:datasource ds …}). Pass to persistance.core functions for reads. Do not close it.
:routermapsvar LLM router. Provider configs, model list, routing rules. Read-only.
:sci-ctxSCI contextLive SCI sandbox context. Contains the :env atom with all namespace maps. Read sandbox state via (get-in @(:env sci-ctx) [:namespaces 'sandbox]). Do not mutate directly — use bind-and-bump!.
:sandbox-nsSCI nsThe 'sandbox namespace object. Used internally by eval-string+.
:initial-ns-keysset of symbolsSymbols in the sandbox at creation time (tools, helpers, builtins). Distinguishes user vars from infrastructure.
:var-index-atomatomCached <var_index> render. Shape: {:index string, :revision int, :current-revision int}. The rendered string is compact pseudo-source ((def ^{:v 3 :s :l :t :map :n 12} foo ...), (defn ^{:v 2 :s :l} f [x] ...)). Bump via bump-var-index! after mutating sandbox bindings.
:extensionsatom of vectorAll registered extensions. Managed by register-extension! (replaces by :ext/namespace). Read by the iteration loop for nudges.
:state-atomatomInternal: {:custom-bindings {sym val}, :environment <self-ref>, :conversation-id uuid}. Extensions should not poke this.
:depth-atomatom of intSub-RLM recursion depth. 0 for top-level queries.

Query-scoped (added by the query engine per turn)

These keys are assoc’d onto the environment map when a query starts (query/core.clj :: prepare-query-context). They do not exist on the base environment returned by create-environment.

KeyTypeDescription
:max-iterations-atomatom of intLive iteration budget — extendable via request-more-iterations. Reset each query.
:current-iteration-id-atomatom of UUID or nilEntity ID (UUID) of the most recent store-iteration!. Created by prepare-query-context, reset to nil at query start, updated after each store-iteration!. Used for sub-RLM parenting.
:parent-iteration-iduuid or nilNon-nil for sub-RLM forks. Points to the parent iteration.

Safe Operations

  • Read any key for conditional logic (:db-info, :conversation-id, :sci-ctx, :router, :initial-ns-keys).
  • Call persistance.core functions with :db-info for DB reads.
  • Bump the var-index cache via bump-var-index! after your tool mutates sandbox state.
  • Read sandbox vars via (get-in @(:env (:sci-ctx env)) [:namespaces 'sandbox sym]).

Prohibited Operations

  • Close :db-info — the runtime owns the connection lifecycle.
  • Swap :extensions directly — use register-extension!.
  • Reset :max-iterations-atom or :current-iteration-id-atom — internal iteration-loop state.
  • Mutate :sci-ctx namespace maps without calling bump-var-index! — the <var_index> cache will serve stale data.