Skip to content

Commit

Permalink
Merge pull request #56 from polywrap/nerfzael-move-agent-package-to-c…
Browse files Browse the repository at this point in the history
…aller

Move agent package to caller
  • Loading branch information
dOrgJelli authored Aug 21, 2023
2 parents 881f4c5 + 4ffa721 commit 31deb25
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 22 deletions.
1 change: 1 addition & 0 deletions apps/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"@evo-ninja/core": "0.1.0",
"@polywrap/client-js": "~0.12.0",
"@fortawesome/fontawesome-svg-core": "^6.4.2",
"@fortawesome/free-brands-svg-icons": "^6.4.2",
"@fortawesome/free-solid-svg-icons": "^6.4.2",
Expand Down
18 changes: 17 additions & 1 deletion apps/browser/src/pages/Dojo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useState, useEffect } from 'react';

import * as EvoCore from "@evo-ninja/core";
import cl100k_base from "gpt-tokenizer/esm/encoding/cl100k_base";
import { PluginPackage } from "@polywrap/plugin-js";

import './Dojo.css';

Expand Down Expand Up @@ -127,13 +128,28 @@ function Dojo() {
cl100k_base,
logger
);
const agentPackage = PluginPackage.from(module => ({
"onGoalAchieved": async (args: any) => {
logger.success("Goal has been achieved!!!!!");
},
"speak": async (args: any) => {
logger.success("Agent: " + args.message);
return "User has been informed! If you think you've achieved the goal, execute onGoalAchieved.";
},
"ask": async (args: any) => {
logger.error("Agent: " + args.message);
const response = await prompt("");
return "User: " + response;
},
}));

setEvo(new EvoCore.Evo(
userWorkspace,
scripts,
llm,
chat,
logger
logger,
agentPackage
));
} catch (err) {
setDojoError(err);
Expand Down
1 change: 1 addition & 0 deletions apps/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"dependencies": {
"@evo-ninja/core": "0.1.0",
"@polywrap/client-js": "~0.12.0",
"chalk": "^4.1.2",
"clui": "~0.3.6",
"dotenv": "~16.3.1",
Expand Down
20 changes: 19 additions & 1 deletion apps/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import dotenv from "dotenv";
import readline from "readline";
import path from "path";
import cl100k_base from "gpt-tokenizer/cjs/encoding/cl100k_base";
import { PluginPackage } from "@polywrap/plugin-js";

dotenv.config({
path: path.join(__dirname, "../../../.env")
Expand Down Expand Up @@ -78,13 +79,30 @@ export async function cli(): Promise<void> {
logger
);

const agentPackage = PluginPackage.from(module => ({
"onGoalAchieved": async (args: any) => {
logger.success("Goal has been achieved!");
process.exit(0);
},
"speak": async (args: any) => {
logger.success("Agent: " + args.message);
return "User has been informed! If you think you've achieved the goal, execute onGoalAchieved.";
},
"ask": async (args: any) => {
logger.error("Agent: " + args.message);
const response = await prompt("");
return "User: " + response;
},
}));

// Create Evo
const evo = new Evo(
userWorkspace,
scripts,
llm,
chat,
logger
logger,
agentPackage
);

await logger.logHeader();
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/agents/evo/Evo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LlmApi, Chat } from "../../llm";
import { WrapClient } from "../../wrap";
import { Scripts } from "../../Scripts";
import { InMemoryWorkspace, Workspace, Logger } from "../../sys";
import { IWrapPackage } from "@polywrap/client-js";

export class Evo implements Agent {
private client: WrapClient;
Expand All @@ -17,11 +18,13 @@ export class Evo implements Agent {
private readonly scripts: Scripts,
private readonly llm: LlmApi,
private readonly chat: Chat,
private readonly logger: Logger
private readonly logger: Logger,
private readonly agentPackage: IWrapPackage
) {
this.client = new WrapClient(
this.workspace,
this.logger
this.logger,
this.agentPackage
);

this.globals = {};
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/agents/script-writer/ScriptWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class ScriptWriter implements Agent {
) {
this.client = new WrapClient(
this.workspace,
this.logger
this.logger,
);

this.globals = {};
Expand Down
26 changes: 9 additions & 17 deletions packages/core/src/wrap/WrapClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import {
PolywrapClient,
PolywrapClientConfigBuilder,
Uri,
InvokeResult
InvokeResult,
IWrapPackage
} from "@polywrap/client-js";
import { PluginPackage } from "@polywrap/plugin-js";
import axios from "axios";
Expand All @@ -16,7 +17,8 @@ export class WrapClient extends PolywrapClient {

constructor(
workspace: Workspace,
logger: Logger
logger: Logger,
agentPlugin: IWrapPackage | undefined = undefined,
) {
const jsPromiseOutput = { result: undefined };

Expand Down Expand Up @@ -104,23 +106,13 @@ export class WrapClient extends PolywrapClient {
logger.notice(`AXIOS.HEAD = ${args.url}`);
return await axios.head(args.url, args.config);
},
})))
.setPackage("plugin/agent", PluginPackage.from(module => ({
"onGoalAchieved": async (args: any) => {
logger.success("Goal has been achieved!");
process.exit(0);
},
"speak": async (args: any) => {
logger.success("Agent: " + args.message);
return "User has been informed! If you think you've achieved the goal, execute onGoalAchieved.";
},
"ask": async (args: any) => {
logger.error("Agent: " + args.message);
const response = await prompt("");
return "User: " + response;
},
})));

if (agentPlugin) {
builder
.setPackage("plugin/agent", agentPlugin);
}

super(builder.build());

this.jsPromiseOutput = jsPromiseOutput;
Expand Down

0 comments on commit 31deb25

Please sign in to comment.