pig/agent/runtime
Message-driven runtime interpreter for the pure pig agent core.
The runtime owns one run lifecycle at a time. Provider coordination and tool execution live in cancellable workers, so the actor remains available for cancellation, history, and settings messages while effects are active.
Types
Action retained with an ambiguous durable commit.
pub type PostCommitDisposition =
@internal PostCommitDisposition
Configuration owned by one runtime actor.
pub type RuntimeConfig {
RuntimeConfig(
provider: provider.Provider,
tools: tool.ToolRegistry,
hooks: List(hooks.Hooks),
dispatcher: process.Subject(dispatcher.DispatcherMessage),
model: String,
max_iterations: Int,
inference_settings: provider.InferenceSettings,
)
}
Constructors
-
RuntimeConfig( provider: provider.Provider, tools: tool.ToolRegistry, hooks: List(hooks.Hooks), dispatcher: process.Subject(dispatcher.DispatcherMessage), model: String, max_iterations: Int, inference_settings: provider.InferenceSettings, )
Messages accepted by the runtime actor.
pub type RuntimeMsg {
StartPrompt(
prompt: String,
sink: process.Subject(run.RunEvent),
terminal: process.Subject(run.RunEvent),
owner: option.Option(process.Pid),
reply_to: process.Subject(
Result(run.Run, run_error.RunStartError),
),
)
StartContinue(
sink: process.Subject(run.RunEvent),
terminal: process.Subject(run.RunEvent),
owner: option.Option(process.Pid),
reply_to: process.Subject(
Result(run.Run, run_error.RunStartError),
),
)
CancelRun(run_id: String, reason: run_error.CancelReason)
WatchClient(run_id: String, owner: process.Pid)
InferenceWorkerEvent(
run_id: String,
round: Int,
event: provider.InferenceEvent,
)
ToolWorkerFinished(
run_id: String,
round: Int,
call: message.ToolCall,
result: Result(json.Json, tool.ToolError),
duration_ms: Int,
)
SetInferenceSettings(
settings: provider.InferenceSettings,
reply_to: process.Subject(Result(Nil, run_error.RunError)),
)
GetHistory(reply_to: process.Subject(List(message.Message)))
Stop(reply_to: process.Subject(Nil))
}
Constructors
-
StartPrompt( prompt: String, sink: process.Subject(run.RunEvent), terminal: process.Subject(run.RunEvent), owner: option.Option(process.Pid), reply_to: process.Subject( Result(run.Run, run_error.RunStartError), ), ) -
StartContinue( sink: process.Subject(run.RunEvent), terminal: process.Subject(run.RunEvent), owner: option.Option(process.Pid), reply_to: process.Subject( Result(run.Run, run_error.RunStartError), ), ) -
CancelRun(run_id: String, reason: run_error.CancelReason) -
WatchClient(run_id: String, owner: process.Pid) -
InferenceWorkerEvent( run_id: String, round: Int, event: provider.InferenceEvent, ) -
ToolWorkerFinished( run_id: String, round: Int, call: message.ToolCall, result: Result(json.Json, tool.ToolError), duration_ms: Int, ) -
SetInferenceSettings( settings: provider.InferenceSettings, reply_to: process.Subject(Result(Nil, run_error.RunError)), ) -
GetHistory(reply_to: process.Subject(List(message.Message))) -
Stop(reply_to: process.Subject(Nil))
Internal state held by the runtime actor.
pub opaque type RuntimeState
Durable session state held by the runtime.
pub type SessionState {
SessionDisabled
SessionReady(
store: session_store.SessionStore,
head: option.Option(String),
)
SessionPending(
store: session_store.SessionStore,
commit: session_store.SessionCommit,
candidate: state.AgentState,
disposition: PostCommitDisposition,
)
SessionSettingsPending(
store: session_store.SessionStore,
settings: provider.InferenceSettings,
mode: SettingsPendingMode,
)
}
Constructors
-
SessionDisabled -
SessionReady( store: session_store.SessionStore, head: option.Option(String), ) -
SessionPending( store: session_store.SessionStore, commit: session_store.SessionCommit, candidate: state.AgentState, disposition: PostCommitDisposition, ) -
SessionSettingsPending( store: session_store.SessionStore, settings: provider.InferenceSettings, mode: SettingsPendingMode, )
Recovery mode for a durable settings transition.
pub type SettingsPendingMode =
@internal SettingsPendingMode
Values
pub fn collect(
run: run.Run,
sink: process.Subject(run.RunEvent),
timeout_ms: Int,
) -> Result(message.Message, run_error.RunError)
Collect a run stream into the final message. The timeout actively cancels.
pub fn history(
subject: process.Subject(RuntimeMsg),
timeout: Int,
) -> List(message.Message)
Get committed conversation history.
pub fn initial_state(
agent_state: state.AgentState,
config: RuntimeConfig,
session: SessionState,
inference_settings: provider.InferenceSettings,
) -> RuntimeState
Construct runtime state around a pre-built pure agent state.
pub fn run(
subject: process.Subject(RuntimeMsg),
prompt: String,
timeout: Int,
) -> Result(message.Message, run_error.RunError)
Collect a prompt run using the caller’s timeout.
pub fn run_continue(
subject: process.Subject(RuntimeMsg),
timeout: Int,
) -> Result(message.Message, run_error.RunError)
Collect a continuation using the caller’s timeout.
pub fn set_inference_settings(
subject: process.Subject(RuntimeMsg),
settings: provider.InferenceSettings,
timeout: Int,
) -> Result(Nil, run_error.RunError)
Set inference settings and wait for a durable commit when configured.
pub fn start(
config: RuntimeConfig,
) -> Result(process.Subject(RuntimeMsg), actor.StartError)
Start a runtime from low-level configuration.
pub fn start_with_state(
config: RuntimeConfig,
initial: RuntimeState,
) -> Result(process.Subject(RuntimeMsg), actor.StartError)
Start a runtime with replayed history and durable session state.
pub fn stop(subject: process.Subject(RuntimeMsg)) -> Nil
Stop the actor after cancelling any active work with AgentStopped.
pub fn stream(
subject: process.Subject(RuntimeMsg),
prompt: String,
sink: process.Subject(run.RunEvent),
) -> Result(run.Run, run_error.RunStartError)
Start a run and infer the watched client from the caller-owned sink.
pub fn stream_continue(
subject: process.Subject(RuntimeMsg),
sink: process.Subject(run.RunEvent),
) -> Result(run.Run, run_error.RunStartError)
Continue history and infer the watched client from the caller-owned sink.
pub fn stream_continue_owned(
subject: process.Subject(RuntimeMsg),
sink: process.Subject(run.RunEvent),
owner: process.Pid,
) -> Result(run.Run, run_error.RunStartError)
Continue history with an explicit process to watch for disconnection.
pub fn stream_owned(
subject: process.Subject(RuntimeMsg),
prompt: String,
sink: process.Subject(run.RunEvent),
owner: process.Pid,
) -> Result(run.Run, run_error.RunStartError)
Start a run with an explicit process to watch for client disconnection.
pub fn supervised(
agent_config: state.AgentConfig,
dispatcher_name: process.Name(dispatcher.DispatcherMessage),
name: process.Name(RuntimeMsg),
initial_history: List(message.Message),
session: SessionState,
) -> supervision.ChildSpecification(Nil)
Create a child specification for a named runtime actor.
pub fn supervised_with_session_store(
agent_config: state.AgentConfig,
dispatcher_name: process.Name(dispatcher.DispatcherMessage),
name: process.Name(RuntimeMsg),
store: session_store.SessionStore,
) -> supervision.ChildSpecification(Nil)
Create a durable child specification which reloads on every restart.
pub fn try_run(
subject: process.Subject(RuntimeMsg),
prompt: String,
timeout: Int,
) -> Result(Result(message.Message, run_error.RunError), Nil)
Transitional non-panicking collector. Deadline remains the outer error.
pub fn try_run_continue(
subject: process.Subject(RuntimeMsg),
timeout: Int,
) -> Result(Result(message.Message, run_error.RunError), Nil)
Transitional non-panicking continuation collector.