-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add Reviewer agent to summarize PR. #54
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
48df5f7
Specify Weaviate schema (#49)
arihanv 88e74d3
dispatch coding agent
DexterStorey 80ce114
Setup commands for sandbox
arihanv 5088ffa
dispatch engineer instructions
DexterStorey 5b1cef8
fix: sandbox clone repo
arihanv 49d3193
fix: add git access token to sandbox
arihanv c01b888
fix: process.env usage
arihanv 5f0696c
engineer prompt
DexterStorey 5ddc312
Add reviewer agent for pull request
arihanv 3f8b119
feat: add error handling to reviewer
arihanv 72074e9
feat: create specific function for PR comments
arihanv 0da48d1
feat: turn code reviewer into an agent
arihanv 484e2f9
Fix labelling regression
tedspare f9092cc
Lint and minor refactors
tedspare 4a651be
Fix instruction updater
tedspare 707aac3
Merge branch 'staging' of https://github.com/RubricLab/maige into ari…
tedspare eea274f
Comment out dispatcher for now
tedspare File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Binary file not shown.
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 |
---|---|---|
|
@@ -5,14 +5,13 @@ import {SerpAPI} from 'langchain/tools' | |
import env from '~/env.mjs' | ||
import commentTool from '~/tools/comment' | ||
import execTool from '~/tools/exec' | ||
import githubTool from '~/tools/github' | ||
import updateInstructionsTool from '~/tools/updateInstructions' | ||
import {isDev} from '~/utils' | ||
|
||
const model = new ChatOpenAI({ | ||
modelName: 'gpt-4-1106-preview', | ||
openAIApiKey: env.OPENAI_API_KEY, | ||
temperature: 0.7 | ||
temperature: 0.3 | ||
}) | ||
|
||
export default async function engineer({ | ||
|
@@ -30,16 +29,34 @@ export default async function engineer({ | |
}) { | ||
const shell = await Sandbox.create({ | ||
apiKey: env.E2B_API_KEY, | ||
id: 'Nodejs', | ||
onStderr: data => console.error(data.line), | ||
onStdout: data => console.log(data.line) | ||
}) | ||
|
||
function preCmdCallback(cmd: string) { | ||
const tokenB64 = btoa(`pat:${env.GITHUB_ACCESS_TOKEN}`) | ||
const authFlag = `-c http.extraHeader="AUTHORIZATION: basic ${tokenB64}"` | ||
|
||
// Replace only first occurrence to avoid prompt injection | ||
// Otherwise "git log && echo 'git '" would print the token | ||
return cmd.replace('git ', `git ${authFlag} `) | ||
} | ||
|
||
const cloneName = `maige-${repoName.split('/')[1]}` | ||
|
||
const repoSetup = preCmdCallback( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should these changes be in the scope of this PR? |
||
`git config --global user.email "${env.GITHUB_EMAIL}" && git config --global user.name "${env.GITHUB_USERNAME}" && git clone https://github.com/${repoName}.git ${cloneName} && cd ${cloneName} && git log -n 3` | ||
) | ||
|
||
const clone = await shell.process.start({ | ||
cmd: repoSetup | ||
}) | ||
await clone.wait() | ||
|
||
const tools = [ | ||
new SerpAPI(), | ||
commentTool({octokit}), | ||
updateInstructionsTool({octokit, prisma, customerId, repoName}), | ||
githubTool({octokit}), | ||
execTool({ | ||
name: 'shell', | ||
description: 'Executes a shell command.', | ||
|
@@ -48,7 +65,7 @@ export default async function engineer({ | |
execTool({ | ||
name: 'git', | ||
description: | ||
'Executes a shell command with git logged in. Commands must begin with "git ".', | ||
'Executes a shell command with git already logged in and configured. Commands must begin with "git ".', | ||
setupCmd: `git config --global user.email "${env.GITHUB_EMAIL}" && git config --global user.name "${env.GITHUB_USERNAME}"`, | ||
preCmdCallback: (cmd: string) => { | ||
const tokenB64 = btoa(`pat:${env.GITHUB_ACCESS_TOKEN}`) | ||
|
@@ -64,16 +81,19 @@ export default async function engineer({ | |
|
||
const prefix = `You are a senior AI engineer. | ||
You use the internet, shell, and git to solve problems. | ||
You like to read the docs. | ||
Only use necessary tools. | ||
A shell has been initialized for your session and has a file system. | ||
The repo has already been cloned and you can use ls or cat to view files, touch, mkdir, echo, etc. | ||
Your job is to write code, commit it to a new branch, and open a pull request. | ||
Always commit code before terminating. | ||
YOUR FIRST STEP SHOULD ALWAYS BE TO RUN ls | ||
{agent_scratchpad} | ||
`.replaceAll('\n', ' ') | ||
|
||
const executor = await initializeAgentExecutorWithOptions(tools, model, { | ||
agentType: 'openai-functions', | ||
returnIntermediateSteps: isDev, | ||
handleParsingErrors: true, | ||
verbose: isDev, | ||
verbose: false, | ||
agentArgs: { | ||
prefix | ||
} | ||
|
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,47 @@ | ||
import {initializeAgentExecutorWithOptions} from 'langchain/agents' | ||
import {ChatOpenAI} from 'langchain/chat_models/openai' | ||
import {SerpAPI} from 'langchain/tools' | ||
import env from '~/env.mjs' | ||
import {prComment} from '~/tools/prComment' | ||
import {isDev} from '~/utils' | ||
|
||
const model = new ChatOpenAI({ | ||
modelName: 'gpt-4-1106-preview', | ||
openAIApiKey: env.OPENAI_API_KEY, | ||
temperature: 0.3 | ||
}) | ||
|
||
export default async function reviewer({ | ||
input, | ||
octokit, | ||
pullId | ||
}: { | ||
input: string | ||
octokit: any | ||
pullId: string | ||
}) { | ||
const tools = [new SerpAPI(), prComment({octokit, pullId})] | ||
|
||
const prefix = ` | ||
You are senior engineer reviewing a Pull Request in GitHub made by a junior engineer. | ||
You MUST leave a comment on the PR according to the user's instructions using the prComment function. | ||
Format your answer beautifully using markdown suitable for GitHub. | ||
DO NOT use any emojis or non-Ascii characters. | ||
{agent_scratchpad} | ||
`.replaceAll('\n', ' ') | ||
|
||
const executor = await initializeAgentExecutorWithOptions(tools, model, { | ||
agentType: 'openai-functions', | ||
returnIntermediateSteps: isDev, | ||
handleParsingErrors: true, | ||
verbose: false, | ||
agentArgs: { | ||
prefix | ||
} | ||
}) | ||
|
||
const result = await executor.call({input}) | ||
const {output} = result | ||
|
||
return output | ||
} |
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,39 @@ | ||
import {DynamicStructuredTool} from 'langchain/tools' | ||
import {z} from 'zod' | ||
import engineer from '~/agents/engineer' | ||
/** | ||
* Execute a shell command | ||
*/ | ||
export default function dispatchEngineer({ | ||
octokit, | ||
prisma, | ||
customerId, | ||
repoName | ||
}: { | ||
octokit: any | ||
prisma: any | ||
customerId: string | ||
repoName: string | ||
}) { | ||
return new DynamicStructuredTool({ | ||
description: 'Dispatch an engineer to work on an issue', | ||
func: async ({input}) => { | ||
console.log('DISPATCHING ENGINEER') | ||
engineer({ | ||
input, | ||
octokit, | ||
prisma, | ||
customerId, | ||
repoName | ||
}) | ||
// await new Promise(resolve => setTimeout(resolve, 1000)) | ||
return 'dispatched' | ||
}, | ||
name: 'dispatchEngineer', | ||
schema: z.object({ | ||
input: z | ||
.string() | ||
.describe('specific, detailed instructions for the engineer.') | ||
}) | ||
}) | ||
} |
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,29 @@ | ||
import {DynamicStructuredTool} from 'langchain/tools' | ||
import {z} from 'zod' | ||
import {addComment} from '~/utils/github' | ||
|
||
/** | ||
* Comment on an issue | ||
*/ | ||
export function prComment({octokit, pullId}: {octokit: any; pullId: string}) { | ||
return new DynamicStructuredTool({ | ||
description: 'Adds a comment to a PR', | ||
func: async ({comment, severity}) => { | ||
const footer = `By [Maige](https://maige.app). How's my driving?` | ||
const res = await addComment({ | ||
octokit, | ||
issueId: pullId, | ||
comment: `${comment}\nThis is a Level ${severity} problem.\n\n${footer}` | ||
}) | ||
return JSON.stringify(res) | ||
}, | ||
name: 'prComment', | ||
schema: z.object({ | ||
comment: z.string().describe('The comment to add'), | ||
severity: z | ||
.number() | ||
.optional() | ||
.describe('The severity of the needed fix on a scale of 1-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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only downstream effect was in
prisma.project.update({ where: { ... name: repoName } ... })
in theupdateInstructions
tool