@mozaik-ai/core 4.2.0-beta.1 → 4.2.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +340 -1
- package/dist/index.d.ts +340 -1
- package/dist/index.js +2220 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2209 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -59,6 +59,7 @@ interface FunctionTool {
|
|
|
59
59
|
strict: boolean;
|
|
60
60
|
invoke: (args: any) => Promise<any> | any;
|
|
61
61
|
}
|
|
62
|
+
type Tool = FunctionTool;
|
|
62
63
|
|
|
63
64
|
type SpaceRecord = {
|
|
64
65
|
id: string;
|
|
@@ -102,4 +103,342 @@ declare function defineRuntime<TSharedState extends SharedState>(): {
|
|
|
102
103
|
sendMessageTool: FunctionTool;
|
|
103
104
|
};
|
|
104
105
|
|
|
105
|
-
|
|
106
|
+
interface ItemContent {
|
|
107
|
+
readonly type: string;
|
|
108
|
+
}
|
|
109
|
+
interface InputText extends ItemContent {
|
|
110
|
+
readonly type: "input_text";
|
|
111
|
+
readonly text: string;
|
|
112
|
+
}
|
|
113
|
+
interface SummaryText {
|
|
114
|
+
readonly type: "summary_text";
|
|
115
|
+
readonly text: string;
|
|
116
|
+
}
|
|
117
|
+
interface ReasoningItem {
|
|
118
|
+
readonly type: "reasoning";
|
|
119
|
+
readonly content?: InputText;
|
|
120
|
+
readonly encryptedContent?: string;
|
|
121
|
+
readonly summary: SummaryText[];
|
|
122
|
+
}
|
|
123
|
+
interface MessageItem {
|
|
124
|
+
readonly type: "user_message" | "system_message" | "developer_message" | "model_message";
|
|
125
|
+
readonly text: string;
|
|
126
|
+
}
|
|
127
|
+
interface ModelMessageItem extends MessageItem {
|
|
128
|
+
readonly type: "model_message";
|
|
129
|
+
readonly text: string;
|
|
130
|
+
}
|
|
131
|
+
interface ToolUseRequest {
|
|
132
|
+
readonly type: "tool_use_request";
|
|
133
|
+
readonly requestId: string;
|
|
134
|
+
readonly toolName: string;
|
|
135
|
+
readonly toolArguments: string;
|
|
136
|
+
}
|
|
137
|
+
interface ToolUseResult {
|
|
138
|
+
readonly type: "tool_use_result";
|
|
139
|
+
readonly requestId: string;
|
|
140
|
+
readonly result: InputText;
|
|
141
|
+
}
|
|
142
|
+
type ContextItem = MessageItem | ReasoningItem | ToolUseRequest | ToolUseResult;
|
|
143
|
+
type ModelOutputItem = ModelMessageItem | ToolUseRequest | ReasoningItem;
|
|
144
|
+
type Context = {
|
|
145
|
+
readonly items: ContextItem[];
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
interface InferenceEndpointMapper {
|
|
149
|
+
toRequest(inferenceRequest: InferenceRequest): any;
|
|
150
|
+
toResponse(response: any): InferenceResult;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
interface Endpoint {
|
|
154
|
+
endpointMapper: InferenceEndpointMapper;
|
|
155
|
+
infer(requestParams: InferenceRequest): Promise<InferenceResult>;
|
|
156
|
+
stream(requestParams: InferenceRequest): AsyncIterable<SpaceEvent>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
type GenerativeModel = {
|
|
160
|
+
endpoint: Endpoint;
|
|
161
|
+
specification: ModelSpecification;
|
|
162
|
+
};
|
|
163
|
+
type ModelSpecification = {
|
|
164
|
+
name: string;
|
|
165
|
+
provider: string;
|
|
166
|
+
supportsReasoningEffort: boolean;
|
|
167
|
+
supportedReasoningEfforts: string[];
|
|
168
|
+
supportsStreaming: boolean;
|
|
169
|
+
contextWindowSize: number;
|
|
170
|
+
supportedContextItemTypes: string[];
|
|
171
|
+
maxOutputTokens: number;
|
|
172
|
+
supportsFunctionCalling: boolean;
|
|
173
|
+
supportsStructuredOutput: boolean;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
type StructuredOutputFormat = {
|
|
177
|
+
name?: string;
|
|
178
|
+
schema: Record<string, any>;
|
|
179
|
+
strict?: boolean;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
declare class InputTokenDetails {
|
|
183
|
+
readonly cached_tokens: number;
|
|
184
|
+
constructor(cached_tokens: number);
|
|
185
|
+
}
|
|
186
|
+
declare class OutputTokenDetails {
|
|
187
|
+
readonly reasoning_tokens: number;
|
|
188
|
+
constructor(reasoning_tokens: number);
|
|
189
|
+
}
|
|
190
|
+
declare class TokenUsage {
|
|
191
|
+
readonly inputTokens: number;
|
|
192
|
+
readonly outputTokens: number;
|
|
193
|
+
readonly totalTokens: number;
|
|
194
|
+
readonly inputTokenDetails: InputTokenDetails;
|
|
195
|
+
readonly outputTokenDetails: OutputTokenDetails;
|
|
196
|
+
constructor(inputTokens: number, outputTokens: number, totalTokens: number, inputTokenDetails: InputTokenDetails, outputTokenDetails: OutputTokenDetails);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
type InferenceRequest = {
|
|
200
|
+
model: string;
|
|
201
|
+
maxOutputTokens?: number;
|
|
202
|
+
reasoningEffort?: string;
|
|
203
|
+
tools?: Tool[];
|
|
204
|
+
streaming?: boolean;
|
|
205
|
+
structuredOutput?: StructuredOutputFormat;
|
|
206
|
+
context: Context;
|
|
207
|
+
};
|
|
208
|
+
type InferenceResult = {
|
|
209
|
+
items: ModelOutputItem[];
|
|
210
|
+
tokenUsage: TokenUsage | undefined;
|
|
211
|
+
rowResponse: any;
|
|
212
|
+
};
|
|
213
|
+
interface InferenceRunner {
|
|
214
|
+
run(request: InferenceRequest): Promise<InferenceResult>;
|
|
215
|
+
stream(request: InferenceRequest): AsyncGenerator<SpaceEvent>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
interface Memory {
|
|
219
|
+
getContext(): Context;
|
|
220
|
+
saveItem(item: ContextItem): void;
|
|
221
|
+
saveItems(items: ContextItem[]): void;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
type AgentRecord = {
|
|
225
|
+
id: string;
|
|
226
|
+
manifest: ParticipantManifest;
|
|
227
|
+
tools: Tool[];
|
|
228
|
+
memory: Memory;
|
|
229
|
+
handlers: SituationHandler[];
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
declare class Agent extends Participant {
|
|
233
|
+
private memory;
|
|
234
|
+
private tools;
|
|
235
|
+
constructor(manifest: ParticipantManifest, tools: Tool[], memory: Memory, handlers: SituationHandler[]);
|
|
236
|
+
getTools(): Tool[];
|
|
237
|
+
getMemory(): Memory;
|
|
238
|
+
static create({ manifest, tools, memory, handlers, }: {
|
|
239
|
+
manifest: ParticipantManifest;
|
|
240
|
+
tools: Tool[];
|
|
241
|
+
memory: Memory;
|
|
242
|
+
handlers: SituationHandler[];
|
|
243
|
+
}): Agent;
|
|
244
|
+
static rehydrate(record: AgentRecord): Agent;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
interface AgentRepository {
|
|
248
|
+
save(agent: Agent): Promise<void>;
|
|
249
|
+
exists(id: string): Promise<boolean>;
|
|
250
|
+
findById(id: string): Promise<Agent | undefined>;
|
|
251
|
+
findAll(): Promise<Agent[]>;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
type CompletedOperation = {
|
|
255
|
+
type: "inference";
|
|
256
|
+
operationId: string;
|
|
257
|
+
requestedAt: Date;
|
|
258
|
+
completedAt: Date;
|
|
259
|
+
request: InferenceRequest;
|
|
260
|
+
result: InferenceResult;
|
|
261
|
+
} | {
|
|
262
|
+
type: "tool_use";
|
|
263
|
+
operationId: string;
|
|
264
|
+
requestedAt: Date;
|
|
265
|
+
completedAt: Date;
|
|
266
|
+
call: ToolUseRequest;
|
|
267
|
+
result: ToolUseResult;
|
|
268
|
+
};
|
|
269
|
+
type PendingInference = {
|
|
270
|
+
id: string;
|
|
271
|
+
type: "inference";
|
|
272
|
+
requestedAt: Date;
|
|
273
|
+
request: InferenceRequest;
|
|
274
|
+
};
|
|
275
|
+
type PendingToolExecution = {
|
|
276
|
+
id: string;
|
|
277
|
+
type: "tool_execution";
|
|
278
|
+
requestedAt: Date;
|
|
279
|
+
call: ToolUseRequest;
|
|
280
|
+
};
|
|
281
|
+
type PendingOperation = PendingInference | PendingToolExecution;
|
|
282
|
+
|
|
283
|
+
interface LoopTransition {
|
|
284
|
+
readonly occurredAt: Date;
|
|
285
|
+
readonly previousState: LoopStateId;
|
|
286
|
+
readonly nextState: LoopStateId;
|
|
287
|
+
readonly reason: string;
|
|
288
|
+
readonly operationId?: string;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
type AgentLoop = {
|
|
292
|
+
readonly agent: Agent;
|
|
293
|
+
readonly loop: Loop;
|
|
294
|
+
};
|
|
295
|
+
declare abstract class LoopSpecification {
|
|
296
|
+
abstract isSatisfiedBy(agentLoop: AgentLoop): boolean;
|
|
297
|
+
and(other: LoopSpecification): LoopSpecification;
|
|
298
|
+
or(other: LoopSpecification): LoopSpecification;
|
|
299
|
+
not(): LoopSpecification;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
type LoopControlDirective = InferenceDirective | ToolUseDirective | WaitDirective | CompleteDirective;
|
|
303
|
+
type InferenceDirective = {
|
|
304
|
+
type: "inference";
|
|
305
|
+
request: InferenceRequest;
|
|
306
|
+
};
|
|
307
|
+
type ToolUseDirective = {
|
|
308
|
+
type: "tool_use";
|
|
309
|
+
call: ToolUseRequest;
|
|
310
|
+
};
|
|
311
|
+
type WaitDirective = {
|
|
312
|
+
type: "wait";
|
|
313
|
+
reason: string;
|
|
314
|
+
};
|
|
315
|
+
type CompleteDirective = {
|
|
316
|
+
type: "complete";
|
|
317
|
+
reason: string;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
declare abstract class LoopAction {
|
|
321
|
+
abstract execute(agentLoop: AgentLoop): LoopControlDirective;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
type CreateLoopRuleParams = {
|
|
325
|
+
readonly priority?: number;
|
|
326
|
+
readonly when: LoopSpecification;
|
|
327
|
+
readonly then: LoopAction;
|
|
328
|
+
};
|
|
329
|
+
type LoopRuleRecord = {
|
|
330
|
+
readonly id: string;
|
|
331
|
+
readonly priority: number;
|
|
332
|
+
readonly condition: LoopSpecification;
|
|
333
|
+
readonly action: LoopAction;
|
|
334
|
+
};
|
|
335
|
+
declare class LoopRule {
|
|
336
|
+
_id: string;
|
|
337
|
+
_priority: number;
|
|
338
|
+
_condition: LoopSpecification;
|
|
339
|
+
_action: LoopAction;
|
|
340
|
+
constructor(id: string, condition: LoopSpecification, action: LoopAction, priority: number);
|
|
341
|
+
get id(): string;
|
|
342
|
+
get priority(): number;
|
|
343
|
+
get condition(): LoopSpecification;
|
|
344
|
+
get action(): LoopAction;
|
|
345
|
+
static create(spec: CreateLoopRuleParams): LoopRule;
|
|
346
|
+
static rehydrate(spec: LoopRuleRecord): LoopRule;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
interface LoopRecord {
|
|
350
|
+
id: string;
|
|
351
|
+
agentId: string;
|
|
352
|
+
subject: string;
|
|
353
|
+
createdAt: Date;
|
|
354
|
+
state: LoopStateId;
|
|
355
|
+
inferenceRequest?: InferenceRequest;
|
|
356
|
+
pendingOperation?: PendingOperation;
|
|
357
|
+
transitionHistory: LoopTransition[];
|
|
358
|
+
operationHistory: CompletedOperation[];
|
|
359
|
+
rules: LoopRule[];
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
type LoopStateId = "idle" | "awaiting_inference_request" | "awaiting_inference" | "awaiting_tool_output" | "stopped" | "completed";
|
|
363
|
+
declare class Loop {
|
|
364
|
+
private readonly loopId;
|
|
365
|
+
private readonly agentId;
|
|
366
|
+
private readonly subject;
|
|
367
|
+
private readonly createdAt;
|
|
368
|
+
private state;
|
|
369
|
+
private pendingOperation;
|
|
370
|
+
private readonly transitionHistory;
|
|
371
|
+
private inferenceRequest;
|
|
372
|
+
private readonly operationHistory;
|
|
373
|
+
private readonly loopRules;
|
|
374
|
+
private constructor();
|
|
375
|
+
get id(): string;
|
|
376
|
+
get stateId(): LoopStateId;
|
|
377
|
+
get pending(): PendingOperation | undefined;
|
|
378
|
+
get history(): readonly LoopTransition[];
|
|
379
|
+
get completedOperations(): readonly CompletedOperation[];
|
|
380
|
+
get request(): InferenceRequest | undefined;
|
|
381
|
+
get rules(): readonly LoopRule[];
|
|
382
|
+
getAgentId(): string;
|
|
383
|
+
record(): LoopRecord;
|
|
384
|
+
moveToIdle(reason: string, transitionId: string): void;
|
|
385
|
+
moveToAwaitingInference(operation: PendingInference): void;
|
|
386
|
+
moveToAwaitingToolOutput(operation: Extract<PendingOperation, {
|
|
387
|
+
type: "tool_execution";
|
|
388
|
+
}>, occurredAt: Date): void;
|
|
389
|
+
requestInference(request: InferenceRequest): PendingInference;
|
|
390
|
+
requestToolUse(operationId: string, call: ToolUseRequest, requestedAt: Date): PendingToolExecution;
|
|
391
|
+
private transitionTo;
|
|
392
|
+
private assertIdle;
|
|
393
|
+
private assertAwaitingInferenceRequest;
|
|
394
|
+
receiveInferenceResult(operationId: string, result: InferenceResult): void;
|
|
395
|
+
receiveToolUseResult(operationId: string, result: ToolUseResult): void;
|
|
396
|
+
complete(reason: string): void;
|
|
397
|
+
stop(reason: string): void;
|
|
398
|
+
wait(reason: string): void;
|
|
399
|
+
private assertNotSettled;
|
|
400
|
+
static create(id: string, agentId: string, subject: string, rules: LoopRule[]): Loop;
|
|
401
|
+
static rehydrate(record: LoopRecord): Loop;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
interface LoopRepository {
|
|
405
|
+
save(loop: Loop): Promise<void>;
|
|
406
|
+
findById(id: string): Promise<Loop | undefined>;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
interface ToolUseRunner {
|
|
410
|
+
run(request: ToolUseRequest, tool: Tool): Promise<ToolUseResult>;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
type InferenceRunnerConfig = {
|
|
414
|
+
supportedModels?: GenerativeModel[];
|
|
415
|
+
runner?: InferenceRunner;
|
|
416
|
+
};
|
|
417
|
+
type AgentModuleConfig = {
|
|
418
|
+
agentRepository?: AgentRepository;
|
|
419
|
+
agentLoopRepository?: LoopRepository;
|
|
420
|
+
inferenceRunnerConfig?: InferenceRunnerConfig;
|
|
421
|
+
toolRunner?: ToolUseRunner;
|
|
422
|
+
};
|
|
423
|
+
declare function defineAgentModule(config: AgentModuleConfig): {
|
|
424
|
+
createAgent: (config: {
|
|
425
|
+
name: string;
|
|
426
|
+
instruction: string;
|
|
427
|
+
tools: Tool[];
|
|
428
|
+
handlers: SituationHandler[];
|
|
429
|
+
}) => Promise<AgentRecord>;
|
|
430
|
+
createLoop: (params: {
|
|
431
|
+
subject: string;
|
|
432
|
+
agentId: string;
|
|
433
|
+
rules: CreateLoopRuleParams[];
|
|
434
|
+
}) => Promise<Loop>;
|
|
435
|
+
runLoop: (loopId: string) => Promise<Loop>;
|
|
436
|
+
state: (loopStateId: LoopStateId) => LoopSpecification;
|
|
437
|
+
modelAnswered: () => LoopSpecification;
|
|
438
|
+
runInference: () => LoopAction;
|
|
439
|
+
toolUse: () => LoopAction;
|
|
440
|
+
complete: (reason?: string) => LoopAction;
|
|
441
|
+
wait: (reason?: string) => LoopAction;
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
export { type AgentModuleConfig, type AgentRepository, type GenerativeModel, type InferenceRunner, type InferenceRunnerConfig, type LoopRepository, Participant, type SharedState, type SituationContext, type SituationHandler, type SituationProcessor, SituationSpecification, SpaceEvent, type Tool, type ToolUseRunner, defineAgentModule, defineRuntime };
|
package/dist/index.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ interface FunctionTool {
|
|
|
59
59
|
strict: boolean;
|
|
60
60
|
invoke: (args: any) => Promise<any> | any;
|
|
61
61
|
}
|
|
62
|
+
type Tool = FunctionTool;
|
|
62
63
|
|
|
63
64
|
type SpaceRecord = {
|
|
64
65
|
id: string;
|
|
@@ -102,4 +103,342 @@ declare function defineRuntime<TSharedState extends SharedState>(): {
|
|
|
102
103
|
sendMessageTool: FunctionTool;
|
|
103
104
|
};
|
|
104
105
|
|
|
105
|
-
|
|
106
|
+
interface ItemContent {
|
|
107
|
+
readonly type: string;
|
|
108
|
+
}
|
|
109
|
+
interface InputText extends ItemContent {
|
|
110
|
+
readonly type: "input_text";
|
|
111
|
+
readonly text: string;
|
|
112
|
+
}
|
|
113
|
+
interface SummaryText {
|
|
114
|
+
readonly type: "summary_text";
|
|
115
|
+
readonly text: string;
|
|
116
|
+
}
|
|
117
|
+
interface ReasoningItem {
|
|
118
|
+
readonly type: "reasoning";
|
|
119
|
+
readonly content?: InputText;
|
|
120
|
+
readonly encryptedContent?: string;
|
|
121
|
+
readonly summary: SummaryText[];
|
|
122
|
+
}
|
|
123
|
+
interface MessageItem {
|
|
124
|
+
readonly type: "user_message" | "system_message" | "developer_message" | "model_message";
|
|
125
|
+
readonly text: string;
|
|
126
|
+
}
|
|
127
|
+
interface ModelMessageItem extends MessageItem {
|
|
128
|
+
readonly type: "model_message";
|
|
129
|
+
readonly text: string;
|
|
130
|
+
}
|
|
131
|
+
interface ToolUseRequest {
|
|
132
|
+
readonly type: "tool_use_request";
|
|
133
|
+
readonly requestId: string;
|
|
134
|
+
readonly toolName: string;
|
|
135
|
+
readonly toolArguments: string;
|
|
136
|
+
}
|
|
137
|
+
interface ToolUseResult {
|
|
138
|
+
readonly type: "tool_use_result";
|
|
139
|
+
readonly requestId: string;
|
|
140
|
+
readonly result: InputText;
|
|
141
|
+
}
|
|
142
|
+
type ContextItem = MessageItem | ReasoningItem | ToolUseRequest | ToolUseResult;
|
|
143
|
+
type ModelOutputItem = ModelMessageItem | ToolUseRequest | ReasoningItem;
|
|
144
|
+
type Context = {
|
|
145
|
+
readonly items: ContextItem[];
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
interface InferenceEndpointMapper {
|
|
149
|
+
toRequest(inferenceRequest: InferenceRequest): any;
|
|
150
|
+
toResponse(response: any): InferenceResult;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
interface Endpoint {
|
|
154
|
+
endpointMapper: InferenceEndpointMapper;
|
|
155
|
+
infer(requestParams: InferenceRequest): Promise<InferenceResult>;
|
|
156
|
+
stream(requestParams: InferenceRequest): AsyncIterable<SpaceEvent>;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
type GenerativeModel = {
|
|
160
|
+
endpoint: Endpoint;
|
|
161
|
+
specification: ModelSpecification;
|
|
162
|
+
};
|
|
163
|
+
type ModelSpecification = {
|
|
164
|
+
name: string;
|
|
165
|
+
provider: string;
|
|
166
|
+
supportsReasoningEffort: boolean;
|
|
167
|
+
supportedReasoningEfforts: string[];
|
|
168
|
+
supportsStreaming: boolean;
|
|
169
|
+
contextWindowSize: number;
|
|
170
|
+
supportedContextItemTypes: string[];
|
|
171
|
+
maxOutputTokens: number;
|
|
172
|
+
supportsFunctionCalling: boolean;
|
|
173
|
+
supportsStructuredOutput: boolean;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
type StructuredOutputFormat = {
|
|
177
|
+
name?: string;
|
|
178
|
+
schema: Record<string, any>;
|
|
179
|
+
strict?: boolean;
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
declare class InputTokenDetails {
|
|
183
|
+
readonly cached_tokens: number;
|
|
184
|
+
constructor(cached_tokens: number);
|
|
185
|
+
}
|
|
186
|
+
declare class OutputTokenDetails {
|
|
187
|
+
readonly reasoning_tokens: number;
|
|
188
|
+
constructor(reasoning_tokens: number);
|
|
189
|
+
}
|
|
190
|
+
declare class TokenUsage {
|
|
191
|
+
readonly inputTokens: number;
|
|
192
|
+
readonly outputTokens: number;
|
|
193
|
+
readonly totalTokens: number;
|
|
194
|
+
readonly inputTokenDetails: InputTokenDetails;
|
|
195
|
+
readonly outputTokenDetails: OutputTokenDetails;
|
|
196
|
+
constructor(inputTokens: number, outputTokens: number, totalTokens: number, inputTokenDetails: InputTokenDetails, outputTokenDetails: OutputTokenDetails);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
type InferenceRequest = {
|
|
200
|
+
model: string;
|
|
201
|
+
maxOutputTokens?: number;
|
|
202
|
+
reasoningEffort?: string;
|
|
203
|
+
tools?: Tool[];
|
|
204
|
+
streaming?: boolean;
|
|
205
|
+
structuredOutput?: StructuredOutputFormat;
|
|
206
|
+
context: Context;
|
|
207
|
+
};
|
|
208
|
+
type InferenceResult = {
|
|
209
|
+
items: ModelOutputItem[];
|
|
210
|
+
tokenUsage: TokenUsage | undefined;
|
|
211
|
+
rowResponse: any;
|
|
212
|
+
};
|
|
213
|
+
interface InferenceRunner {
|
|
214
|
+
run(request: InferenceRequest): Promise<InferenceResult>;
|
|
215
|
+
stream(request: InferenceRequest): AsyncGenerator<SpaceEvent>;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
interface Memory {
|
|
219
|
+
getContext(): Context;
|
|
220
|
+
saveItem(item: ContextItem): void;
|
|
221
|
+
saveItems(items: ContextItem[]): void;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
type AgentRecord = {
|
|
225
|
+
id: string;
|
|
226
|
+
manifest: ParticipantManifest;
|
|
227
|
+
tools: Tool[];
|
|
228
|
+
memory: Memory;
|
|
229
|
+
handlers: SituationHandler[];
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
declare class Agent extends Participant {
|
|
233
|
+
private memory;
|
|
234
|
+
private tools;
|
|
235
|
+
constructor(manifest: ParticipantManifest, tools: Tool[], memory: Memory, handlers: SituationHandler[]);
|
|
236
|
+
getTools(): Tool[];
|
|
237
|
+
getMemory(): Memory;
|
|
238
|
+
static create({ manifest, tools, memory, handlers, }: {
|
|
239
|
+
manifest: ParticipantManifest;
|
|
240
|
+
tools: Tool[];
|
|
241
|
+
memory: Memory;
|
|
242
|
+
handlers: SituationHandler[];
|
|
243
|
+
}): Agent;
|
|
244
|
+
static rehydrate(record: AgentRecord): Agent;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
interface AgentRepository {
|
|
248
|
+
save(agent: Agent): Promise<void>;
|
|
249
|
+
exists(id: string): Promise<boolean>;
|
|
250
|
+
findById(id: string): Promise<Agent | undefined>;
|
|
251
|
+
findAll(): Promise<Agent[]>;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
type CompletedOperation = {
|
|
255
|
+
type: "inference";
|
|
256
|
+
operationId: string;
|
|
257
|
+
requestedAt: Date;
|
|
258
|
+
completedAt: Date;
|
|
259
|
+
request: InferenceRequest;
|
|
260
|
+
result: InferenceResult;
|
|
261
|
+
} | {
|
|
262
|
+
type: "tool_use";
|
|
263
|
+
operationId: string;
|
|
264
|
+
requestedAt: Date;
|
|
265
|
+
completedAt: Date;
|
|
266
|
+
call: ToolUseRequest;
|
|
267
|
+
result: ToolUseResult;
|
|
268
|
+
};
|
|
269
|
+
type PendingInference = {
|
|
270
|
+
id: string;
|
|
271
|
+
type: "inference";
|
|
272
|
+
requestedAt: Date;
|
|
273
|
+
request: InferenceRequest;
|
|
274
|
+
};
|
|
275
|
+
type PendingToolExecution = {
|
|
276
|
+
id: string;
|
|
277
|
+
type: "tool_execution";
|
|
278
|
+
requestedAt: Date;
|
|
279
|
+
call: ToolUseRequest;
|
|
280
|
+
};
|
|
281
|
+
type PendingOperation = PendingInference | PendingToolExecution;
|
|
282
|
+
|
|
283
|
+
interface LoopTransition {
|
|
284
|
+
readonly occurredAt: Date;
|
|
285
|
+
readonly previousState: LoopStateId;
|
|
286
|
+
readonly nextState: LoopStateId;
|
|
287
|
+
readonly reason: string;
|
|
288
|
+
readonly operationId?: string;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
type AgentLoop = {
|
|
292
|
+
readonly agent: Agent;
|
|
293
|
+
readonly loop: Loop;
|
|
294
|
+
};
|
|
295
|
+
declare abstract class LoopSpecification {
|
|
296
|
+
abstract isSatisfiedBy(agentLoop: AgentLoop): boolean;
|
|
297
|
+
and(other: LoopSpecification): LoopSpecification;
|
|
298
|
+
or(other: LoopSpecification): LoopSpecification;
|
|
299
|
+
not(): LoopSpecification;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
type LoopControlDirective = InferenceDirective | ToolUseDirective | WaitDirective | CompleteDirective;
|
|
303
|
+
type InferenceDirective = {
|
|
304
|
+
type: "inference";
|
|
305
|
+
request: InferenceRequest;
|
|
306
|
+
};
|
|
307
|
+
type ToolUseDirective = {
|
|
308
|
+
type: "tool_use";
|
|
309
|
+
call: ToolUseRequest;
|
|
310
|
+
};
|
|
311
|
+
type WaitDirective = {
|
|
312
|
+
type: "wait";
|
|
313
|
+
reason: string;
|
|
314
|
+
};
|
|
315
|
+
type CompleteDirective = {
|
|
316
|
+
type: "complete";
|
|
317
|
+
reason: string;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
declare abstract class LoopAction {
|
|
321
|
+
abstract execute(agentLoop: AgentLoop): LoopControlDirective;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
type CreateLoopRuleParams = {
|
|
325
|
+
readonly priority?: number;
|
|
326
|
+
readonly when: LoopSpecification;
|
|
327
|
+
readonly then: LoopAction;
|
|
328
|
+
};
|
|
329
|
+
type LoopRuleRecord = {
|
|
330
|
+
readonly id: string;
|
|
331
|
+
readonly priority: number;
|
|
332
|
+
readonly condition: LoopSpecification;
|
|
333
|
+
readonly action: LoopAction;
|
|
334
|
+
};
|
|
335
|
+
declare class LoopRule {
|
|
336
|
+
_id: string;
|
|
337
|
+
_priority: number;
|
|
338
|
+
_condition: LoopSpecification;
|
|
339
|
+
_action: LoopAction;
|
|
340
|
+
constructor(id: string, condition: LoopSpecification, action: LoopAction, priority: number);
|
|
341
|
+
get id(): string;
|
|
342
|
+
get priority(): number;
|
|
343
|
+
get condition(): LoopSpecification;
|
|
344
|
+
get action(): LoopAction;
|
|
345
|
+
static create(spec: CreateLoopRuleParams): LoopRule;
|
|
346
|
+
static rehydrate(spec: LoopRuleRecord): LoopRule;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
interface LoopRecord {
|
|
350
|
+
id: string;
|
|
351
|
+
agentId: string;
|
|
352
|
+
subject: string;
|
|
353
|
+
createdAt: Date;
|
|
354
|
+
state: LoopStateId;
|
|
355
|
+
inferenceRequest?: InferenceRequest;
|
|
356
|
+
pendingOperation?: PendingOperation;
|
|
357
|
+
transitionHistory: LoopTransition[];
|
|
358
|
+
operationHistory: CompletedOperation[];
|
|
359
|
+
rules: LoopRule[];
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
type LoopStateId = "idle" | "awaiting_inference_request" | "awaiting_inference" | "awaiting_tool_output" | "stopped" | "completed";
|
|
363
|
+
declare class Loop {
|
|
364
|
+
private readonly loopId;
|
|
365
|
+
private readonly agentId;
|
|
366
|
+
private readonly subject;
|
|
367
|
+
private readonly createdAt;
|
|
368
|
+
private state;
|
|
369
|
+
private pendingOperation;
|
|
370
|
+
private readonly transitionHistory;
|
|
371
|
+
private inferenceRequest;
|
|
372
|
+
private readonly operationHistory;
|
|
373
|
+
private readonly loopRules;
|
|
374
|
+
private constructor();
|
|
375
|
+
get id(): string;
|
|
376
|
+
get stateId(): LoopStateId;
|
|
377
|
+
get pending(): PendingOperation | undefined;
|
|
378
|
+
get history(): readonly LoopTransition[];
|
|
379
|
+
get completedOperations(): readonly CompletedOperation[];
|
|
380
|
+
get request(): InferenceRequest | undefined;
|
|
381
|
+
get rules(): readonly LoopRule[];
|
|
382
|
+
getAgentId(): string;
|
|
383
|
+
record(): LoopRecord;
|
|
384
|
+
moveToIdle(reason: string, transitionId: string): void;
|
|
385
|
+
moveToAwaitingInference(operation: PendingInference): void;
|
|
386
|
+
moveToAwaitingToolOutput(operation: Extract<PendingOperation, {
|
|
387
|
+
type: "tool_execution";
|
|
388
|
+
}>, occurredAt: Date): void;
|
|
389
|
+
requestInference(request: InferenceRequest): PendingInference;
|
|
390
|
+
requestToolUse(operationId: string, call: ToolUseRequest, requestedAt: Date): PendingToolExecution;
|
|
391
|
+
private transitionTo;
|
|
392
|
+
private assertIdle;
|
|
393
|
+
private assertAwaitingInferenceRequest;
|
|
394
|
+
receiveInferenceResult(operationId: string, result: InferenceResult): void;
|
|
395
|
+
receiveToolUseResult(operationId: string, result: ToolUseResult): void;
|
|
396
|
+
complete(reason: string): void;
|
|
397
|
+
stop(reason: string): void;
|
|
398
|
+
wait(reason: string): void;
|
|
399
|
+
private assertNotSettled;
|
|
400
|
+
static create(id: string, agentId: string, subject: string, rules: LoopRule[]): Loop;
|
|
401
|
+
static rehydrate(record: LoopRecord): Loop;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
interface LoopRepository {
|
|
405
|
+
save(loop: Loop): Promise<void>;
|
|
406
|
+
findById(id: string): Promise<Loop | undefined>;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
interface ToolUseRunner {
|
|
410
|
+
run(request: ToolUseRequest, tool: Tool): Promise<ToolUseResult>;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
type InferenceRunnerConfig = {
|
|
414
|
+
supportedModels?: GenerativeModel[];
|
|
415
|
+
runner?: InferenceRunner;
|
|
416
|
+
};
|
|
417
|
+
type AgentModuleConfig = {
|
|
418
|
+
agentRepository?: AgentRepository;
|
|
419
|
+
agentLoopRepository?: LoopRepository;
|
|
420
|
+
inferenceRunnerConfig?: InferenceRunnerConfig;
|
|
421
|
+
toolRunner?: ToolUseRunner;
|
|
422
|
+
};
|
|
423
|
+
declare function defineAgentModule(config: AgentModuleConfig): {
|
|
424
|
+
createAgent: (config: {
|
|
425
|
+
name: string;
|
|
426
|
+
instruction: string;
|
|
427
|
+
tools: Tool[];
|
|
428
|
+
handlers: SituationHandler[];
|
|
429
|
+
}) => Promise<AgentRecord>;
|
|
430
|
+
createLoop: (params: {
|
|
431
|
+
subject: string;
|
|
432
|
+
agentId: string;
|
|
433
|
+
rules: CreateLoopRuleParams[];
|
|
434
|
+
}) => Promise<Loop>;
|
|
435
|
+
runLoop: (loopId: string) => Promise<Loop>;
|
|
436
|
+
state: (loopStateId: LoopStateId) => LoopSpecification;
|
|
437
|
+
modelAnswered: () => LoopSpecification;
|
|
438
|
+
runInference: () => LoopAction;
|
|
439
|
+
toolUse: () => LoopAction;
|
|
440
|
+
complete: (reason?: string) => LoopAction;
|
|
441
|
+
wait: (reason?: string) => LoopAction;
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
export { type AgentModuleConfig, type AgentRepository, type GenerativeModel, type InferenceRunner, type InferenceRunnerConfig, type LoopRepository, Participant, type SharedState, type SituationContext, type SituationHandler, type SituationProcessor, SituationSpecification, SpaceEvent, type Tool, type ToolUseRunner, defineAgentModule, defineRuntime };
|