-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from polywrap/developer-agent
feat: dev-agent
- Loading branch information
Showing
49 changed files
with
604 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from "./AgentProtocolWorkspace"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "@evo-ninja/agent-debug", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"main": "./build/index.js", | ||
"scripts": { | ||
"build": "rimraf build && tsc" | ||
}, | ||
"dependencies": { | ||
"@evo-ninja/agent-utils": "~0.1.0" | ||
}, | ||
"devDependencies": { | ||
"rimraf": "~5.0.1", | ||
"ts-node": "10.9.1", | ||
"typescript": "4.9.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../tsconfig", | ||
"compilerOptions": { | ||
"outDir": "build" | ||
}, | ||
"include": [ | ||
"./src/**/*.ts" | ||
], | ||
"exclude": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "@evo-ninja/agent-utils-fs", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"main": "./build/index.js", | ||
"scripts": { | ||
"build": "rimraf build && tsc" | ||
}, | ||
"dependencies": { | ||
"@evo-ninja/agent-utils": "~0.1.0" | ||
}, | ||
"devDependencies": { | ||
"rimraf": "~5.0.1", | ||
"ts-node": "10.9.1", | ||
"typescript": "4.9.5" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../tsconfig", | ||
"compilerOptions": { | ||
"outDir": "build" | ||
}, | ||
"include": [ | ||
"./src/**/*.ts" | ||
], | ||
"exclude": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from "./agent-plugin"; | ||
export * from "./js-engine"; | ||
export * from "./wrap-client"; | ||
export * from "./Scripts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/__tests__/test-cases/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "@evo-ninja/dev-agent", | ||
"version": "0.1.0", | ||
"license": "MIT", | ||
"main": "./build/index.js", | ||
"scripts": { | ||
"build": "rimraf build && tsc", | ||
"test": "jest --runInBand --verbose --rootDir . --config ../../jest.config.js" | ||
}, | ||
"dependencies": { | ||
"@polywrap/result": "~0.12.0", | ||
"@evo-ninja/agent-utils": "~0.1.0" | ||
}, | ||
"devDependencies": { | ||
"@types/jest": "29.5.0", | ||
"@evo-ninja/agent-debug": "~0.1.0", | ||
"@evo-ninja/agent-utils-fs": "~0.1.0", | ||
"gpt-tokenizer": "~2.1.1", | ||
"jest": "29.5.0", | ||
"rimraf": "~5.0.1", | ||
"ts-jest": "29.1.1", | ||
"ts-node": "10.9.1", | ||
"typescript": "4.9.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { | ||
Chat, | ||
LlmApi, | ||
Scripts, | ||
WrapClient, | ||
Workspace | ||
} from "@evo-ninja/agent-utils"; | ||
|
||
export interface AgentContext { | ||
llm: LlmApi; | ||
chat: Chat; | ||
workspace: Workspace; | ||
scripts: Scripts; | ||
client: WrapClient; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { AgentContext } from "./AgentContext"; | ||
import { agentFunctions } from "./agent-functions"; | ||
import { INITIAL_PROMP, GOAL_PROMPT, LOOP_PREVENTION_PROMPT } from "./prompts"; | ||
|
||
import { | ||
Agent, | ||
AgentOutput, | ||
Chat, | ||
RunResult, | ||
LlmApi, | ||
Scripts, | ||
Logger, | ||
Workspace, | ||
WrapClient, | ||
agentPlugin, | ||
basicFunctionCallLoop, | ||
ExecuteAgentFunctionCalled | ||
} from "@evo-ninja/agent-utils"; | ||
import { ResultErr } from "@polywrap/result"; | ||
|
||
export class DevAgent implements Agent { | ||
private readonly context: AgentContext; | ||
|
||
constructor( | ||
llm: LlmApi, | ||
chat: Chat, | ||
workspace: Workspace, | ||
scripts: Scripts, | ||
private readonly logger: Logger | ||
) { | ||
this.context = { | ||
llm, | ||
chat, | ||
scripts, | ||
workspace, | ||
client: new WrapClient( | ||
workspace, | ||
this.logger, | ||
agentPlugin({ logger: this.logger }) | ||
), | ||
}; | ||
} | ||
|
||
public get workspace(): Workspace { | ||
return this.context.workspace; | ||
} | ||
|
||
public async* run( | ||
goal: string | ||
): AsyncGenerator<AgentOutput, RunResult, string | undefined> { | ||
const { chat } = this.context; | ||
try { | ||
chat.persistent("system", INITIAL_PROMP()); | ||
chat.persistent("user", GOAL_PROMPT(goal)); | ||
|
||
return yield* basicFunctionCallLoop( | ||
this.context, | ||
agentFunctions, | ||
(functionCalled: ExecuteAgentFunctionCalled) => { | ||
const terminationFunctions = [ | ||
"agent_onGoalAchieved", | ||
"agent_onGoalFailed" | ||
]; | ||
return terminationFunctions.includes(functionCalled.name); | ||
}, | ||
LOOP_PREVENTION_PROMPT | ||
); | ||
} catch (err) { | ||
this.logger.error(err); | ||
return ResultErr("Unrecoverable error encountered."); | ||
} | ||
} | ||
} |
Oops, something went wrong.