Skip to content

Commit adfda1a

Browse files
committedDec 13, 2024
add runtime::stop(), runtime::clients, disable specifying direct as a character client
1 parent 84a7aaf commit adfda1a

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
 

‎packages/core/src/runtime.ts

+20
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export class AgentRuntime implements IAgentRuntime {
142142
services: Map<ServiceType, Service> = new Map();
143143
memoryManagers: Map<string, IMemoryManager> = new Map();
144144
cacheManager: ICacheManager;
145+
clients: Record<string, any>;
145146

146147
registerMemoryManager(manager: IMemoryManager): void {
147148
if (!manager.tableName) {
@@ -405,6 +406,25 @@ export class AgentRuntime implements IAgentRuntime {
405406
}
406407
}
407408

409+
async stop() {
410+
elizaLogger.debug('runtime::stop - character', this.character)
411+
// stop services, they don't have a stop function
412+
// just initialize
413+
414+
// plugins
415+
// have actions, providers, evaluators (no start/stop)
416+
// services (just initialized), clients
417+
418+
// client have a start
419+
for(const cStr in this.clients) {
420+
const c = this.clients[cStr]
421+
elizaLogger.log('runtime::stop - requesting', cStr, 'client stop for', this.character.name)
422+
c.stop()
423+
}
424+
// we don't need to unregister with directClient
425+
// don't need to worry about knowledge
426+
}
427+
408428
/**
409429
* Processes character knowledge by creating document memories and fragment memories.
410430
* This function takes an array of knowledge items, creates a document memory for each item if it doesn't exist,

‎packages/core/src/types.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,9 @@ export type Plugin = {
603603
*/
604604
export enum Clients {
605605
DISCORD = "discord",
606-
DIRECT = "direct",
606+
// you can't specify this in characters
607+
// all characters are registered with this
608+
// DIRECT = "direct",
607609
TWITTER = "twitter",
608610
TELEGRAM = "telegram",
609611
FARCASTER = "farcaster",
@@ -1003,6 +1005,9 @@ export interface IAgentRuntime {
10031005
cacheManager: ICacheManager;
10041006

10051007
services: Map<ServiceType, Service>;
1008+
// any could be EventEmitter
1009+
// but I think the real solution is forthcoming as a base client interface
1010+
clients: Record<string, any>;
10061011

10071012
initialize(): Promise<void>;
10081013

0 commit comments

Comments
 (0)