# ol.llx.agent.loop

_platforms: clj, cljs_

## empty-queue

### clj

_platforms: clj_

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

### cljs

_platforms: cljs_

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

---

## handle-command

### clj

_platforms: clj_

```clojure
(handle-command state cmd)
```

Pure command handler. Takes state + command, returns `[state' signals]`.
 Handles global state mutations directly and translates FSM-driving
 commands into signals for the graph.

    Commands that only mutate state (e.g. `:ol.llx.agent.command/steer`) return an empty
    signals vector. Commands that drive the FSM (e.g. `:ol.llx.agent.command/prompt`)
    return one or more signals to be fed into the transition functions.

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

### cljs

_platforms: cljs_

```clojure
(handle-command state cmd)
```

Pure command handler. Takes state + command, returns `[state' signals]`.
 Handles global state mutations directly and translates FSM-driving
 commands into signals for the graph.

    Commands that only mutate state (e.g. `:ol.llx.agent.command/steer`) return an empty
    signals vector. Commands that drive the FSM (e.g. `:ol.llx.agent.command/prompt`)
    return one or more signals to be fed into the transition functions.

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

---

## idle-transition

### clj

_platforms: clj_

```clojure
(idle-transition state msg)
```

Pure transition from ::idle state. Returns [state' effects].

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

### cljs

_platforms: cljs_

```clojure
(idle-transition state msg)
```

Pure transition from ::idle state. Returns [state' effects].

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

---

## streaming-transition

### clj

_platforms: clj_

```clojure
(streaming-transition state msg)
```

Pure transition from ::streaming state. Returns [state' effects].

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

### cljs

_platforms: cljs_

```clojure
(streaming-transition state msg)
```

Pure transition from ::streaming state. Returns [state' effects].

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

---

## tool-executing-transition

### clj

_platforms: clj_

```clojure
(tool-executing-transition state msg)
```

Pure transition from ::tool-executing state. Returns [state' effects].

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

### cljs

_platforms: cljs_

```clojure
(tool-executing-transition state msg)
```

Pure transition from ::tool-executing state. Returns [state' effects].

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

---

## closed-transition

### clj

_platforms: clj_

```clojure
(closed-transition state _msg)
```

Terminal state. No transitions possible.

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

### cljs

_platforms: cljs_

```clojure
(closed-transition state _msg)
```

Terminal state. No transitions possible.

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

---

## route-from-idle

### clj

_platforms: clj_

```clojure
(route-from-idle state)
```

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

### cljs

_platforms: cljs_

```clojure
(route-from-idle state)
```

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

---

## route-from-streaming

### clj

_platforms: clj_

```clojure
(route-from-streaming state)
```

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

### cljs

_platforms: cljs_

```clojure
(route-from-streaming state)
```

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

---

## route-from-tool-executing

### clj

_platforms: clj_

```clojure
(route-from-tool-executing state)
```

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

### cljs

_platforms: cljs_

```clojure
(route-from-tool-executing state)
```

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

---

## command?

### clj

_platforms: clj_

```clojure
(command? input)
```

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

### cljs

_platforms: cljs_

```clojure
(command? input)
```

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

---

## graph

### clj

_platforms: clj_

Agent state machine as data.

    Transitions: `(state, msg) -> [state', effects]`
      Pure transition fns. Take current state and a signal, return
      new state and a vector of effect descriptions to execute.

    Routes: `(state') -> phase-key`
      Pure routing fns. Take the post-transition state and return
      the keyword of the next phase to enter.

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

### cljs

_platforms: cljs_

Agent state machine as data.

    Transitions: `(state, msg) -> [state', effects]`
      Pure transition fns. Take current state and a signal, return
      new state and a vector of effect descriptions to execute.

    Routes: `(state') -> phase-key`
      Pure routing fns. Take the post-transition state and return
      the keyword of the next phase to enter.

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

---

## step

### clj

_platforms: clj_

```clojure
(step state input)
(step g state input)
```

Pure step function. Takes state + input (command or signal), returns `[state' effects]`.

    Commands are processed by `handle-command` which may produce signals.
    Signals are processed by the graph transition + routing fns.

    Emits `:ol.llx.agent.event/agent-end` automatically when the agent transitions from a non-idle phase back to `::idle`.

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

### cljs

_platforms: cljs_

```clojure
(step state input)
(step g state input)
```

Pure step function. Takes state + input (command or signal), returns `[state' effects]`.

    Commands are processed by `handle-command` which may produce signals.
    Signals are processed by the graph transition + routing fns.

    Emits `:ol.llx.agent.event/agent-end` automatically when the agent transitions from a non-idle phase back to `::idle`.

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