agent-swarm-kit 1.0.113 → 1.0.115

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-swarm-kit",
3
- "version": "1.0.113",
3
+ "version": "1.0.115",
4
4
  "description": "A TypeScript library for building orchestrated framework-agnostic multi-agent AI systems",
5
5
  "author": {
6
6
  "name": "Petr Tripolsky",
package/types.d.ts CHANGED
@@ -522,6 +522,13 @@ interface ISwarmSessionCallbacks {
522
522
  * @param mode - The source of execution: tool or user.
523
523
  */
524
524
  onExecute?: (clientId: string, swarmName: SwarmName, content: string, mode: ExecutionMode) => void;
525
+ /**
526
+ * Callback triggered when a stateless completion run executed
527
+ * @param clientId - The ID of the client.
528
+ * @param swarmName - The name of the swarm.
529
+ * @param content - The content to execute.
530
+ */
531
+ onRun?: (clientId: string, swarmName: SwarmName, content: string) => void;
525
532
  /**
526
533
  * Callback triggered when a message is emitted.
527
534
  * @param clientId - The ID of the client.
@@ -680,6 +687,12 @@ interface ISession {
680
687
  * @returns {Promise<void>}
681
688
  */
682
689
  emit(message: string): Promise<void>;
690
+ /**
691
+ * Run the complete stateless without modifying chat history
692
+ * @param {string} content - The content to execute.
693
+ * @returns {Promise<string>}
694
+ */
695
+ run(content: string): Promise<string>;
683
696
  /**
684
697
  * Execute a command.
685
698
  * @param {string} content - The content to execute.
@@ -1338,6 +1351,14 @@ interface IAgentParams extends Omit<IAgentSchema, keyof {
1338
1351
  * Interface representing the lifecycle callbacks of an agent
1339
1352
  */
1340
1353
  interface IAgentSchemaCallbacks {
1354
+ /**
1355
+ * Callback triggered when the agent run stateless.
1356
+ * @param clientId - The ID of the client.
1357
+ * @param agentName - The name of the agent.
1358
+ * @param input - The input to execute.
1359
+ * @param mode - The source of execution: tool or user.
1360
+ */
1361
+ onRun?: (clientId: string, agentName: AgentName, input: string) => void;
1341
1362
  /**
1342
1363
  * Callback triggered when the agent executes.
1343
1364
  * @param clientId - The ID of the client.
@@ -1455,6 +1476,12 @@ interface IAgentSchema {
1455
1476
  * Interface representing an agent.
1456
1477
  */
1457
1478
  interface IAgent {
1479
+ /**
1480
+ * Run the complete stateless without write to the chat history
1481
+ * @param input - The input to run.
1482
+ * @returns A promise that resolves when the run is complete.
1483
+ */
1484
+ run: (input: string) => Promise<string>;
1458
1485
  /**
1459
1486
  * Executes the agent with the given input.
1460
1487
  * @param input - The input to execute.
@@ -1662,6 +1689,12 @@ declare class ClientAgent implements IAgent {
1662
1689
  * @returns {Promise<void>}
1663
1690
  */
1664
1691
  execute: IAgent["execute"];
1692
+ /**
1693
+ * Run the completion stateless and return the output
1694
+ * @param {string} incoming - The incoming message content.
1695
+ * @returns {Promise<void>}
1696
+ */
1697
+ run: IAgent["run"];
1665
1698
  /**
1666
1699
  * Should call on agent dispose
1667
1700
  * @returns {Promise<void>}
@@ -1696,6 +1729,12 @@ declare class AgentConnectionService implements IAgent {
1696
1729
  * @returns {Promise<any>} The execution result.
1697
1730
  */
1698
1731
  execute: (input: string, mode: ExecutionMode) => Promise<void>;
1732
+ /**
1733
+ * Run the completion stateless
1734
+ * @param {string} input - The input command.
1735
+ * @returns {Promise<any>} The execution result.
1736
+ */
1737
+ run: (input: string) => Promise<string>;
1699
1738
  /**
1700
1739
  * Waits for the output from the agent.
1701
1740
  * @returns {Promise<any>} The output result.
@@ -2064,6 +2103,12 @@ declare class ClientSession implements ISession {
2064
2103
  * @returns {Promise<string>} - The output of the execution.
2065
2104
  */
2066
2105
  execute: (message: string, mode: ExecutionMode) => Promise<string>;
2106
+ /**
2107
+ * Run the completion stateless
2108
+ * @param {string} message - The message to run.
2109
+ * @returns {Promise<string>} - The output of the execution.
2110
+ */
2111
+ run: (message: string) => Promise<string>;
2067
2112
  /**
2068
2113
  * Commits tool output.
2069
2114
  * @param {string} toolId - The `tool_call_id` for openai history
@@ -2141,6 +2186,12 @@ declare class SessionConnectionService implements ISession {
2141
2186
  * @returns {Promise<string>} A promise that resolves with the execution result.
2142
2187
  */
2143
2188
  execute: (content: string, mode: ExecutionMode) => Promise<string>;
2189
+ /**
2190
+ * Run the completion stateless
2191
+ * @param {string} content - The content to execute.
2192
+ * @returns {Promise<string>} A promise that resolves with the execution result.
2193
+ */
2194
+ run: (content: string) => Promise<string>;
2144
2195
  /**
2145
2196
  * Connects to the session using the provided connector.
2146
2197
  * @param {SendMessageFn} connector - The function to send messages.
@@ -2220,6 +2271,14 @@ declare class AgentPublicService implements TAgentConnectionService {
2220
2271
  * @returns {Promise<unknown>} The execution result.
2221
2272
  */
2222
2273
  execute: (input: string, mode: ExecutionMode, methodName: string, clientId: string, agentName: AgentName) => Promise<void>;
2274
+ /**
2275
+ * Run the completion stateless
2276
+ * @param {string} input - The input command.
2277
+ * @param {string} clientId - The client ID.
2278
+ * @param {AgentName} agentName - The name of the agent.
2279
+ * @returns {Promise<unknown>} The execution result.
2280
+ */
2281
+ run: (input: string, methodName: string, clientId: string, agentName: AgentName) => Promise<string>;
2223
2282
  /**
2224
2283
  * Waits for the agent's output.
2225
2284
  * @param {string} clientId - The client ID.
@@ -2367,6 +2426,14 @@ declare class SessionPublicService implements TSessionConnectionService {
2367
2426
  * @returns {Promise<void>}
2368
2427
  */
2369
2428
  execute: (content: string, mode: ExecutionMode, methodName: string, clientId: string, swarmName: SwarmName) => Promise<string>;
2429
+ /**
2430
+ * Run the completion stateless
2431
+ * @param {string} content - The content to execute.
2432
+ * @param {string} clientId - The client ID.
2433
+ * @param {SwarmName} swarmName - The swarm name.
2434
+ * @returns {Promise<void>}
2435
+ */
2436
+ run: (content: string, methodName: string, clientId: string, swarmName: SwarmName) => Promise<string>;
2370
2437
  /**
2371
2438
  * Connects to the session.
2372
2439
  * @param {SendMessageFn} connector - The function to send messages.
@@ -3502,6 +3569,36 @@ declare class SharedStoragePublicService implements TSharedStorageConnectionServ
3502
3569
  clear: (methodName: string, storageName: StorageName) => Promise<void>;
3503
3570
  }
3504
3571
 
3572
+ /**
3573
+ * Service to manage memory schema for different sessions.
3574
+ */
3575
+ declare class MemorySchemaService {
3576
+ private readonly loggerService;
3577
+ private memoryMap;
3578
+ /**
3579
+ * Writes a value to the memory map for a given client ID.
3580
+ *
3581
+ * @template T - The type of the value to be written.
3582
+ * @param {string} clientId - The ID of the client.
3583
+ * @param {T} value - The value to be written.
3584
+ */
3585
+ writeValue: <T extends object = object>(clientId: string, value: T) => T;
3586
+ /**
3587
+ * Reads a value from the memory map for a given client ID.
3588
+ *
3589
+ * @template T - The type of the value to be read.
3590
+ * @param {string} clientId - The ID of the client.
3591
+ * @returns {T} - The value associated with the client ID.
3592
+ */
3593
+ readValue: <T extends object = object>(clientId: string) => T;
3594
+ /**
3595
+ * Disposes the memory map entry for a given client ID.
3596
+ *
3597
+ * @param {string} clientId - The ID of the client.
3598
+ */
3599
+ dispose: (clientId: string) => void;
3600
+ }
3601
+
3505
3602
  declare const swarm: {
3506
3603
  agentValidationService: AgentValidationService;
3507
3604
  toolValidationService: ToolValidationService;
@@ -3527,6 +3624,7 @@ declare const swarm: {
3527
3624
  embeddingSchemaService: EmbeddingSchemaService;
3528
3625
  storageSchemaService: StorageSchemaService;
3529
3626
  stateSchemaService: StateSchemaService;
3627
+ memorySchemaService: MemorySchemaService;
3530
3628
  agentConnectionService: AgentConnectionService;
3531
3629
  historyConnectionService: HistoryConnectionService;
3532
3630
  swarmConnectionService: SwarmConnectionService;
@@ -3842,6 +3940,29 @@ declare const execute: (content: string, clientId: string, agentName: AgentName)
3842
3940
  */
3843
3941
  declare const emit: (content: string, clientId: string, agentName: AgentName) => Promise<void>;
3844
3942
 
3943
+ /**
3944
+ * Complete the message stateless without append to the chat history
3945
+ * Use to prevent model from history overflow while handling storage output
3946
+ *
3947
+ * @param {string} content - The content to be runned.
3948
+ * @param {string} clientId - The ID of the client requesting run.
3949
+ * @param {AgentName} agentName - The name of the agent running the command.
3950
+ * @returns {Promise<string>} - A promise that resolves the run result
3951
+ */
3952
+ declare const run: (content: string, clientId: string, agentName: AgentName) => Promise<string>;
3953
+
3954
+ /**
3955
+ * Complete the message stateless without append to the chat history
3956
+ * Use to prevent model from history overflow while handling storage output
3957
+ *
3958
+ * Will run even if the agent is inactive
3959
+ *
3960
+ * @param {string} content - The content to be runned.
3961
+ * @param {string} clientId - The ID of the client requesting run.
3962
+ * @returns {Promise<string>} - A promise that resolves the run result
3963
+ */
3964
+ declare const runForce: (content: string, clientId: string) => Promise<string>;
3965
+
3845
3966
  type SendMessageFn = (outgoing: string) => Promise<void>;
3846
3967
  /**
3847
3968
  * A connection factory for a client to a swarm and returns a function to send messages.
@@ -3982,6 +4103,27 @@ declare const getAgentHistory: (clientId: string, agentName: AgentName) => Promi
3982
4103
  */
3983
4104
  declare const getSessionMode: (clientId: string) => Promise<SessionMode>;
3984
4105
 
4106
+ /**
4107
+ * Represents the session context.
4108
+ *
4109
+ * @interface ISessionContext
4110
+ * @property {string | null} clientId - The client id, or null if not available.
4111
+ * @property {IMethodContext | null} methodContext - The method context, or null if not available.
4112
+ * @property {IExecutionContext | null} executionContext - The execution context, or null if not available.
4113
+ */
4114
+ interface ISessionContext {
4115
+ clientId: string | null;
4116
+ methodContext: IMethodContext | null;
4117
+ executionContext: IExecutionContext | null;
4118
+ }
4119
+ /**
4120
+ * Retrieves the session context for a given client ID.
4121
+ *
4122
+ * @param {string} clientId - The ID of the client.
4123
+ * @returns {Promise<ISessionContext>} A promise that resolves to the session context.
4124
+ */
4125
+ declare const getSessionContext: () => Promise<ISessionContext>;
4126
+
3985
4127
  /**
3986
4128
  * Retrieves the last message sent by the user from the client's message history.
3987
4129
  *
@@ -4470,42 +4612,28 @@ declare class SharedStateUtils implements TSharedState {
4470
4612
  * Retrieves the state for a given client and state name.
4471
4613
  * @template T
4472
4614
  * @param {Object} payload - The payload containing client and state information.
4473
- * @param {AgentName} payload.agentName - The agent name.
4474
4615
  * @param {StateName} payload.stateName - The state name.
4475
4616
  * @returns {Promise<T>} The state data.
4476
4617
  * @throws Will throw an error if the state is not registered in the agent.
4477
4618
  */
4478
- getState: <T extends unknown = any>(payload: {
4479
- agentName: AgentName;
4480
- stateName: StateName;
4481
- }) => Promise<T>;
4619
+ getState: <T extends unknown = any>(stateName: StateName) => Promise<T>;
4482
4620
  /**
4483
4621
  * Sets the state for a given client and state name.
4484
4622
  * @template T
4485
4623
  * @param {T | ((prevSharedState: T) => Promise<T>)} dispatchFn - The new state or a function that returns the new state.
4486
- * @param {Object} payload - The payload containing client and state information.
4487
- * @param {AgentName} payload.agentName - The agent name.
4488
- * @param {StateName} payload.stateName - The state name.
4624
+ * @param {StateName} stateName - The state name.
4489
4625
  * @returns {Promise<void>}
4490
4626
  * @throws Will throw an error if the state is not registered in the agent.
4491
4627
  */
4492
- setState: <T extends unknown = any>(dispatchFn: T | ((prevSharedState: T) => Promise<T>), payload: {
4493
- agentName: AgentName;
4494
- stateName: StateName;
4495
- }) => Promise<void>;
4628
+ setState: <T extends unknown = any>(dispatchFn: T | ((prevSharedState: T) => Promise<T>), stateName: StateName) => Promise<void>;
4496
4629
  /**
4497
4630
  * Set the state to initial value
4498
4631
  * @template T
4499
- * @param {Object} payload - The payload containing client and state information.
4500
- * @param {AgentName} payload.agentName - The agent name.
4501
4632
  * @param {StateName} payload.stateName - The state name.
4502
4633
  * @returns {Promise<void>}
4503
4634
  * @throws Will throw an error if the state is not registered in the agent.
4504
4635
  */
4505
- clearState: <T extends unknown = any>(payload: {
4506
- agentName: AgentName;
4507
- stateName: StateName;
4508
- }) => Promise<T>;
4636
+ clearState: <T extends unknown = any>(stateName: StateName) => Promise<T>;
4509
4637
  }
4510
4638
  /**
4511
4639
  * Instance of SharedStateUtils for managing state.
@@ -4617,7 +4745,6 @@ declare class SharedStorageUtils implements TSharedStorage {
4617
4745
  * Takes items from the storage.
4618
4746
  * @param {string} search - The search query.
4619
4747
  * @param {number} total - The total number of items to take.
4620
- * @param {AgentName} agentName - The agent name.
4621
4748
  * @param {StorageName} storageName - The storage name.
4622
4749
  * @returns {Promise<T[]>} - A promise that resolves to an array of items.
4623
4750
  * @template T
@@ -4625,71 +4752,46 @@ declare class SharedStorageUtils implements TSharedStorage {
4625
4752
  take: <T extends IStorageData = IStorageData>(payload: {
4626
4753
  search: string;
4627
4754
  total: number;
4628
- agentName: AgentName;
4629
4755
  storageName: StorageName;
4630
4756
  score?: number;
4631
4757
  }) => Promise<T[]>;
4632
4758
  /**
4633
4759
  * Upserts an item in the storage.
4634
4760
  * @param {T} item - The item to upsert.
4635
- * @param {AgentName} agentName - The agent name.
4636
4761
  * @param {StorageName} storageName - The storage name.
4637
4762
  * @returns {Promise<void>} - A promise that resolves when the operation is complete.
4638
4763
  * @template T
4639
4764
  */
4640
- upsert: <T extends IStorageData = IStorageData>(payload: {
4641
- item: T;
4642
- agentName: AgentName;
4643
- storageName: StorageName;
4644
- }) => Promise<void>;
4765
+ upsert: <T extends IStorageData = IStorageData>(item: T, storageName: StorageName) => Promise<void>;
4645
4766
  /**
4646
4767
  * Removes an item from the storage.
4647
4768
  * @param {IStorageData["id"]} itemId - The ID of the item to remove.
4648
- * @param {AgentName} agentName - The agent name.
4649
4769
  * @param {StorageName} storageName - The storage name.
4650
4770
  * @returns {Promise<void>} - A promise that resolves when the operation is complete.
4651
4771
  */
4652
- remove: (payload: {
4653
- itemId: IStorageData["id"];
4654
- agentName: AgentName;
4655
- storageName: StorageName;
4656
- }) => Promise<void>;
4772
+ remove: (itemId: IStorageData["id"], storageName: StorageName) => Promise<void>;
4657
4773
  /**
4658
4774
  * Gets an item from the storage.
4659
4775
  * @param {IStorageData["id"]} itemId - The ID of the item to get.
4660
- * @param {AgentName} agentName - The agent name.
4661
4776
  * @param {StorageName} storageName - The storage name.
4662
4777
  * @returns {Promise<T | null>} - A promise that resolves to the item or null if not found.
4663
4778
  * @template T
4664
4779
  */
4665
- get: <T extends IStorageData = IStorageData>(payload: {
4666
- itemId: IStorageData["id"];
4667
- agentName: AgentName;
4668
- storageName: StorageName;
4669
- }) => Promise<T | null>;
4780
+ get: <T extends IStorageData = IStorageData>(itemId: IStorageData["id"], storageName: StorageName) => Promise<T | null>;
4670
4781
  /**
4671
4782
  * Lists items from the storage.
4672
- * @param {AgentName} agentName - The agent name.
4673
4783
  * @param {StorageName} storageName - The storage name.
4674
4784
  * @param {(item: T) => boolean} [filter] - Optional filter function.
4675
4785
  * @returns {Promise<T[]>} - A promise that resolves to an array of items.
4676
4786
  * @template T
4677
4787
  */
4678
- list: <T extends IStorageData = IStorageData>(payload: {
4679
- agentName: AgentName;
4680
- storageName: StorageName;
4681
- filter?: (item: T) => boolean;
4682
- }) => Promise<T[]>;
4788
+ list: <T extends IStorageData = IStorageData>(storageName: StorageName, filter?: (item: T) => boolean) => Promise<T[]>;
4683
4789
  /**
4684
4790
  * Clears the storage.
4685
- * @param {AgentName} agentName - The agent name.
4686
4791
  * @param {StorageName} storageName - The storage name.
4687
4792
  * @returns {Promise<void>} - A promise that resolves when the operation is complete.
4688
4793
  */
4689
- clear: (payload: {
4690
- agentName: AgentName;
4691
- storageName: StorageName;
4692
- }) => Promise<void>;
4794
+ clear: (storageName: StorageName) => Promise<void>;
4693
4795
  }
4694
4796
  declare const SharedStorage: SharedStorageUtils;
4695
4797
 
@@ -4697,6 +4799,23 @@ declare const SharedStorage: SharedStorageUtils;
4697
4799
  * Utility class for schema-related operations.
4698
4800
  */
4699
4801
  declare class SchemaUtils {
4802
+ /**
4803
+ * Writes a value to the session memory for a given client.
4804
+ *
4805
+ * @template T - The type of the value to write.
4806
+ * @param {string} clientId - The ID of the client.
4807
+ * @param {T} value - The value to write to the session memory.
4808
+ * @returns {T} The actual value from the session memory.
4809
+ */
4810
+ writeSessionMemory: <T extends object = object>(clientId: string, value: T) => T;
4811
+ /**
4812
+ * Reads a value from the session memory for a given client.
4813
+ *
4814
+ * @template T - The type of the value to read.
4815
+ * @param {string} clientId - The ID of the client.
4816
+ * @returns {T} The value read from the session memory.
4817
+ */
4818
+ readSessionMemory: <T extends object = object>(clientId: string) => T;
4700
4819
  /**
4701
4820
  * Serializes an object or an array of objects into a formatted string.
4702
4821
  *
@@ -4711,4 +4830,4 @@ declare class SchemaUtils {
4711
4830
  */
4712
4831
  declare const Schema: SchemaUtils;
4713
4832
 
4714
- export { type EventSource, ExecutionContextService, History, HistoryAdapter, HistoryInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IHistoryAdapter, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type ISessionConfig, type IStateSchema, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerAdapter, LoggerInstance, MethodContextService, type ReceiveMessageFn, Schema, type SendMessageFn$1 as SendMessageFn, SharedState, SharedStorage, State, Storage, addAgent, addCompletion, addEmbedding, addState, addStorage, addSwarm, addTool, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpDocs, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, session, setConfig, swarm };
4833
+ export { type EventSource, ExecutionContextService, History, HistoryAdapter, HistoryInstance, type IAgentSchema, type IAgentTool, type IBaseEvent, type IBusEvent, type IBusEventContext, type ICompletionArgs, type ICompletionSchema, type ICustomEvent, type IEmbeddingSchema, type IHistoryAdapter, type IHistoryInstance, type IHistoryInstanceCallbacks, type IIncomingMessage, type ILoggerAdapter, type ILoggerInstance, type ILoggerInstanceCallbacks, type IMakeConnectionConfig, type IMakeDisposeParams, type IModelMessage, type IOutgoingMessage, type ISessionConfig, type IStateSchema, type IStorageSchema, type ISwarmSchema, type ITool, type IToolCall, Logger, LoggerAdapter, LoggerInstance, MethodContextService, type ReceiveMessageFn, Schema, type SendMessageFn$1 as SendMessageFn, SharedState, SharedStorage, State, Storage, addAgent, addCompletion, addEmbedding, addState, addStorage, addSwarm, addTool, cancelOutput, cancelOutputForce, changeToAgent, changeToDefaultAgent, changeToPrevAgent, commitAssistantMessage, commitAssistantMessageForce, commitFlush, commitFlushForce, commitStopTools, commitStopToolsForce, commitSystemMessage, commitSystemMessageForce, commitToolOutput, commitToolOutputForce, commitUserMessage, commitUserMessageForce, complete, disposeConnection, dumpAgent, dumpDocs, dumpSwarm, emit, emitForce, event, execute, executeForce, getAgentHistory, getAgentName, getAssistantHistory, getLastAssistantMessage, getLastSystemMessage, getLastUserMessage, getRawHistory, getSessionContext, getSessionMode, getUserHistory, listenAgentEvent, listenAgentEventOnce, listenEvent, listenEventOnce, listenHistoryEvent, listenHistoryEventOnce, listenSessionEvent, listenSessionEventOnce, listenStateEvent, listenStateEventOnce, listenStorageEvent, listenStorageEventOnce, listenSwarmEvent, listenSwarmEventOnce, makeAutoDispose, makeConnection, run, runForce, session, setConfig, swarm };