From 9f047f91613500bae577b8b38b1e661d7acd6ae2 Mon Sep 17 00:00:00 2001 From: Lars Grammel Date: Wed, 19 Apr 2023 22:31:29 +0800 Subject: [PATCH] Introduce agent.observer package. --- examples/javascript-developer/src/runDeveloperAgent.ts | 2 +- examples/wikipedia/src/runWikipediaAgent.ts | 4 +--- packages/agent/src/agent/Run.ts | 2 +- packages/agent/src/agent/index.ts | 5 +++-- packages/agent/src/agent/{ => observer}/RunObserver.ts | 8 ++++---- packages/agent/src/agent/observer/index.ts | 2 ++ .../agent/src/agent/{ => observer}/showRunInConsole.ts | 6 +++--- packages/agent/src/agent/runAgent.ts | 2 +- 8 files changed, 16 insertions(+), 15 deletions(-) rename packages/agent/src/agent/{ => observer}/RunObserver.ts (80%) create mode 100644 packages/agent/src/agent/observer/index.ts rename packages/agent/src/agent/{ => observer}/showRunInConsole.ts (93%) diff --git a/examples/javascript-developer/src/runDeveloperAgent.ts b/examples/javascript-developer/src/runDeveloperAgent.ts index 08289ec..691231f 100644 --- a/examples/javascript-developer/src/runDeveloperAgent.ts +++ b/examples/javascript-developer/src/runDeveloperAgent.ts @@ -80,7 +80,7 @@ export async function runDeveloperAgent({ }), ], }), - observer: $.agent.showRunInConsole({ + observer: $.agent.observer.showRunInConsole({ name: "JavaScript Developer Agent", }), }); diff --git a/examples/wikipedia/src/runWikipediaAgent.ts b/examples/wikipedia/src/runWikipediaAgent.ts index aab68af..94f83d7 100644 --- a/examples/wikipedia/src/runWikipediaAgent.ts +++ b/examples/wikipedia/src/runWikipediaAgent.ts @@ -80,8 +80,6 @@ export async function runWikipediaAgent({ }), }), controller: $.agent.controller.maxSteps(20), - observer: $.agent.showRunInConsole({ - name: "Wikipedia Agent", - }), + observer: $.agent.observer.showRunInConsole({ name: "Wikipedia Agent" }), }); } diff --git a/packages/agent/src/agent/Run.ts b/packages/agent/src/agent/Run.ts index 3ea87cf..fcd3a80 100644 --- a/packages/agent/src/agent/Run.ts +++ b/packages/agent/src/agent/Run.ts @@ -4,7 +4,7 @@ import { Step } from "../step/Step"; import { StepResult } from "../step/StepResult"; import { createNextId } from "../util/createNextId"; import { GenerateCall } from "./GenerateCall"; -import { RunObserver } from "./RunObserver"; +import { RunObserver } from "./observer/RunObserver"; export class Run { private readonly observer?: RunObserver; diff --git a/packages/agent/src/agent/index.ts b/packages/agent/src/agent/index.ts index f751b29..0eb6f3b 100644 --- a/packages/agent/src/agent/index.ts +++ b/packages/agent/src/agent/index.ts @@ -1,5 +1,6 @@ +export * from "./GenerateCall"; export * from "./Run"; -export * from "./RunObserver"; +export * from "./RunContext"; export * as controller from "./controller/index"; +export * as observer from "./observer/index"; export * from "./runAgent"; -export * from "./showRunInConsole"; diff --git a/packages/agent/src/agent/RunObserver.ts b/packages/agent/src/agent/observer/RunObserver.ts similarity index 80% rename from packages/agent/src/agent/RunObserver.ts rename to packages/agent/src/agent/observer/RunObserver.ts index f949621..8938f6d 100644 --- a/packages/agent/src/agent/RunObserver.ts +++ b/packages/agent/src/agent/observer/RunObserver.ts @@ -1,7 +1,7 @@ -import { StepResult } from "../step"; -import { Loop } from "../step/Loop"; -import { Step } from "../step/Step"; -import { Run } from "./Run"; +import { StepResult } from "../../step"; +import { Loop } from "../../step/Loop"; +import { Step } from "../../step/Step"; +import { Run } from "../Run"; export type RunObserver = { onRunStarted?: ({}: { run: Run }) => void; diff --git a/packages/agent/src/agent/observer/index.ts b/packages/agent/src/agent/observer/index.ts new file mode 100644 index 0000000..0f16e76 --- /dev/null +++ b/packages/agent/src/agent/observer/index.ts @@ -0,0 +1,2 @@ +export * from "./RunObserver"; +export * from "./showRunInConsole"; diff --git a/packages/agent/src/agent/showRunInConsole.ts b/packages/agent/src/agent/observer/showRunInConsole.ts similarity index 93% rename from packages/agent/src/agent/showRunInConsole.ts rename to packages/agent/src/agent/observer/showRunInConsole.ts index d9a34e6..7bd599f 100644 --- a/packages/agent/src/agent/showRunInConsole.ts +++ b/packages/agent/src/agent/observer/showRunInConsole.ts @@ -1,7 +1,7 @@ import chalk from "chalk"; -import { Step, StepResult } from "../step"; -import { ToolStep } from "../tool/ToolStep"; -import { Run } from "./Run"; +import { Step, StepResult } from "../../step"; +import { ToolStep } from "../../tool/ToolStep"; +import { Run } from "../Run"; import { RunObserver } from "./RunObserver"; const log = console.log; diff --git a/packages/agent/src/agent/runAgent.ts b/packages/agent/src/agent/runAgent.ts index c070149..6c3d2fb 100644 --- a/packages/agent/src/agent/runAgent.ts +++ b/packages/agent/src/agent/runAgent.ts @@ -2,7 +2,7 @@ import { StepFactory } from "../step/StepFactory"; import { maxSteps } from "./controller/maxSteps"; import { Run } from "./Run"; import { RunController } from "./controller/RunController"; -import { RunObserver } from "./RunObserver"; +import { RunObserver } from "./observer/RunObserver"; export const runAgent = async ({ agent,