UseDocumentation Index
Fetch the complete documentation index at: https://docs.ai-stats.phaseo.app/llms.txt
Use this file to discover all available pages before exploring further.
@ai-stats/agent-sdk when your application needs more than one-shot text generation:
- multi-step tool loops
- local runtime tools
- resumable runs from SDK-returned state
- explicit human approval pauses
- typed final outputs
- gateway-backed model turns through the existing TypeScript SDK
State model
The Agent SDK does not persist runs into any AI Stats-hosted service.run()returns the full state needed to continue later.- If your application wants resumability across requests or process restarts, persist that returned state in your own application store.
continueRun()accepts that prior run state directly.
Install
What the SDK ships
createAgent()defineTool()createGatewayAgentClient()continueRun()for continuing from previously returned run state
First agent
Mental model
The runtime loop does four things:- sends the current message state to the model client
- executes any returned local tool calls
- appends tool results into the next turn
- returns the updated run state after each completed step boundary
Core primitives
createAgent()
Use createAgent() to define:
- one stable
id - instructions
- one model or preset
- one small tool list
- optional output parsing
- optional human review rules
- optional retry and tool-execution controls
defineTool()
Define local runtime tools with:
iddescription- optional JSON
parameters - optional
timeoutMs execute()
context.signal, marks the run as failed, and rethrows the timeout error.
createGatewayAgentClient()
Use the gateway-backed adapter when model turns should execute through AI Stats Gateway.
It can carry gateway-native controls such as:
responseFormatpluginsgatewayToolstoolChoicewebSearchOptionsproviderOptionspromptCacheKeyincludeMeta
Application-owned persistence
If your application needs resumability, persist the returnedAgentRunResult in your own database, cache, or workflow record.
The SDK intentionally does not ship persistence adapters or a hosted state backend.
That means you can:
- keep one-shot runs entirely in-process
- serialize paused or incomplete runs into your own application records
- reload that saved run state and pass it back to
continueRun()later
Human review and continuation
UsehumanReview when a run should checkpoint and wait for approval:
Typed outputs
UseparseOutput when your app wants a typed final value:
Runtime controls
Model retries
UsemodelRetry when transient model failures should retry before the run is persisted as failed:
maxRetries counts extra attempts after the first model request.
The persisted step record stores the final retry count as modelAttempts.
Concurrent local tools
If one model turn can safely call several independent tools, settoolExecution.toolConcurrency:
Preset-driven routing
Usepreset when routing, prompt, or parameter defaults should stay managed in the dashboard instead of being hard-coded in app code:
Event hooks
UseonEvent when your application wants lifecycle hooks for logs, telemetry, or internal workflows.
Current events include:
run.startedrun.resumedstep.startedstep.completedstep.failedstep.cancelledmodel.requestedmodel.completedmodel.failedtool.startedtool.completedtool.failedcheckpoint.savedrun.waiting_for_humanrun.cancelledrun.completedrun.failed
step.completed after the checkpointed step has been persisted.
Error handling
Gateway failures are rethrown asAgentGatewayError:
errorDetails.
Included examples
The package currently ships these examples:examples/research-brief-agent.tsexamples/support-triage-agent.tsexamples/coding-review-agent.tsexamples/parallel-tool-agent.ts
Current scope
The SDK is intentionally focused on application-building primitives:- local or app-owned checkpoint persistence
- gateway-backed model turns
- local tools
- resumable agent loops