# ol.llx.agent

_platforms: clj, cljs_

Public runtime wrapper for the agent loop.

    This namespace wires runtime state, effect environment dependencies,
    and subscription management around `ol.llx.agent.loop` + `ol.llx.agent.fx`.

## create-initial-state

### clj

_platforms: clj_

```clojure
(create-initial-state schema-registry opts)
```

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

### cljs

_platforms: cljs_

```clojure
(create-initial-state schema-registry opts)
```

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

---

## default-convert-to-llm

### clj

_platforms: clj_

```clojure
(default-convert-to-llm messages)
```

Converts agent messages to LLM-compatible messages by keeping only maps
 whose `:role` is one of `:user`, `:assistant`, or `:tool-result`.

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

### cljs

_platforms: cljs_

```clojure
(default-convert-to-llm messages)
```

Converts agent messages to LLM-compatible messages by keeping only maps
 whose `:role` is one of `:user`, `:assistant`, or `:tool-result`.

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

---

## create-agent

### clj

_platforms: clj_

```clojure
(create-agent)
(create-agent opts)
```

Creates an agent runtime handle.

    Required options:
    - `:tools`             vector of tools

    `opts` may include:
    - `:convert-to-llm`    `(fn [messages])`; defaults to filtering
                           messages to roles `:user`, `:assistant`,
                           `:tool-result`
    - `:transform-context` optional context transform hook
    - `:stream-fn`         optional stream hook; resolved at callsite
    - `:schema-registry`   extra Malli registry to be composed with the built-in schemas
    - `:custom-message-schemas` map of message dispatch keyword to schema keyword in the active registry
    - `:session-id`, `:get-api-key`, `:thinking-budgets`, `:max-retry-delay-ms`
    - `:system-prompt`, `:model`, `:thinking-level`
    - `:steering-mode`, `:follow-up-mode`
    - `:abort-signal`

For state rehydration, use [`rehydrate-agent`](#rehydrate-agent).

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

### cljs

_platforms: cljs_

```clojure
(create-agent)
(create-agent opts)
```

Creates an agent runtime handle.

    Required options:
    - `:tools`             vector of tools

    `opts` may include:
    - `:convert-to-llm`    `(fn [messages])`; defaults to filtering
                           messages to roles `:user`, `:assistant`,
                           `:tool-result`
    - `:transform-context` optional context transform hook
    - `:stream-fn`         optional stream hook; resolved at callsite
    - `:schema-registry`   extra Malli registry to be composed with the built-in schemas
    - `:custom-message-schemas` map of message dispatch keyword to schema keyword in the active registry
    - `:session-id`, `:get-api-key`, `:thinking-budgets`, `:max-retry-delay-ms`
    - `:system-prompt`, `:model`, `:thinking-level`
    - `:steering-mode`, `:follow-up-mode`
    - `:abort-signal`

For state rehydration, use [`rehydrate-agent`](#rehydrate-agent).

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

---

## rehydrate-agent

### clj

_platforms: clj_

```clojure
(rehydrate-agent state opts)
```

Creates an agent runtime from a previously persisted state snapshot.

    `state` must satisfy `:ol.llx.agent.loop/state`.
    `opts` carries runtime dependencies and may include:
    - `:convert-to-llm` (optional; see <<create-agent,`create-agent`>>)
    - `:transform-context` (optional; see <<create-agent,`create-agent`>>)
    - `:stream-fn` (optional; see <<create-agent,`create-agent`>>)
    - `:schema-registry` (optional; see <<create-agent,`create-agent`>>)
    - `:custom-message-schemas` (optional; see <<create-agent,`create-agent`>>)
    - `:session-id`, `:get-api-key`, `:thinking-budgets`, `:max-retry-delay-ms`
* `:tools`
* `:abort-signal`.

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

### cljs

_platforms: cljs_

```clojure
(rehydrate-agent state opts)
```

Creates an agent runtime from a previously persisted state snapshot.

    `state` must satisfy `:ol.llx.agent.loop/state`.
    `opts` carries runtime dependencies and may include:
    - `:convert-to-llm` (optional; see <<create-agent,`create-agent`>>)
    - `:transform-context` (optional; see <<create-agent,`create-agent`>>)
    - `:stream-fn` (optional; see <<create-agent,`create-agent`>>)
    - `:schema-registry` (optional; see <<create-agent,`create-agent`>>)
    - `:custom-message-schemas` (optional; see <<create-agent,`create-agent`>>)
    - `:session-id`, `:get-api-key`, `:thinking-budgets`, `:max-retry-delay-ms`
* `:tools`
* `:abort-signal`.

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

---

## state

### clj

_platforms: clj_

```clojure
(state agent)
```

Returns the current agent state snapshot.

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

### cljs

_platforms: cljs_

```clojure
(state agent)
```

Returns the current agent state snapshot.

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

---

## subscribe

### clj

_platforms: clj_

```clojure
(subscribe agent)
(subscribe agent ch)
```

Subscribes a channel to the agent event stream.

* `(subscribe agent)` creates and returns a buffered channel.
* `(subscribe agent ch)` taps the provided channel and returns it.

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

### cljs

_platforms: cljs_

```clojure
(subscribe agent)
(subscribe agent ch)
```

Subscribes a channel to the agent event stream.

* `(subscribe agent)` creates and returns a buffered channel.
* `(subscribe agent ch)` taps the provided channel and returns it.

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

---

## unsubscribe

### clj

_platforms: clj_

```clojure
(unsubscribe agent ch)
```

Unsubscribes a channel from the agent event stream and closes it.

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

### cljs

_platforms: cljs_

```clojure
(unsubscribe agent ch)
```

Unsubscribes a channel from the agent event stream and closes it.

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

---

## dispatch!

### clj

_platforms: clj_

```clojure
(dispatch! agent command)
```

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

### cljs

_platforms: cljs_

```clojure
(dispatch! agent command)
```

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

---

## prompt

### clj

_platforms: clj_

```clojure
(prompt agent messages)
```

Submits a prompt command to the agent runtime.

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

### cljs

_platforms: cljs_

```clojure
(prompt agent messages)
```

Submits a prompt command to the agent runtime.

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

---

## continue

### clj

_platforms: clj_

```clojure
(continue agent)
```

Submits a continue command to the agent runtime.

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

### cljs

_platforms: cljs_

```clojure
(continue agent)
```

Submits a continue command to the agent runtime.

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

---

## abort

### clj

_platforms: clj_

```clojure
(abort agent)
```

Submits an abort command to the agent runtime.

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

### cljs

_platforms: cljs_

```clojure
(abort agent)
```

Submits an abort command to the agent runtime.

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

---

## steer

### clj

_platforms: clj_

```clojure
(steer agent messages)
```

Queues steering messages.

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

### cljs

_platforms: cljs_

```clojure
(steer agent messages)
```

Queues steering messages.

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

---

## follow-up

### clj

_platforms: clj_

```clojure
(follow-up agent messages)
```

Queues follow-up messages.

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

### cljs

_platforms: cljs_

```clojure
(follow-up agent messages)
```

Queues follow-up messages.

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

---

## wait-for-idle

### clj

_platforms: clj_

```clojure
(wait-for-idle agent)
(wait-for-idle agent max-polls)
```

Waits until the agent reaches `:ol.llx.agent.loop/idle` or `:ol.llx.agent.loop/closed`.

    Resolves `true` when idle/closed, or `false` after the polling budget is
    exhausted.

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

### cljs

_platforms: cljs_

```clojure
(wait-for-idle agent)
(wait-for-idle agent max-polls)
```

Waits until the agent reaches `:ol.llx.agent.loop/idle` or `:ol.llx.agent.loop/closed`.

    Resolves `true` when idle/closed, or `false` after the polling budget is
    exhausted.

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

---

## set-system-prompt

### clj

_platforms: clj_

```clojure
(set-system-prompt agent system-prompt)
```

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

### cljs

_platforms: cljs_

```clojure
(set-system-prompt agent system-prompt)
```

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

---

## set-model

### clj

_platforms: clj_

```clojure
(set-model agent model)
```

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

### cljs

_platforms: cljs_

```clojure
(set-model agent model)
```

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

---

## set-thinking-level

### clj

_platforms: clj_

```clojure
(set-thinking-level agent thinking-level)
```

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

### cljs

_platforms: cljs_

```clojure
(set-thinking-level agent thinking-level)
```

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

---

## set-tools

### clj

_platforms: clj_

```clojure
(set-tools agent tools)
```

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

### cljs

_platforms: cljs_

```clojure
(set-tools agent tools)
```

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

---

## set-steering-mode

### clj

_platforms: clj_

```clojure
(set-steering-mode agent mode)
```

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

### cljs

_platforms: cljs_

```clojure
(set-steering-mode agent mode)
```

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

---

## set-follow-up-mode

### clj

_platforms: clj_

```clojure
(set-follow-up-mode agent mode)
```

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

### cljs

_platforms: cljs_

```clojure
(set-follow-up-mode agent mode)
```

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

---

## replace-messages

### clj

_platforms: clj_

```clojure
(replace-messages agent messages)
```

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

### cljs

_platforms: cljs_

```clojure
(replace-messages agent messages)
```

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

---

## append-message

### clj

_platforms: clj_

```clojure
(append-message agent message)
```

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

### cljs

_platforms: cljs_

```clojure
(append-message agent message)
```

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

---

## clear-messages

### clj

_platforms: clj_

```clojure
(clear-messages agent)
```

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

### cljs

_platforms: cljs_

```clojure
(clear-messages agent)
```

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

---

## clear-steering-queue

### clj

_platforms: clj_

```clojure
(clear-steering-queue agent)
```

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

### cljs

_platforms: cljs_

```clojure
(clear-steering-queue agent)
```

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

---

## clear-follow-up-queue

### clj

_platforms: clj_

```clojure
(clear-follow-up-queue agent)
```

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

### cljs

_platforms: cljs_

```clojure
(clear-follow-up-queue agent)
```

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

---

## clear-all-queues

### clj

_platforms: clj_

```clojure
(clear-all-queues agent)
```

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

### cljs

_platforms: cljs_

```clojure
(clear-all-queues agent)
```

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

---

## reset

### clj

_platforms: clj_

```clojure
(reset agent)
```

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

### cljs

_platforms: cljs_

```clojure
(reset agent)
```

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

---

## close

### clj

_platforms: clj_

```clojure
(close agent)
```

Closes the command channel and marks state as closed.

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

### cljs

_platforms: cljs_

```clojure
(close agent)
```

Closes the command channel and marks state as closed.

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