Agent SDK · Reference

Exports.

Classes, errors, functions, constants, and types exported by the Python 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 conversation_id.
AgentAuthManaged auth: login, restore, token refresh, logout (via runner.auth).
MatildaAgentRunErrorHTTP-level failure (status, response_text).
MatildaAgentStreamErrorSSE stream error (code, errors, partial result).
MatildaClientUnderlying API client (re-exported from matilda-client).
MatildaConfigClient config dataclass (re-exported).
FilesResourceFile upload/retrieve resource (re-exported; also at runner.files).
ConversationsResourceConversation list/retrieve/update/feedback resource (re-exported).
FeedbackResourceBug-report resource, agent-stamped (report_bug; also at runner.feedback).

Errors (re-exported)

ExportDescription
MatildaErrorShared base class.
MatildaAPIErrorNon-2xx HTTP response.
QuotaExceededError429 quota error with structured attributes.
MatildaStreamErrorTerminal stream error event (code).
SafetyReplaceErrorSafety filter replacement (categories).
MatildaObjectParseErrorStructured output parse/validation failure (raw, cause).
UploadErrorFile upload failure.

Functions

ExportDescription
run(agent, prompt, **options)Run an agent turn via the shared default runner. Returns AgentRunResult.
stream(agent, prompt, **options)Stream agent events. Returns an async generator of AgentEvent.
stream_text(agent, prompt, **options)Stream text deltas. Returns an async generator of str.
run_text(agent, prompt, **options)Run and return just the text. Returns str.
stream_object(agent, prompt, schema, **options)Stream with structured output. Async generator of AgentObjectEvent.
run_object(agent, prompt, schema, **options)Run with structured output. Returns AgentObjectResult.
create_session(agent, **options)Create a Session.
build_agent_chat_request(**options)Build a chat request dict without executing. Async.
resume_agent_stream(stream_id, last_event_id=None, **options)Resume a detached durable stream. Returns AgentRunResult.
configure_default_client(client)Install the shared default MatildaClient.

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.
AGENT_SDK_NAME / AGENT_SDK_LANGUAGESDK provenance constants stamped on requests.
DSML_TOOL_CALL_OPEN / DSML_TOOL_CALL_CLOSEDSML tool-call tag constants.

Types

ExportDescription
AgentPurposeLiteral['code', 'analysis', 'general']
AgentInstructionsstr | Callable[[dict], str | Awaitable[str]]
AgentEventUnion of the 20 agent stream event dataclasses.
AgentObjectEventAgentEvent plus the terminal ObjectEvent.
AgentRunResultResult of an agent run (dataclass).
AgentObjectResult[T]AgentRunResult plus the validated object.
ToolHandler(args, ctx) -> Awaitable[ToolResult]
ToolHandlersdict[str, ToolHandler]
ToolExecutionContextContext passed to tool handlers (tool_call_id).
ToolResult{content, is_error} dataclass.
StreamErrorDetail{code, message} pair on AgentRunResult.errors.
UsageSummaryToken usage summary on AgentRunResult.
UsageEventresponse.usage event (re-exported from matilda-client).
EventCallback / ObjectEventCallbackCatch-all event callback types.
MatildaClientProtocolProtocol a Runner client's object must satisfy.
RunStarted / StreamStartedAgent lifecycle events.
ClientToolRequested / ClientToolExecuting / ClientToolResult / ClientToolRoundtripClient-tool events.
TurnRetryingRetry notice event.
OutputTextDelta / OutputTextReplace / StatusEvent / QueuedEvent / ToolCallStarted / ToolCallProgress / ToolCallCompleted / GenerationStatus / CursorEvent / Truncated / Completed / ResponseErrorChat events re-exported from matilda-client so consumers dispatch on one set of types.

Auth imports

Auth types (AuthError, StorageAdapter, TokenManager, TokenSet, MemoryStorage / memory_storage, AuthServerMetadata, login-flow functions, create_file_token_store, DEFAULT_SUCCESS_REDIRECT) live in matilda_client / matilda_client.auth / matilda_client.auth_local — import them from there. See the client SDK exports.