Skip to content

AgentSession

A session: one agent process working in one directory, from Agent.open. It stays open until its Scope closes. Its calls fail with SessionError.

Since v0.3.0

Lost the connection to the process running the session (a DetachedAgent host) and could not get it back. The session itself may still be running: AgentHosts.attach it again.

Signature

declare class ConnectionLost

Source

Since v0.2.0

The session can’t take this call: it has ended (end, its Scope closed, or the agent process died, which message then says) or, for a detached session, this handle was detached.

Signature

declare class SessionClosed

Source

Since v0.2.0

How an AgentSession call can fail, besides a turn’s own TurnFailure.

Signature

declare const SessionError: Schema.Union<
readonly [typeof AgentError, typeof SessionClosed, typeof ConnectionLost]
>

Source

Since v0.2.0

Signature

type SessionError = typeof SessionError.Type

Source

Since v0.2.0

Resuming a session that the provider has no record of.

Signature

declare class SessionNotFound

Source

Since v0.1.0

An open session, from Agent.open. Calls fail with SessionClosed once the session has ended, with ConnectionLost when a detached session’s host can’t be reached, and with AgentError for anything else.

Signature

export interface AgentSession {
readonly sessionId: SessionId
readonly provider: string
/** Where the provider stores this session (a transcript file), when known. */
readonly location: Option.Option<string>
/** The agent process's pid (the wrapped command's, if a `Launcher` wraps it). */
readonly pid: Effect.Effect<Option.Option<number>>
/**
* Subscribe now; the returned stream holds every event from this point on,
* starting with the session's `SessionStarted` once it is known. Use this
* (then fork the stream) when you must not miss events after a `send`.
*/
readonly subscribe: Effect.Effect<
Stream.Stream<AgentEvent, SessionError>,
never,
Scope.Scope
>
/**
* `subscribe`, deferred until the stream runs. Events sent before it runs are missed.
*/
readonly events: Stream.Stream<AgentEvent, SessionError>
/** Start a turn now if idle, otherwise after the running turn. */
readonly send: (input: Input) => Effect.Effect<MessageId, SessionError>
/** `send`, then wait for that message's turn to end. */
readonly turn: (
input: Input,
) => Effect.Effect<TurnSucceeded, TurnFailure | SessionError>
/**
* Deliver into the running turn at its next tool boundary; starts a new turn if none
* is running.
*/
readonly steer: (input: Input) => Effect.Effect<SteerOutcome, SessionError>
/** Stop the running turn (it ends `Interrupted`); the session stays usable. */
readonly interrupt: Effect.Effect<void, SessionError>
/**
* No more input: let queued work finish, then end the session. On a
* session that already ended, succeeds if it ended cleanly and fails with
* what ended it otherwise.
*/
readonly end: Effect.Effect<void, SessionError>
}

Source

Since v0.1.0

The provider’s id for a session, used to resume it.

Signature

declare const SessionId: Schema.brand<Schema.String, "effect-agent/SessionId">

Source

Since v0.1.0

Signature

type SessionId = typeof SessionId.Type

Source

Since v0.1.0