-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stepless model/network/agent instantiations (#24)
* Upgrade to `inngest@pr-756` * Strip models, use `inngest` `AiAdapter` instead * Update demo * Exploration * Add `createRoutingAgent`, refactor state, messages, and routing * Don't set routing model, and always inject into run if unset * Allow tool choice of "auto", "any", or forcing of particular tools * WIP: SWEBench * Fix `step` type errors * Make stateful `.withModel()` return a new `Agent` * nit in readfile tool * Updates to swebench to add code editing agents * Pull out to make stateless * Merge * Use `@inngest/agent-kit` for imports * Separate network instantiation * Make `Network` entirely stateless * Create ten-apes-argue.md --------- Co-authored-by: Tony Holdstock-Brown <[email protected]>
- Loading branch information
1 parent
a1fa17b
commit f7158e4
Showing
30 changed files
with
688 additions
and
651 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@inngest/agent-kit": minor | ||
--- | ||
|
||
Stepless model/network/agent instantiations |
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
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,6 @@ | ||
import { createAgent } from "@inngest/agent-kit"; | ||
|
||
createAgent({ | ||
name: "setup", | ||
system: "This is a system prompt", | ||
}); |
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 |
---|---|---|
@@ -1,15 +1,8 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import { execSync } from "child_process"; | ||
import fs from "fs"; | ||
import { execSync } from 'child_process'; | ||
import { EventSchemas, Inngest } from "inngest"; | ||
import { z } from "zod"; | ||
import { | ||
createNetwork, | ||
anthropic, | ||
State, | ||
} from "../../src/index"; | ||
import { Inngest, EventSchemas } from "inngest"; | ||
import { planningAgent } from "./agents/planner"; | ||
import { editingAgent } from "./agents/editor"; | ||
import { codeWritingNetwork } from "./networks/codeWritingNetwork"; | ||
|
||
export const inngest = new Inngest({ | ||
id: "agents", | ||
|
@@ -20,16 +13,15 @@ export const inngest = new Inngest({ | |
base_commit: z.string(), | ||
environment_setup_commit: z.string(), | ||
problem_statement: z.string(), | ||
}) | ||
}), | ||
}, | ||
}), | ||
}); | ||
|
||
export const fn = inngest.createFunction( | ||
{ id: "agent", retries: 2, }, | ||
{ id: "agent", retries: 2 }, | ||
{ event: "swebench/run" }, | ||
async ({ event, step }) => { | ||
|
||
// This is some basic stuff to initialize and set up the repos | ||
// for the swebench test. | ||
// | ||
|
@@ -38,57 +30,26 @@ export const fn = inngest.createFunction( | |
await step.run("clone repo", async () => { | ||
// Check if the dir already exists. | ||
if (fs.existsSync(dir)) { | ||
return | ||
return; | ||
} | ||
console.log("creating repo"); | ||
fs.mkdirSync(dir, { recursive: true }); | ||
execSync(`cd ${dir} && git init`); | ||
execSync(`cd ${dir} && git remote add origin [email protected]:${event.data.repo}.git`); | ||
execSync( | ||
`cd ${dir} && git remote add origin [email protected]:${event.data.repo}.git` | ||
); | ||
}); | ||
|
||
await step.run("check out commit", async () => { | ||
console.log("checking out commit"); | ||
execSync(`cd ${dir} && git fetch origin ${event.data.base_commit} --depth=1`); | ||
execSync( | ||
`cd ${dir} && git fetch origin ${event.data.base_commit} --depth=1` | ||
); | ||
execSync(`cd ${dir} && git reset --hard FETCH_HEAD`); | ||
}); | ||
|
||
// Use Claude as the base model of the network. | ||
const model = anthropic({ | ||
model: "claude-3-5-haiku-latest", | ||
max_tokens: 1000, | ||
step: step as any, | ||
}); | ||
|
||
// Create new network state, and set the repo we're editing directly from the event | ||
// input. | ||
const state = new State(); | ||
state.kv.set("repo", event.data.repo); | ||
|
||
const network = createNetwork({ | ||
agents: [planningAgent, editingAgent], | ||
defaultModel: model, | ||
state, | ||
}); | ||
await network.run(event.data.problem_statement, (opts) => { | ||
if (opts.network.state.kv.get("done")) { | ||
// We're done editing. This is set when the editing agent finishes | ||
// implementing the plan. | ||
// | ||
// At this point, we should hand off to another agent that tests, critiques, | ||
// and validates the edits. | ||
return; | ||
} | ||
|
||
// If there's a plan, we should switch to the editing agent to begin implementing. | ||
// | ||
// This lets us separate the concerns of planning vs editing, including using differing | ||
// prompts and tools at various stages of the editing process. | ||
if (opts.network.state.kv.get("plan") !== undefined) { | ||
return editingAgent; | ||
} | ||
|
||
// By default, use the planning agent. | ||
return planningAgent; | ||
await codeWritingNetwork.run(event.data.problem_statement, { | ||
state: { repo: event.data.repo }, | ||
}); | ||
}, | ||
} | ||
); |
Oops, something went wrong.