Browse Source

add base agent

pull/5678/head
Ryan Sweet 1 year ago
parent
commit
ec44efef17
2 changed files with 40 additions and 0 deletions
  1. +8
    -0
      typescript/contracts/IAgent.ts
  2. +32
    -0
      typescript/core/BaseAgent.ts

+ 8
- 0
typescript/contracts/IAgent.ts View File

@@ -0,0 +1,8 @@
import { AgentId } from "./IAgentRuntime";

export interface IAgent {
readonly id: AgentId;
onMessageAsync(message: unknown, context: unknown): Promise<unknown>;
saveStateAsync(): Promise<unknown>;
loadStateAsync(state: unknown): Promise<void>;
}

+ 32
- 0
typescript/core/BaseAgent.ts View File

@@ -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<unknown> {
return null;
}

async saveStateAsync(): Promise<unknown> {
return {};
}

async loadStateAsync(state: unknown): Promise<void> {}
}

Loading…
Cancel
Save