Abstract Class: AIAgentConnector<TBus, TConfig>
Makaio Framework / ai-adapters-core / AIAgentConnector
Abstract Class: AIAgentConnector<TBus, TConfig>
Section titled “Abstract Class: AIAgentConnector<TBus, TConfig>”Defined in: ../../../adapters/core/src/connector/agent-connector.ts:63
Abstract base class for AI agent implementations.
Each adapter provides its own message queue implementation (UserMessageQueue). This base class provides common infrastructure for state management, bus operations, and error handling.
Extended by
Section titled “Extended by”Type Parameters
Section titled “Type Parameters”TBus extends ScopedBus<string> = ScopedBus<string>
Scoped bus type for adapter namespace
TConfig
Section titled “TConfig”TConfig extends BaseAgentConnectorConfig<TBus> = BaseAgentConnectorConfig<TBus>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”
protectednew AIAgentConnector<TBus,TConfig>(config):AIAgentConnector<TBus,TConfig>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:119
Parameters
Section titled “Parameters”config
Section titled “config”BaseAgentConnectorConfig<TBus, object> & object
Returns
Section titled “Returns”AIAgentConnector<TBus, TConfig>
Properties
Section titled “Properties”adapterId
Section titled “adapterId”
readonlyadapterId:string
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:91
Adapter identifier shared across instances of the same adapter type.
adapterName
Section titled “adapterName”
protectedreadonlyadapterName:string
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:115
Adapter type name for event identification.
adapterSessionId?
Section titled “adapterSessionId?”
optionaladapterSessionId?:string
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:70
Session ID from the provider (set after connection/start).
agentId
Section titled “agentId”
protectedreadonlyagentId:string
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:68
Unique identifier for this agent instance.
config
Section titled “config”
protectedreadonlyconfig:TConfig&object
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:95
Type Declaration
Section titled “Type Declaration”adapterId
Section titled “adapterId”adapterId:
string
currentReasoningEffort
Section titled “currentReasoningEffort”currentReasoningEffort:
"none"|"low"|"medium"|"high"|"extra-high"|undefined
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:103
Current reasoning effort level, updated by changeReasoningInPlace.
cwd:
string
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:101
Working directory for agent execution
deferredInterrupt
Section titled “deferredInterrupt”
protecteddeferredInterrupt:DeferredPromise<void> |undefined
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:82
Deferred promise for interrupt coordination.
protectedreadonlyenv:Record<string,string>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:109
errorHandler?
Section titled “errorHandler?”
protectedreadonlyoptionalerrorHandler?: (error,terminate) =>void
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:80
Optional error handler callback.
Parameters
Section titled “Parameters”Error
terminate
Section titled “terminate”boolean
Returns
Section titled “Returns”void
lastResult
Section titled “lastResult”
protectedlastResult:MessageResult|null=null
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:94
model:
string
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:97
Model used for this agent (subclasses may update when SDK confirms actual model)
pendingMessageHandle?
Section titled “pendingMessageHandle?”
protectedoptionalpendingMessageHandle?:MessageHandle
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:74
Currently active message handle waiting for completion.
providerConfigId?
Section titled “providerConfigId?”
optionalproviderConfigId?:string
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:99
ProviderConfig UUID used during agent creation, carried for runtime introspection
sessionId?
Section titled “sessionId?”
protectedreadonlyoptionalsessionId?:string
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:72
Makaio session ID for cross-session correlation and approval routing.
supportedReasoningLevels
Section titled “supportedReasoningLevels”supportedReasoningLevels: {
extra-high?:string|number;high?:string|number;low?:string|number;medium?:string|number;none?:string|number; } |undefined
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:108
Reasoning levels supported by the current model, forwarded from the config factory.
undefined when the model does not declare reasoning support.
systemPrompt?
Section titled “systemPrompt?”
protectedoptionalsystemPrompt?:string| {content:string;mode:"append"; }
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:117
Runtime system prompt from start/initialize options.
timeouts
Section titled “timeouts”
protectedreadonlytimeouts:TrackedTimeoutConfig
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:93
Resolved timeout configuration with provenance tracking.
Accessors
Section titled “Accessors”currentTurnNumber
Section titled “currentTurnNumber”Get Signature
Section titled “Get Signature”get
protectedcurrentTurnNumber():number
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:344
Current turn number (read-only). Use consumeTurnNumber to advance.
Returns
Section titled “Returns”number
The current turn number
pendingTurnNumber
Section titled “pendingTurnNumber”Get Signature
Section titled “Get Signature”get
protectedpendingTurnNumber():number|undefined
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:352
Staged canonical turn number, or undefined if none was staged.
Returns
Section titled “Returns”number | undefined
The pending canonical turn number
Methods
Section titled “Methods”abort()
Section titled “abort()”
abstractabort():void
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:246
Abort the agent and cleanup resources (panic mode). Triggers AbortController which may cause provider errors. Use close() for graceful shutdown instead.
Returns
Section titled “Returns”void
captureSystemPrompt()
Section titled “captureSystemPrompt()”
protectedcaptureSystemPrompt(prompt):void
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:167
Store runtime system prompt for session creation. Subclasses may override to apply SDK-specific side effects (e.g., Gemini’s setSystemInstruction).
Parameters
Section titled “Parameters”prompt
Section titled “prompt”string | { content: string; mode: "append"; } | undefined
System prompt from start/initialize options
Returns
Section titled “Returns”void
changeCwdInPlace()
Section titled “changeCwdInPlace()”changeCwdInPlace(
_newCwd):Promise<boolean>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:385
Attempt to change the working directory without a connector swap. Subclasses override when the adapter supports in-place cwd changes (e.g., stateless APIs). Base implementation returns false (swap required).
Mutation contract: Implementations MUST NOT mutate this.cwd directly.
The caller (AIAgent.handleCwdChange) owns the this.cwd field update after
a successful in-place change. Implementations only update SDK-internal state.
Parameters
Section titled “Parameters”_newCwd
Section titled “_newCwd”string
The working directory path to switch to
Returns
Section titled “Returns”Promise<boolean>
true if changed in-place, false if swap needed. Exceptions are caught by the caller and treated as false (automatic swap fallback), so implementations need not guard.
changeModelInPlace()
Section titled “changeModelInPlace()”changeModelInPlace(
_newModel):Promise<boolean>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:369
Attempt to change the model without a connector swap. Subclasses override when the SDK supports in-place model changes. Base implementation returns false (swap required).
Mutation contract: Implementations MUST NOT mutate this.model directly.
The caller (AIAgent.handleModelChange) owns the this.model field update after
a successful in-place change. Implementations only configure the SDK-internal model
(e.g., query.setModel(), geminiConfig.setModel()).
Parameters
Section titled “Parameters”_newModel
Section titled “_newModel”string
The model identifier to switch to
Returns
Section titled “Returns”Promise<boolean>
true if changed in-place, false if swap needed. Exceptions are caught by the caller and treated as false (automatic swap fallback), so implementations need not guard.
changeReasoningInPlace()
Section titled “changeReasoningInPlace()”changeReasoningInPlace(
_newLevel):Promise<boolean>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:402
Attempt to change reasoning effort without swapping the connector.
Override in subclasses that support in-place reasoning changes (e.g., adapters
that pass reasoning parameters per-request rather than at session-creation time).
The base implementation returns false so callers fall back to a connector swap.
Mutation contract: Implementations MUST NOT mutate this.currentReasoningEffort
directly. The caller owns the currentReasoningEffort field update after a successful
in-place change. Implementations only configure the SDK-internal reasoning parameter.
Parameters
Section titled “Parameters”_newLevel
Section titled “_newLevel”"none" | "low" | "medium" | "high" | "extra-high"
The new reasoning effort level to apply
Returns
Section titled “Returns”Promise<boolean>
true if the change was applied in-place, false if a connector swap is needed
close()
Section titled “close()”
abstractclose():Promise<void>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:253
Gracefully close the agent session. Unlike abort(), this doesn’t trigger AbortController errors. Use this for normal shutdown; use abort() for emergency termination.
Returns
Section titled “Returns”Promise<void>
complete()
Section titled “complete()”
abstractcomplete():Promise<MessageResult|null>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:265
Complete the agent session by waiting for all messages to finish.
Returns
Section titled “Returns”Promise<MessageResult | null>
Last message result or null if no messages processed
consumeTurnNumber()
Section titled “consumeTurnNumber()”
protectedconsumeTurnNumber():number
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:330
Advance to the next turn number, consuming any pending canonical value. Orchestrator-staged values win; otherwise the local counter increments by one.
Returns
Section titled “Returns”number
The current turn number after advancement
createMessageHandle()
Section titled “createMessageHandle()”
protectedcreateMessageHandle(message,options?):MessageHandle
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:279
Create a MessageHandle with standard initialization.
Centralizes the pattern used by all connectors:
- Generate messageId (use provided or generate UUID)
- Create MessageHandle instance
- Set adapterSessionId
- Call onMessageSent callback
Parameters
Section titled “Parameters”message
Section titled “message”Normalized user message
options?
Section titled “options?”MessageHandleOptions
Optional message options (id, delivery mode, history, and turn context)
Returns
Section titled “Returns”Initialized MessageHandle ready for enqueueing
emit()
Section titled “emit()”
protectedemit<TSubject>(subject,payload):Promise<void>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:527
Emit an event via the scoped bus with auto-injected metadata.
Wraps scopedBus.emit() to automatically include connector identity
(adapterName, agentId, adapterId, adapterSessionId) in the payload.
Type Parameters
Section titled “Type Parameters”TSubject
Section titled “TSubject”TSubject extends ScopedSubjectDefinition<TBus["namespace"]>
Parameters
Section titled “Parameters”subject
Section titled “subject”TSubject
Subject definition for the event
payload
Section titled “payload”Forbid<TSubject["$meta"]["payload"], ForbiddenKeys>
Event payload (metadata fields are forbidden and auto-injected)
Returns
Section titled “Returns”Promise<void>
Promise that resolves when the event is emitted
getAdapterName()
Section titled “getAdapterName()”getAdapterName():
string
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:456
Returns
Section titled “Returns”string
getAdapterSessionId()
Section titled “getAdapterSessionId()”
abstractgetAdapterSessionId():Promise<string>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:259
Get session ID, waiting for provider to generate it if not yet available.
Returns
Section titled “Returns”Promise<string>
Session ID from provider
getAgentId()
Section titled “getAgentId()”getAgentId():
string
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:452
Returns
Section titled “Returns”string
getProcessingState()
Section titled “getProcessingState()”getProcessingState():
ProcessingState
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:149
Get the current processing state of the agent.
Returns
Section titled “Returns”The current processing state
getTimeoutMs()
Section titled “getTimeoutMs()”getTimeoutMs(
category):number
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:465
Get timeout value for a specific category.
Parameters
Section titled “Parameters”category
Section titled “category”Timeout category (initialization, acknowledgement, completion, toolApproval, eventWait)
Returns
Section titled “Returns”number
Timeout value in milliseconds
handleError()
Section titled “handleError()”handleError(
error,terminate?):void
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:418
Internal
Marks pending message as failed, calls error handler, resolves completion promise.
Parameters
Section titled “Parameters”unknown
Error that occurred
terminate?
Section titled “terminate?”boolean = false
Whether to abort the agent after handling error
Returns
Section titled “Returns”void
handlePause()
Section titled “handlePause()”
protectedhandlePause(_reason):void
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:158
Handle pause after rejection or error. Subclasses should clear pending messages as appropriate.
Parameters
Section titled “Parameters”_reason
Section titled “_reason”"error" | "rejection"
Reason for pause (‘rejection’ | ‘error’); available for subclass overrides
Returns
Section titled “Returns”void
handleToolApprovalDenied()
Section titled “handleToolApprovalDenied()”
protectedhandleToolApprovalDenied(abort,details?):void
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:444
Parameters
Section titled “Parameters”"handled" | "not_requested" | "not_supported"
details?
Section titled “details?”string
Returns
Section titled “Returns”void
initialize()
Section titled “initialize()”
abstractinitialize(options?):Promise<void>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:219
Initialize the connector’s SDK session without sending a message. Must set adapterSessionId before returning. Called by createAgent for idle agent setup. Implementations MUST be idempotent (no-op if already initialized).
Parameters
Section titled “Parameters”options?
Section titled “options?”Optional start options (e.g., systemPrompt for Claude)
Returns
Section titled “Returns”Promise<void>
interrupt()
Section titled “interrupt()”
abstractinterrupt():Promise<void>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:410
Interrupt the current message processing.
Returns
Section titled “Returns”Promise<void>
Promise that resolves when interrupt is handled
logLowLevelEvent()
Section titled “logLowLevelEvent()”
protectedlogLowLevelEvent(_event):void
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:572
Parameters
Section titled “Parameters”_event
Section titled “_event”unknown
Returns
Section titled “Returns”void
markToolRefreshPending()
Section titled “markToolRefreshPending()”markToolRefreshPending():
void
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:302
Signal that MCP tools have changed and should be refreshed at the next turn boundary.
Called by the AIAgent layer when receiving MCP bus events (mcp.tools.updated,
mcp.tools.enabled). Connectors that support direct-inject tool refresh (e.g.,
BaseStreamConnector) override this to set an internal pending-refresh flag.
The default implementation is a no-op so connectors that do not manage MCP tools
directly are unaffected.
Returns
Section titled “Returns”void
on<
Subject>(subject,handler,options?): () =>void
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:549
Subscribe to events on the filtered bus (pre-filtered by agentId).
Uses filteredBus which only delivers events matching this connector’s agentId.
Type Parameters
Section titled “Type Parameters”Subject
Section titled “Subject”Subject extends ScopedSubjectDefinition<TBus["namespace"]>
Parameters
Section titled “Parameters”subject
Section titled “subject”Subject
Subject definition to subscribe to
handler
Section titled “handler”HandlerForSubjectDefinition<Subject>
Event handler receiving the event context
options?
Section titled “options?”Optional subscription options (e.g., priority)
Returns
Section titled “Returns”Unsubscribe function
() => void
once()
Section titled “once()”once<
Subject>(subject,options?):Promise<never>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:565
Wait for a single event on the filtered bus (pre-filtered by agentId).
Uses filteredBus which only delivers events matching this connector’s agentId.
Type Parameters
Section titled “Type Parameters”Subject
Section titled “Subject”Subject extends ScopedSubjectDefinition<TBus["namespace"]>
Parameters
Section titled “Parameters”subject
Section titled “subject”Subject
Subject definition to wait for
options?
Section titled “options?”OnceOptions<ScopedSubjectDefinition<TBus["namespace"]>>
Optional options (e.g., predicate filter, timeout)
Returns
Section titled “Returns”Promise<never>
Promise resolving to the event context
onceProcessingStateChanged()
Section titled “onceProcessingStateChanged()”onceProcessingStateChanged(
predicate?):Promise<ProcessingState>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:206
Wait for a single processing state change matching an optional predicate.
Parameters
Section titled “Parameters”predicate?
Section titled “predicate?”(eventData) => boolean
Optional filter, e.g., (e) => !e.isProcessing for idle
Returns
Section titled “Returns”Promise<ProcessingState>
Promise resolving to { isProcessing: boolean }
onProcessingStateChanged()
Section titled “onProcessingStateChanged()”onProcessingStateChanged(
handler):UnsubscribeFunction
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:195
Subscribe to processing state changes (idle ↔ processing transitions).
Parameters
Section titled “Parameters”handler
Section titled “handler”(payload) => void | Promise<void>
Called with { isProcessing: boolean } on each state change
Returns
Section titled “Returns”UnsubscribeFunction
Unsubscribe function
requestToolApproval()
Section titled “requestToolApproval()”
protectedrequestToolApproval<TSubject>(subject,payload):Promise<TSubject["$meta"]["payload"]["response"]>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:478
Request tool approval via the scoped bus with auto-injected metadata.
Wraps scopedBus.request() to automatically include connector identity
(adapterName, agentId, adapterId, adapterSessionId) in the payload.
Type Parameters
Section titled “Type Parameters”TSubject
Section titled “TSubject”TSubject extends ScopedSubjectDefinition<TBus["namespace"]>
Parameters
Section titled “Parameters”subject
Section titled “subject”TSubject
Subject definition for the tool approval request
payload
Section titled “payload”Forbid<TSubject["$meta"]["payload"]["request"], ForbiddenKeys>
Request payload (metadata fields are forbidden and auto-injected)
Returns
Section titled “Returns”Promise<TSubject["$meta"]["payload"]["response"]>
Promise resolving to the approval response
requestToolApprovalWithHandling()
Section titled “requestToolApprovalWithHandling()”
protectedrequestToolApprovalWithHandling<TSubject>(subject,payload):Promise<TSubject["$meta"]["payload"]["response"]>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:502
Execute a tool approval request with the shared diagnostics wrapper.
Handles the common RequestError/NoHandlerError path by logging a helpful
message via handleError and re-throwing so callers can decide whether to
surface the failure or fall back to a denial.
Type Parameters
Section titled “Type Parameters”TSubject
Section titled “TSubject”TSubject extends ScopedSubjectDefinition<TBus["namespace"]>
Parameters
Section titled “Parameters”subject
Section titled “subject”TSubject
Scoped subject definition for the tool approval request
payload
Section titled “payload”Forbid<TSubject["$meta"]["payload"]["request"], ForbiddenKeys>
Payload that must not include adapter metadata
Returns
Section titled “Returns”Promise<TSubject["$meta"]["payload"]["response"]>
Tool approval response payload
sendMessage()
Section titled “sendMessage()”
abstractsendMessage(message,options?):Promise<MessageHandle>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:236
Send a message to the agent. For initial message, use start() instead.
Parameters
Section titled “Parameters”message
Section titled “message”Normalized message content
options?
Section titled “options?”Send options (e.g., delivery mode, message ID)
Returns
Section titled “Returns”Promise<MessageHandle>
Message handle for tracking
setCanonicalTurnNumber()
Section titled “setCanonicalTurnNumber()”setCanonicalTurnNumber(
turnNumber):void
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:312
Stage the canonical orchestrator-assigned turn number for consumption by the next consumeTurnNumber call. The counter is monotonically increasing.
Parameters
Section titled “Parameters”turnNumber
Section titled “turnNumber”number
Canonical 1-based turn number from SessionOrchestrator
Returns
Section titled “Returns”void
Throws
Section titled “Throws”RangeError when the value is invalid, regresses, or downgrades a staged value
start()
Section titled “start()”
abstractstart(message,options?):Promise<AgentStartResult>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:227
Start agent with initial message.
Parameters
Section titled “Parameters”message
Section titled “message”Normalized user message (role and content)
options?
Section titled “options?”Optional start options (e.g., delivery mode)
Returns
Section titled “Returns”Promise<AgentStartResult>
Session ID, agent ID, and message handle for tracking
updateProcessingState()
Section titled “updateProcessingState()”
protectedupdateProcessingState(state):Promise<void>
Defined in: ../../../adapters/core/src/connector/agent-connector.ts:177
Update the agent’s processing state. State transitions trigger events via emittery.
Parameters
Section titled “Parameters”New processing state
Returns
Section titled “Returns”Promise<void>