diff --git a/typescript/contracts/IAgent.ts b/typescript/contracts/IAgent.ts new file mode 100644 index 000000000..82bb35d53 --- /dev/null +++ b/typescript/contracts/IAgent.ts @@ -0,0 +1,8 @@ +import { AgentId } from "./IAgentRuntime"; + +export interface IAgent { + readonly id: AgentId; + onMessageAsync(message: unknown, context: unknown): Promise; + saveStateAsync(): Promise; + loadStateAsync(state: unknown): Promise; +} \ No newline at end of file diff --git a/typescript/core/BaseAgent.ts b/typescript/core/BaseAgent.ts new file mode 100644 index 000000000..626340283 --- /dev/null +++ b/typescript/core/BaseAgent.ts @@ -0,0 +1,32 @@ +import { IAgentRuntime, AgentId } from "../contracts/IAgentRuntime"; +import { IAgent } from "../contracts/IAgent"; + +export abstract class BaseAgent implements IAgent { + public readonly id: AgentId; + protected runtime: IAgentRuntime; + protected description: string; + + constructor(id: AgentId, runtime: IAgentRuntime, description: string) { + this.id = id; + this.runtime = runtime; + this.description = description; + } + + get metadata() { + return { + type: this.id.type, + key: this.id.key, + description: this.description + }; + } + + async onMessageAsync(message: unknown, context: unknown): Promise { + return null; + } + + async saveStateAsync(): Promise { + return {}; + } + + async loadStateAsync(state: unknown): Promise {} +} \ No newline at end of file