Agent SDK · Reference

Exports.

Classes, functions, constants, and types exported by the agent SDK package.

Classes

ExportDescription
AgentNamed persona with static or dynamic instructions.
RunnerMain execution class. Holds auth, files, conversations, feedback resources.
SessionMulti-turn conversation wrapper with auto-managed conversationId.
AgentAuthManaged auth: login, restore, token refresh, logout.
MatildaAgentRunErrorHTTP-level failure (status, responseText).
MatildaAgentStreamErrorSSE stream error (code, errors, partial result).
SafetyReplaceErrorSafety filter replacement error (categories).
MatildaObjectParseErrorStructured output parse/validation failure (raw, cause).
MatildaCoreUnderlying API client (re-exported from @matilda/api-client).
FilesResourceFile upload/retrieve resource.
ConversationsResourceConversation list/retrieve/update/feedback resource.
FeedbackResourceBug-report resource (reportBug).

Functions

ExportDescription
run(agent, input, options?)Run an agent turn via defaultRunner. Returns Promise<AgentRunResult>.
stream(agent, input, options?)Stream agent events via defaultRunner. Returns AsyncGenerator<AgentRunEvent>.
streamText(agent, input, options?)Stream text deltas via defaultRunner. Returns AsyncGenerator<string>.
runText(agent, input, options?)Run and return just the text via defaultRunner. Returns Promise<string>.
streamObject(agent, input, schema, options?)Stream with structured output via defaultRunner. Returns AsyncGenerator<AgentObjectEvent<T>>.
runObject(agent, input, schema, options?)Run with structured output via defaultRunner. Returns Promise<AgentObjectResult<T>>.
createSession(agent, options?)Create a Session.
buildAgentChatRequest(opts)Build a ChatRequest without executing.
resumeAgentStream(streamId, lastEventId, handlers, options?)Resume a detached durable stream.
configureClient(options)Configure the default MatildaCore singleton.
getClientConfig()Get the default core's config.
getDefaultCore()Get the default MatildaCore singleton.
trustApiBaseUrl(rawUrl, policy?)Validate and brand a URL as trusted.
createFileTokenStore(path)0600 JSON file token store with cross-process lock.
memoryStorage()In-memory StorageAdapter.

Constants

ExportValueDescription
DEFAULT_AGENT_PURPOSE'code'Default agent purpose.
DEFAULT_AGENT_STALL_TIMEOUT_MS45_000Default SSE stall watchdog timeout.
DEFAULT_MAX_TOOL_ROUNDTRIPS25Default maximum tool roundtrips.
DEFAULT_MAX_RETRIES0Default maximum retries.
DEFAULT_SUCCESS_REDIRECT'https://matilda.maincode.com/cli/signed-in'Default browser login success redirect.
MATILDA_API_VERSION_HEADERAPI version header name.
MATILDA_CURRENT_API_VERSIONCurrent API version string.

Instances

ExportDescription
defaultRunnerA Runner using the default MatildaCore singleton.

Types

ExportDescription
AgentPurpose'code' | 'analysis' | 'general'
AgentInstructionsstring | ((ctx: AgentRunContext) => string | Promise<string>)
AgentRunContextContext passed to dynamic instructions.
AgentOptionsConstructor options for Agent.
AgentRunOptionsOptions for runner.run() / runner.stream().
AgentRunEvent22-variant discriminated union of stream events.
AgentRunResultResult of an agent run.
AgentObjectEvent<T>AgentRunEvent plus a final { type: 'object'; object: T }.
AgentObjectResult<T>AgentRunResult plus the validated object.
AgentObjectRunOptions<T>AgentRunOptions with an embedded zod schema.
AgentCallbacksCallback hooks for run().
BuildAgentChatRequestOptionsOptions for buildAgentChatRequest().
ToolHandler(args, ctx) => Promise<ToolResult>
ToolHandlersRecord<string, ToolHandler>
ToolExecutionContextContext passed to tool handlers.
ToolResult{ content: string; isError?: boolean }
SessionOptionsOptions for Session / createSession().
FileUploadOptionsOptions for files.upload().
CoreSourceMatildaCore | (() => MatildaCore)
BrowserLoginOptionsOptions for auth.loginWithBrowser().
DeviceLoginOptionsOptions for auth.loginWithDeviceFlow().
TokenSet{ accessToken, refreshToken?, idToken?, expiresAt }
TokenManagerToken manager interface.
StorageAdapterToken persistence interface.
LoginFlowEventLogin flow state event type.
FileTokenStoreFile token store return type.
ClientConfigCore config type (re-exported).
GetTokenToken provider function type (re-exported).
TrustedApiBaseUrlBranded string type (re-exported).
TrustedApiBaseUrlPolicyURL validation policy (re-exported).
ApiMessage{ role, content } (re-exported).
ChatRequestChat request type (re-exported).
ChatResponseMode'auto' | 'instant' | 'deep' (re-exported).
ChatSseEventSSE event type (re-exported).
ChatSseEventNameSSE event name type (re-exported).
SafetyReplaceEventSafety replace event type (re-exported).
UsageEventToken usage type (re-exported).
ConversationListResponseConversation list response (re-exported).
ConversationRecordFull conversation record (re-exported).
ConversationSummaryConversation summary (re-exported).
FileAttachmentFile metadata (re-exported).
FileCompleteResponseFile upload result (re-exported).
UploadFilesOptionsMulti-file upload options (re-exported).

Error classes re-exported

ExportDescription
AuthErrorOAuth error (code, retryable). Re-exported from client SDK.