# ol.llx.agent.fx

_platforms: clj, cljs_

Effect interpreter for the agent runtime.

    The pure state machine in `ol.llx.agent.loop` emits inert effect maps.
    This namespace interprets those maps into concrete side effects.

    Effect categories:

    Fire-and-forget — synchronous, produce no signals.
      - `:emit-event` — publish an event to subscribers
      - `:reject`     — report invalid operation state

    Signal-producing — async, return a channel of signals.
      - `:call-llm`     — perform inference and stream `llm-*` signals
      - `:execute-tool` — execute a tool and emit `tool-*` signals

    Signal-producing effects return promesa CSP channels consumed by
    `ol.llx.agent.driver/run`.

## execute-fx

### clj

_platforms: clj_

```clojure
(execute-fx env effect)
```

Interpret a single effect description. Dispatches on `::type`.

    Fire-and-forget effects (`:emit-event`, `:reject`):
    Execute the side effect synchronously. Return `nil`.

    Signal-producing effects (`:call-llm`, `:execute-tool`):
    Start the async work and return a promesa CSP channel that will
    emit signal maps. The channel closes when the effect is complete.
    The driver consumes the channel and steps each signal through
    `loop/step`. The interpreter must not call `step` or mutate the
    state atom.

    `env` carries runtime dependencies:
      - `:state_`            — atom holding current agent state (read-only for fx)
      - `:events-mx>`        — event multiplexer write endpoint
      - `:convert-to-llm`    — `(fn [messages])` transform to LLM messages
      - `:transform-context`  — `(fn [messages abort-signal])` optional context pruning
      - `:stream-fn`          — `(fn [model context opts])` LLM streaming fn
      - `:abort-signal`       — abort token for cancellation

[source,window=_blank](https://github.com/outskirtslabs/llx/blob/main/src/ol/llx/agent/fx.cljc#L36-L66)

### cljs

_platforms: cljs_

```clojure
(execute-fx env effect)
```

Interpret a single effect description. Dispatches on `::type`.

    Fire-and-forget effects (`:emit-event`, `:reject`):
    Execute the side effect synchronously. Return `nil`.

    Signal-producing effects (`:call-llm`, `:execute-tool`):
    Start the async work and return a promesa CSP channel that will
    emit signal maps. The channel closes when the effect is complete.
    The driver consumes the channel and steps each signal through
    `loop/step`. The interpreter must not call `step` or mutate the
    state atom.

    `env` carries runtime dependencies:
      - `:state_`            — atom holding current agent state (read-only for fx)
      - `:events-mx>`        — event multiplexer write endpoint
      - `:convert-to-llm`    — `(fn [messages])` transform to LLM messages
      - `:transform-context`  — `(fn [messages abort-signal])` optional context pruning
      - `:stream-fn`          — `(fn [model context opts])` LLM streaming fn
      - `:abort-signal`       — abort token for cancellation

[source,window=_blank](https://github.com/outskirtslabs/llx/blob/main/src/ol/llx/agent/fx.cljc#L36-L66)
