Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rename "operation" to "script" #19

Merged
merged 2 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Welcome to evo.ninja.

Evo.ninja is an AI agent that builds itself!
It executes operations to achieve a goal.
It is capable of using fuzzy search to find and execute any operation in its library.
Operations are namespaced JavaScript functions with typed arguments and a description.
If it can not find an operation, it will write one itself.
It executes scripts to achieve a goal.
It is capable of using fuzzy search to find and execute any script in its library.
Scripts are namespaced JavaScript functions with typed arguments and a description.
If it can not find a script, it will write one itself.

[Roadmap](./ROADMAP.md)

Expand Down
6 changes: 4 additions & 2 deletions ROADMAP.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Roadmap

## High-Pri
x rename operations -> scripts
- add metadata to header of script
- chat log, used for showing examples
- example https://github.com/polywrap/polygpt#examples

Expand All @@ -13,8 +15,8 @@
## Improvements for hackathon
- Shims
- axios (done?)
- When executeOperation returns undefined it should be an error to the LLM (maybe) (void funcs to return bool?)
- When executeScript returns undefined it should be an error to the LLM (maybe) (void funcs to return bool?)
- Function to trim text("error...").
- This should also fix the issue with always displaying '...' even when text is shorter than max length
- Better global variable implementation
- Issue is that agent tries to access props of the variable (which is not supported) or use it in operation code, etc
- Issue is that agent tries to access props of the variable (which is not supported) or use it in script code, etc
6 changes: 0 additions & 6 deletions operations/crypto.getPrice.json

This file was deleted.

6 changes: 0 additions & 6 deletions operations/math.divide.json

This file was deleted.

5 changes: 5 additions & 0 deletions scripts/agent.ask.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return __wrap_subinvoke(
'plugin/agent',
'ask',
{ message: message }
).value
2 changes: 1 addition & 1 deletion operations/agent.ask.json → scripts/agent.ask.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name":"agent.ask",
"description":"Sends a message to the user and waits for user response.",
"arguments":"{ message: string }",
"code":"return __wrap_subinvoke('plugin/agent', 'ask', { message: message }).value"
"code":"./agent.ask.js"
}
5 changes: 5 additions & 0 deletions scripts/agent.onGoalAchieved.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return __wrap_subinvoke(
'plugin/agent',
'onGoalAchieved',
{ }
).value
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name":"agent.onGoalAchieved",
"description":"Informs the user that the goal has been achieved.",
"arguments":"None",
"code":"return __wrap_subinvoke('plugin/agent', 'onGoalAchieved', { a: 5 }).value"
"code":"./agent.onGoalAchieved.js"
}
5 changes: 5 additions & 0 deletions scripts/agent.speak.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
return __wrap_subinvoke(
'plugin/agent',
'speak',
{ message: message }
).value
2 changes: 1 addition & 1 deletion operations/agent.speak.json → scripts/agent.speak.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name":"agent.speak",
"description":"Informs the user by sending a message.",
"arguments":"{ message: string }",
"code":"return __wrap_subinvoke('plugin/agent', 'speak', { message: message }).value"
"code":"./agent.speak.js"
}
14 changes: 14 additions & 0 deletions scripts/crypto.getPrice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const axios = require('axios');

const url = 'https://api.coingecko.com/api/v3/simple/price';
const params = {
ids: currency,
vs_currencies: 'usd'
};

try {
const response = await axios.get(url, { params });
return response.data[currency].usd;
} catch (error) {
throw new Error(`Could not fetch price for ${currency}: ${error.message}`);
}
6 changes: 6 additions & 0 deletions scripts/crypto.getPrice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "crypto.getPrice",
"description": "Get the current price of a specified cryptocurrency.",
"arguments": "{ currency: string }",
"code": "./crypto.getPrice.js"
}
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions scripts/fs.writeFile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const fs = require('fs');
try {
fs.writeFileSync(path, data, encoding);
} catch (error) {
throw new Error(`Failed to write file: ${error.message}`);
}
2 changes: 1 addition & 1 deletion operations/fs.writeFile.json → scripts/fs.writeFile.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"name": "fs.writeFile",
"description": "Writes data to a file, replacing the file if it already exists.",
"arguments": "{ path: string, data: string, encoding: string }",
"code": "const fs = require('fs');\ntry {\n fs.writeFileSync(path, data, encoding);\n} catch (error) {\n throw new Error(`Failed to write file: ${error.message}`);\n}"
"code": "./fs.writeFile.js"
}
4 changes: 4 additions & 0 deletions scripts/math.divide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if (denominator === 0) {
throw new Error('Cannot divide by zero');
}
return numerator / denominator;
6 changes: 6 additions & 0 deletions scripts/math.divide.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "math.divide",
"description": "This script divides two numbers and returns the result.",
"arguments": "{ numerator: number, denominator: number }",
"code": "./math.divide.js"
}
4 changes: 2 additions & 2 deletions shim-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ function require(lib) {
}

const __temp = (async function () {
// OPERATION CODE HERE (do not forget to declare arguments of the operation function as local vars)
// SCRIPT CODE HERE (do not forget to declare arguments of the script function as local vars)

//END OPERATION CODE
//END SCRIPT CODE
})().then(result => {
__wrap_subinvoke("plugin/result", "post", { result: result != null ? result : "undefined" })
}, error => {
Expand Down
46 changes: 0 additions & 46 deletions site/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion src/__tests__/agent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('AI Agent Test Suite', () => {

// You can add more complex tests here...
// For example:
test('Complex Operation: (590 * 204) + (1000 / 2) - 42', () => {
test('Complex script: (590 * 204) + (1000 / 2) - 42', () => {
const goal = '(590 * 204) + (1000 / 2) - 42';
const startTime = new Date().getTime();
const result = execSync(`yarn start '${goal}'`, { timeout: oneMinute, encoding: 'utf-8' });
Expand Down
6 changes: 0 additions & 6 deletions src/__tests__/operations.spec.ts

This file was deleted.

6 changes: 6 additions & 0 deletions src/__tests__/scripts.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/*
TODO:
- add tests for individual scripts
*/


Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { AgentFunction } from "../../functions";
import { WrapClient } from "../../wrap";
import { addOperation } from "../../operations";
import { addScript } from "../../scripts";
import { InMemoryWorkspace } from "../../workspaces";
import { Agent as CodeWriterAgent } from "../../code-writer";
import chalk from "chalk";

export const createOperation: AgentFunction = {
export const createScript: AgentFunction = {
definition: {
name: "createOperation",
description: `Create an operation using JavaScript.`,
name: "createScript",
description: `Create a script using JavaScript.`,
parameters: {
type: "object",
properties: {
namespace: {
type: "string",
description: "The namespace of the operation, e.g. fs.readFile"
description: "The namespace of the script, e.g. fs.readFile"
},
description: {
type: "string",
description: "The detailed description of the operation."
description: "The detailed description of the script."
},
arguments: {
type: "string",
description: "The arguments of the operation. E.g. '{ path: string, encoding: string }'. Use only what you need, no optional arguments."
description: "The arguments of the script. E.g. '{ path: string, encoding: string }'. Use only what you need, no optional arguments."
},
developerNote: {
type: "string",
description: "A note for the developer of the operation, if any."
description: "A note for the developer of the script, if any."
}
},
required: ["namespace", "description", "arguments"],
Expand All @@ -41,14 +41,14 @@ export const createOperation: AgentFunction = {
if (options.namespace.startsWith("agent.")) {
return {
ok: false,
result: `Cannot create an operation with namespace ${options.namespace}. Try searching for operations in that namespace instead.`,
result: `Cannot create an script with namespace ${options.namespace}. Try searching for script in that namespace instead.`,
}
}

const workspace = new InMemoryWorkspace();
const writer = new CodeWriterAgent(workspace);
console.log(chalk.yellow(`Creating operation '${options.namespace}'...`));
console.log(chalk.yellow(`Creating script '${options.namespace}'...`));

let iterator = writer.run(options.namespace, options.description, options.arguments, options.developerNote);

while(true) {
Expand All @@ -69,15 +69,15 @@ export const createOperation: AgentFunction = {
arguments: options.arguments,
code: index
};
addOperation(options.namespace, op);
addScript(options.namespace, op);

const candidates = [
op
];

return {
ok: true,
result: `Created the following operations:` +
result: `Created the following scripts:` +
`\n--------------\n` +
`${candidates.map((c) => `Namespace: ${c.name}\nArguments: ${c.arguments}\nDescription: ${c.description}`).join("\n--------------\n")}` +
`\n--------------\n`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { AgentFunction, WrapClient, functionCodeWrapper, nodeShims } from "../..";
import { JS_ENGINE_URI } from "../../constants";
import { getOperationByName } from "../../operations";
import { getScriptByName } from "../../scripts";

export const executeOperation: AgentFunction = {
export const executeScript: AgentFunction = {
definition: {
name: "executeOperation",
description: `Execute an operation.`,
name: "executeScript",
description: `Execute an script.`,
parameters: {
type: "object",
properties: {
namespace: {
type: "string",
description: "Namespace of the operation to execute"
description: "Namespace of the script to execute"
},
arguments: {
type: "string",
description: "The arguments to pass into the operation being executed.",
description: "The arguments to pass into the script being executed",
},
result: {
type: "string",
description: "The name of the variable to store the result of the operation"
description: "The name of the variable to store the result of the script"
}
},
required: ["name", "arguments", "result"],
Expand All @@ -35,16 +35,16 @@ export const executeOperation: AgentFunction = {
// if (!options.arguments) {
// return {
// ok: false,
// error: `No arguments provided for operation ${options.name}.`,
// error: `No arguments provided for script ${options.name}.`,
// };
// }

const operation = getOperationByName(options.namespace);
const script = getScriptByName(options.namespace);

if (!operation) {
if (!script) {
return {
ok: false,
error: `Operation ${options.namespace} not found.`,
error: `Script ${options.namespace} not found.`,
};
}

Expand All @@ -70,12 +70,12 @@ export const executeOperation: AgentFunction = {
} catch {
return {
ok: false,
error: `Invalid arguments provided for operation ${options.namespace}: '${options.arguments}' is not valid JSON!`,
error: `Invalid arguments provided for script ${options.namespace}: '${options.arguments}' is not valid JSON!`,
};
}

const invokeArgs = {
src: nodeShims + functionCodeWrapper(operation.code),
src: nodeShims + functionCodeWrapper(script.code),
globals: Object.keys(args).map((key) => ({
name: key,
value: JSON.stringify(args[key]),
Expand All @@ -89,7 +89,7 @@ export const executeOperation: AgentFunction = {
});

console.log("----------------");
console.log("Execute operation output", client.jsPromiseOutput);
console.log("Execute script output", client.jsPromiseOutput);
console.log("----------------");

if (result.ok && client.jsPromiseOutput.result) {
Expand All @@ -105,11 +105,11 @@ export const executeOperation: AgentFunction = {
}
: {
ok: false,
error: "No result returned from operation.",
error: "No result returned from script.",
}
: {
ok: false,
error: result.value.error + "\nCode: " + operation.code,
error: result.value.error + "\nCode: " + script.code,
}
: {
ok: false,
Expand Down
Loading
Loading