@droveragent/core
Public types and identity builders. No runtime.
The substrate every other drover package depends on. Pure types and a couple of identity builders.
Exports
import {
defineAgent,
defineTool,
// types
type AgentSpec, type AgentInput, type AgentOutput,
type ModelSpec, type ReasoningLevel, type SubagentConfig,
type SystemPromptFn,
type RunContext,
type RunResult, type RunStatus,
type HarnessEvent, type EventOfKind,
type ToolResult, type Usage,
type HarnessPlugin, type ToolDecision, type ErrorRecovery,
type HistoryMessage,
type ToolDef, type AnyToolDef, type ToolExecutionContext,
// errors
type HarnessError,
InputValidationError, OutputValidationError,
SubagentLimitError, QuotaExceededError,
CancelledError, PausedForConfirmationError,
ModelError, SandboxError, StorageError, PluginError,
} from "@droveragent/core";defineAgent
function defineAgent<I extends TSchema, O extends TSchema>(
spec: AgentSpec<I, O>
): AgentSpec<I, O>;Identity builder. Returns the spec unchanged; exists so TypeScript
infers Static<I> and Static<O> at call sites without manual
generics. See AgentSpec.
defineTool
function defineTool<S extends TSchema>(tool: ToolDef<S>): ToolDef<S>;Identity builder for ToolDef. Captures the TypeBox schema once so
execute sees a statically-typed input.
Errors
Every drover error is a Data.TaggedError from Effect, so consumers
can match by _tag:
import { OutputValidationError } from "@droveragent/core";
if (err._tag === "OutputValidationError") {
// err.attempts, err.lastIssues, err.lastText all typed
}The aggregate union is HarnessError. Use that as the Effect error
channel when composing.
RunResult
interface RunResult<TOutput = unknown> {
runId: string;
status: "success" | "quota" | "cancelled" | "error" | "paused";
output?: TOutput;
finalText: string;
turns: number;
durationMs: number;
usage: { inputTokens: number; outputTokens: number; costUsd?: number; ... };
toolCalls: readonly string[];
error?: { tag: string; message: string; status?: number }; // status: ProviderError only
}status: "paused" only when storage was wired and handle.pause() was
called. The Promise resolution NEVER rejects — typed errors fold into
error.
Tagged errors quick reference
_tag | when |
|---|---|
InputValidationError | input failed inputSchema |
OutputValidationError | output failed outputSchema after retry budget |
SubagentLimitError | depth/fan-out/allowed limit hit |
QuotaExceededError | a run budget (turns / duration / cost) was exhausted |
CancelledError | caller aborted |
PausedForConfirmationError | confirm-gate triggered (reserved for runtime) |
ModelError | model resolution failed (routing miss / circuit open) |
ProviderError | a model call failed (HTTP 4xx/5xx) or returned an empty completion; RunResult.error only, see below |
SandboxError | sandbox refused or failed an exec/read/write |
StorageError | storage adapter failure |
PluginError | plugin hook threw |
Provider failures (ProviderError)
pi-ai does not throw when a model call fails: it ends the stream with an
assistant message whose stopReason is "error". drover turns that into a
failed run instead of an empty success. The run ends status: "error" with
error.tag: "ProviderError", an error event is emitted before run_end,
and no output decode is attempted. When the provider reported an HTTP status,
it is also a number on error.status and on the error event’s status
(absent when unknown).
| final assistant message | error.message | status |
|---|---|---|
stopReason: "error" with an HTTP status (402, 401, 503, …) | provider error 402 | 402 |
stopReason: "error" with no leading status | provider error | absent |
stopReason: "length", no tool call and no non-blank text | model hit max tokens before answering | absent |
| no tool call and no non-blank text, and either zero output tokens or the run’s first assistant message | provider returned an empty completion (no content) | absent |
| none at all | provider returned no assistant message | absent |
An answer is a tool call or non-blank text; thinking alone is not. A message
with only tool calls is not an empty completion. An empty end that follows
tool work and reports output tokens stays a success (a model may finish with
an empty turn). stopReason: "aborted" is never a ProviderError: a caller
abort ends cancelled and a budget breach ends quota, as before.
The postSuccess closing turn fails the run only on stopReason: "error";
an empty closing reply does not (the output is already captured). A
subagent whose run ends ProviderError returns a tool error to its parent
carrying the same status-only message. A failed compaction summary call
(stopReason: "error") is a CompactionError event: the run continues with
its history uncompacted.
By default the message carries the status and nothing else. The provider’s
raw text can quote prompt content (for example words from a fetched page), so
it stays out of RunResult.error, the error event, the stored run row and
stored checkpoints (the checkpoint keeps the status-only form in
errorMessage). Pass includeProviderErrorText: true (HarnessDeps, or the
facade’s RunOptions / ResumeOptions) to append it:
provider error 402: 402 This request requires more credits....