(compaction-tool-current agent)Returns the current live session compaction tool summary, if one is set.
Returns the current live session compaction tool summary, if one is set.
(compaction-tool-set! agent tool-ref)Sets the compaction tool for the current live session.
tool-ref must point to a registered tool that accepts a single context map
and returns an updated context map containing :session.
Sets the compaction tool for the current live session. `tool-ref` must point to a registered tool that accepts a single context map and returns an updated context map containing `:session`.
(project-folder-identifier)(project-folder-identifier project-dir)Builds a stable identifier for a project directory.
Builds a stable identifier for a project directory.
(prompt-send! {:keys [agent provider prompt] :as request})Sends a prompt request map through a provider.
Required request keys:
:agent
:prompt
Optional request keys:
:provider to use for this call without mutating the connected provider:model, :temperature, :top-p,
:max-tokens, :stop, :tools, :tool-choice, :response-format,
:metadata, and similar fields:compaction-tool - registered tool ref used by session-compact! during
the live session; compaction tools receive a single context map and must
return an updated context map containing :session. When set, the runtime
automatically runs compaction before a provider call if the estimated
provider request size exceeds :model-context-size * :compaction-threshold-ratio:model-context-size - positive integer context window size used by the
automatic compaction trigger; defaults to 200000:compaction-threshold-ratio - numeric ratio greater than 0 and less
than 1 used by the automatic compaction trigger; defaults to 0.9:provider-step-limit to set an explicit positive loop cap; otherwise the
provider/tool loop is unlimited:step-modifier and :session-modifier
where:
:step-modifier receives
{:agent ... :provider ... :provider-entry ... :request ... :response nil :session ... :step ...}
plus a handler function. Call (handler updated-context) to continue the
provider step and receive the resulting context with :response, for example
(fn [{:keys [request step] :as context} handler] (prn :step-request step (:prompt request)) (let [result (handler (assoc context :request (update request :prompt str "!")))] (prn :step-response step (:response result)) result)):session-modifier receives the live session context and must return the
updated context map containing :session, for example
(fn [{:keys [phase session] :as context}] (if (= phase :after-provider) (assoc context :session (update session :messages subvec 1)) context)):prompt may be:
Prompt entries may be strings, {:role ... :content ...} maps, or single-key
maps like {:system "..."} and {:user "..."}.
Returns:
:prompt is sequential: an atom containing the in-flight session map;
pass that atom to session-end! to stop after the current safe boundary and
resume later with session-continue!, session-close! to stop without
resume, or session-cancel! to interrupt as soon as possibleSends a prompt request map through a provider.
Required request keys:
- `:agent`
- `:prompt`
Optional request keys:
- `:provider` to use for this call without mutating the connected provider
- provider request options like `:model`, `:temperature`, `:top-p`,
`:max-tokens`, `:stop`, `:tools`, `:tool-choice`, `:response-format`,
`:metadata`, and similar fields
- `:compaction-tool` - registered tool ref used by `session-compact!` during
the live session; compaction tools receive a single context map and must
return an updated context map containing `:session`. When set, the runtime
automatically runs compaction before a provider call if the estimated
provider request size exceeds `:model-context-size *
:compaction-threshold-ratio`
- `:model-context-size` - positive integer context window size used by the
automatic compaction trigger; defaults to `200000`
- `:compaction-threshold-ratio` - numeric ratio greater than `0` and less
than `1` used by the automatic compaction trigger; defaults to `0.9`
- `:provider-step-limit` to set an explicit positive loop cap; otherwise the
provider/tool loop is unlimited
- `:step-modifier` and `:session-modifier`
where:
- `:step-modifier` receives
`{:agent ... :provider ... :provider-entry ... :request ... :response nil :session ... :step ...}`
plus a `handler` function. Call `(handler updated-context)` to continue the
provider step and receive the resulting context with `:response`, for example
`(fn [{:keys [request step] :as context} handler]
(prn :step-request step (:prompt request))
(let [result (handler (assoc context :request (update request :prompt str "!")))]
(prn :step-response step (:response result))
result))`
- `:session-modifier` receives the live session context and must return the
updated context map containing `:session`, for example
`(fn [{:keys [phase session] :as context}]
(if (= phase :after-provider)
(assoc context :session (update session :messages subvec 1))
context))`
- provider-level step modifiers wrap per-request step modifiers
- these hooks are middleware-like around wrappers, so one hook can observe
and change both the request and the response for a single provider step
`:prompt` may be:
- a string
- a single prompt map
- a sequential collection of prompt entries
Prompt entries may be strings, `{:role ... :content ...}` maps, or single-key
maps like `{:system "..."}` and `{:user "..."}`.
Returns:
- when `:prompt` is sequential: an atom containing the in-flight session map;
pass that atom to `session-end!` to stop after the current safe boundary and
resume later with `session-continue!`, `session-close!` to stop without
resume, or `session-cancel!` to interrupt as soon as possible
- otherwise: the final provider response(provider-connect! agent provider-ref)(provider-connect! agent provider-name provider-ref)Connects the agent to a provider.
Supported forms:
[agent provider-ref][agent provider-name provider-ref]provider-ref may be:
:invoke function and optional :name, :kind,
:endpoint, :model, :step-modifier, and
:session-modifierprovider-name overrides the inferred provider name when supplied.
Provider maps may also supply:
:step-modifier - function, var, or symbol called around each normalized
provider step with {:agent ... :provider ... :provider-entry ... :request ... :response nil :session ... :step ...} plus a handler function. Call
(handler updated-context) to continue the provider step and receive the
resulting context with :response. Example:
(fn [{:keys [request step] :as context} handler] (prn :step-request step (:prompt request)) (let [result (handler (assoc context :request (update request :prompt str "!")))] (prn :step-response step (:response result)) result)):session-modifier - function, var, or symbol called with the live session
context map and phase data, and expected to return the updated context map
containing :sessionConnects the agent to a provider.
Supported forms:
- `[agent provider-ref]`
- `[agent provider-name provider-ref]`
`provider-ref` may be:
- a provider map with an `:invoke` function and optional `:name`, `:kind`,
`:endpoint`, `:model`, `:step-modifier`, and
`:session-modifier`
- a var, function, or resolvable symbol that yields such a provider map or a
plain callable
`provider-name` overrides the inferred provider name when supplied.
Provider maps may also supply:
- `:step-modifier` - function, var, or symbol called around each normalized
provider step with `{:agent ... :provider ... :provider-entry ... :request
... :response nil :session ... :step ...}` plus a `handler` function. Call
`(handler updated-context)` to continue the provider step and receive the
resulting context with `:response`. Example:
`(fn [{:keys [request step] :as context} handler]
(prn :step-request step (:prompt request))
(let [result (handler (assoc context :request (update request :prompt str "!")))]
(prn :step-response step (:response result))
result))`
- `:session-modifier` - function, var, or symbol called with the live session
context map and phase data, and expected to return the updated context map
containing `:session`(provider-current agent)Returns the connected provider summary, if any.
Returns the connected provider summary, if any.
(provider-disconnect! agent)Disconnects the current provider and returns its summary when one was set.
Disconnects the current provider and returns its summary when one was set.
(session-cancel! session*)Requests that a queued session cancel as soon as possible.
The runner virtual thread is interrupted, remaining queued prompt entries are discarded, and the session is marked cancelled. Code currently running in a provider or tool must still cooperate with interruption to stop immediately.
Requests that a queued session cancel as soon as possible. The runner virtual thread is interrupted, remaining queued prompt entries are discarded, and the session is marked cancelled. Code currently running in a provider or tool must still cooperate with interruption to stop immediately.
(session-cancel-current! agent)Requests that the current live queued session cancel as soon as possible.
Requests that the current live queued session cancel as soon as possible.
(session-close! session*)Requests that a queued session close after the current safe boundary.
Unlike session-end!, this discards any remaining queued prompt entries and
marks the session closed, so it is not resumable through session-continue!.
Requests that a queued session close after the current safe boundary. Unlike `session-end!`, this discards any remaining queued prompt entries and marks the session closed, so it is not resumable through `session-continue!`.
(session-close-current! agent)Requests that the current live queued session close after the current safe boundary.
Requests that the current live queued session close after the current safe boundary.
(session-compact! agent)(session-compact! agent tool-ref)Runs the current live session compaction tool and applies the returned session.
Supported forms:
[agent] uses the compaction tool currently stored on the live session[agent tool-ref] runs the explicit tool and updates the live session to use
that compaction tool for later callsRuns the current live session compaction tool and applies the returned session. Supported forms: - `[agent]` uses the compaction tool currently stored on the live session - `[agent tool-ref]` runs the explicit tool and updates the live session to use that compaction tool for later calls
(session-continue! agent session-source)(session-continue! agent session-source provider-ref)Continues a previously ended or persisted queued session.
Supported forms:
[agent session-source] uses the agent's currently connected provider[agent session-source provider-ref] uses an explicit provider for the
continued runsession-source may be a persisted session path, a session map, or a
completed queued session atom.
Continues a previously ended or persisted queued session. Supported forms: - `[agent session-source]` uses the agent's currently connected provider - `[agent session-source provider-ref]` uses an explicit provider for the continued run `session-source` may be a persisted session path, a session map, or a completed queued session atom.
(session-current agent)Returns the current live session map while a prompt is running.
Returns the current live session map while a prompt is running.
(session-end! session*)Requests that a queued session stop after the current safe boundary.
session* must be the queued session atom returned by prompt-send!. The
current in-flight provider call is allowed to finish, but the remaining queued
prompt entries stay pending so the session can be continued later.
Requests that a queued session stop after the current safe boundary. `session*` must be the queued session atom returned by `prompt-send!`. The current in-flight provider call is allowed to finish, but the remaining queued prompt entries stay pending so the session can be continued later.
(session-end-current! agent)Requests that the current live queued session end after the current safe boundary.
Requests that the current live queued session end after the current safe boundary.
(session-history agent)Returns the full local message history for the current live session.
Returns the full local message history for the current live session.
(session-read path)Reads a persisted session file as a session map.
Reads a persisted session file as a session map.
(sessions-directory agent)Returns the directory where this agent stores prompt sessions.
The path is derived from the agent's :sessions-root and :project-dir.
Returns the directory where this agent stores prompt sessions. The path is derived from the agent's `:sessions-root` and `:project-dir`.
(sessions-list agent)Lists persisted session files for an agent.
Lists persisted session files for an agent.
(sessions-root-default)Returns the default root directory for stored sessions.
Returns the default root directory for stored sessions.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |