# 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 schema-config opts)
```

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

### cljs

_platforms: cljs_

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

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

---

## 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#L51-L59)

### 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#L51-L59)

---

## 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`   user-owned extra Malli schemas
    - `:custom-message-schemas` user-owned custom message dispatch map
    - `: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#L89-L119)

### 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`   user-owned extra Malli schemas
    - `:custom-message-schemas` user-owned custom message dispatch map
    - `: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#L89-L119)

---

## 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`>>)
    - `: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#L121-L136)

### 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`>>)
    - `: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#L121-L136)

---

## 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#L138-L141)

### 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#L138-L141)

---

## 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#L147-L157)

### 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#L147-L157)

---

## 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#L159-L164)

### 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#L159-L164)

---

## 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#L182-L186)

### 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#L182-L186)

---

## 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#L188-L191)

### 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#L188-L191)

---

## 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#L193-L196)

### 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#L193-L196)

---

## 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#L198-L201)

### 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#L198-L201)

---

## 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#L203-L206)

### 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#L203-L206)

---

## 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#L208-L227)

### 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#L208-L227)

---

## 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#L229-L232)

### 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#L229-L232)

---

## 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#L234-L236)

### cljs

_platforms: cljs_

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

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

---

## 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#L238-L241)

### 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#L238-L241)

---

## 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#L243-L245)

### cljs

_platforms: cljs_

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

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

---

## set-schema-config

### clj

_platforms: clj_

```clojure
(set-schema-config agent schema-config-update)
```

Replaces the agent’s user-owned schema configuration.

`schema-config-update` may include `:schema-registry` and/or
`:custom-message-schemas`. `nil` for either field preserves the current
user-owned value.

This setter is accepted in any phase. It affects future validation and
future tool execution only; already queued messages and already running
tool executions keep using the registry they started with.

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

### cljs

_platforms: cljs_

```clojure
(set-schema-config agent schema-config-update)
```

Replaces the agent’s user-owned schema configuration.

`schema-config-update` may include `:schema-registry` and/or
`:custom-message-schemas`. `nil` for either field preserves the current
user-owned value.

This setter is accepted in any phase. It affects future validation and
future tool execution only; already queued messages and already running
tool executions keep using the registry they started with.

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

---

## 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#L280-L282)

### cljs

_platforms: cljs_

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

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

---

## 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#L284-L286)

### 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#L284-L286)

---

## 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#L288-L291)

### cljs

_platforms: cljs_

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

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

---

## 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#L293-L296)

### cljs

_platforms: cljs_

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

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

---

## clear-messages

### clj

_platforms: clj_

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

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

### cljs

_platforms: cljs_

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

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

---

## 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#L302-L304)

### cljs

_platforms: cljs_

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

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

---

## 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#L306-L308)

### cljs

_platforms: cljs_

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

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

---

## 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#L310-L312)

### cljs

_platforms: cljs_

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

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

---

## reset

### clj

_platforms: clj_

```clojure
(reset agent)
```

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

### cljs

_platforms: cljs_

```clojure
(reset agent)
```

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

---

## close

### clj

_platforms: clj_

```clojure
(close agent)
```

Closes the runtime.

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

### cljs

_platforms: cljs_

```clojure
(close agent)
```

Closes the runtime.

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