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

Langgraph Agent - ML4Bio #280

Draft
wants to merge 146 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
90a2e5e
adding minimal on_new_PR webhook for Github lil-jr-dev
KastanDay Aug 11, 2023
2e8d3ff
debug env vars
KastanDay Aug 11, 2023
78bfe38
fixed env vars
KastanDay Aug 11, 2023
c048e09
refactor github initialization
KastanDay Aug 11, 2023
78d7e7c
fix repo name
KastanDay Aug 11, 2023
bebd6dc
fixing repo parsing from json
KastanDay Aug 11, 2023
2864486
fixing repo parsing from json
KastanDay Aug 11, 2023
7048df2
add functions for issues and PRs. Rework auth for GH Auth
KastanDay Aug 11, 2023
b44ce17
fix the issue vs issues spelling
KastanDay Aug 11, 2023
de4e67d
working on fixing issues
KastanDay Aug 11, 2023
1c306c1
fixing up the issue and comment handlers
KastanDay Aug 11, 2023
cc19161
fixing issue comments
KastanDay Aug 11, 2023
fd4bec6
fixing paylods
KastanDay Aug 11, 2023
78a2ed0
don't reply to own comments
KastanDay Aug 11, 2023
46472de
no inf loops, and responding to new issues should finally work
KastanDay Aug 11, 2023
18095bb
handle conditional JSON blobs better with .get()
KastanDay Aug 11, 2023
b20b60c
typo
KastanDay Aug 11, 2023
ad21acb
working responses to new Issues, new PRs and new comments on each
KastanDay Aug 11, 2023
5e30753
MAJOR push: adding agents that respond to new PRs and new Issues. No …
KastanDay Aug 11, 2023
7700e20
major push: first draft of working MVP. Create an issue -> get a PR
KastanDay Aug 12, 2023
5bc16f4
minor type fix
KastanDay Aug 12, 2023
b8c4f7a
set langchain to my own fork
KastanDay Aug 12, 2023
b1c55a0
set langchain to my own fork, with proper branch
KastanDay Aug 12, 2023
5ac47a2
adding bot for on-pr-comment hook
KastanDay Aug 12, 2023
390674a
add bot for issue comments, have an MVP for the WHOLE STACK now. woohoo!
KastanDay Aug 12, 2023
1543863
typo fix
KastanDay Aug 12, 2023
30b10de
add error messages as github comments
KastanDay Aug 12, 2023
a6cf7e1
fix branch name in new issue comment
KastanDay Aug 12, 2023
fa971e2
adding automatic retries to the GH agents on-comment runs
KastanDay Aug 12, 2023
b06520d
minor type fix
KastanDay Aug 12, 2023
691e170
refine bot retry mechanism
KastanDay Aug 12, 2023
f4dbd09
wonderful refactor of bot responsibilities. GH_Agent is now a more re…
KastanDay Aug 12, 2023
d4c69d8
spelling typo
KastanDay Aug 12, 2023
b982acf
spelling typo
KastanDay Aug 12, 2023
5022221
add traceback exception
KastanDay Aug 12, 2023
c737b4c
add traceback exception
KastanDay Aug 12, 2023
8fb51fb
improve traceback exception, improve branch handling
KastanDay Aug 14, 2023
9bbb688
adding run file so imports work
KastanDay Sep 20, 2023
772afbc
use relative imports, remove the need to update python path
KastanDay Sep 20, 2023
4bf7948
fix relative imports and failing VectorStoreRetriever import from lan…
KastanDay Sep 29, 2023
dbc10c5
major code cleanup, add langsmith tracing
KastanDay Oct 1, 2023
66fed91
Completed Setup UIUC.chat vectorstore retrievers for all the common t…
KastanDay Oct 11, 2023
bc37e20
add several bio packages as vectorstore retriever tools
KastanDay Oct 17, 2023
c4f146c
Plan and execute agent
rohan-uiuc Oct 18, 2023
fd3f5b0
Merge branch 'github_agent_webhooks' of github.com:UIUC-Chatbot/ai-ta…
rohan-uiuc Oct 18, 2023
3ea9ec3
Add support for Azure models, add LangSmith link to github comment, v…
KastanDay Nov 1, 2023
239d5ec
Major code cleanup, deleting old code. Added README.
KastanDay Nov 1, 2023
b5f65ac
Further code cleanup, and full implementation of LangSmith real-time …
KastanDay Nov 2, 2023
9654c05
Fixed the 'follow bot's progress in real time' link
KastanDay Nov 2, 2023
6f69756
utils code cleanup
KastanDay Nov 2, 2023
e19159a
Experimental: Adding newrelic logging, major railway.json change
KastanDay Nov 2, 2023
59e58a9
setup newrelic-admin before installing telemetry
KastanDay Nov 2, 2023
5fec929
Maybe it's just pip3?
KastanDay Nov 2, 2023
cd9a019
attempting to change the order of the build steps
KastanDay Nov 2, 2023
f937eec
moving newrelic phase into the phase
KastanDay Nov 2, 2023
34f1f8b
fix silly mistake of trying to run the program too early
KastanDay Nov 2, 2023
d27011b
python310 (instead of 3.8)
KastanDay Nov 2, 2023
d36951f
consolidate newrelic install command to original one-liner
KastanDay Nov 2, 2023
49887f2
INFRA ONLY, NO LOGS. attempt to add the license key better
KastanDay Nov 2, 2023
c489d8c
INFRA ONLY, NO LOGS
KastanDay Nov 2, 2023
12f02d3
INFRA ONLY, NO LOGS
KastanDay Nov 2, 2023
bb95ca5
Install worked... but infra staid 'unsupported'. trying to add back l…
KastanDay Nov 2, 2023
bc9dd6b
try to fix newrelic.ini path
KastanDay Nov 2, 2023
331a21b
try to fix newrelic.ini path v2
KastanDay Nov 2, 2023
2dd4431
try to fix newrelic.ini path v3
KastanDay Nov 2, 2023
e251c4b
try to fix newrelic.ini path v4
KastanDay Nov 2, 2023
ad0ba77
try to fix newrelic.ini path v5 -- very close, just removeing a doubl…
KastanDay Nov 2, 2023
bc33a90
Added custom code execution tool from autogen, integrated with plan&e…
rohan-uiuc Nov 2, 2023
4166236
Merge branch 'github_agent_webhooks' of github.com:UIUC-Chatbot/ai-ta…
rohan-uiuc Nov 2, 2023
616905f
change LangChain branch to our new internal Langchain fork
KastanDay Nov 2, 2023
133e9e2
add ray start --head to try to fix 'unable to start GCS' for ray
KastanDay Nov 2, 2023
e472d97
📜 update readme
KastanDay Nov 2, 2023
1417c5e
support custom langchain-experimental
KastanDay Nov 2, 2023
f58d232
fix langchain-experimental, and random log messages
KastanDay Nov 2, 2023
a67781b
2 spaces is the only way
KastanDay Nov 2, 2023
dcc1c91
Adding ability to fetch linked PRs from issues and vice-versa!
KastanDay Nov 3, 2023
abbaa08
First attempt at Dockerfile for code execution
KastanDay Nov 6, 2023
9b5db8b
Add cmd-line args to support Docker, add shell and filesystem tool
KastanDay Nov 6, 2023
2094625
Setting up docker image for each request (Issue/PR) (#133)
rohan-uiuc Nov 7, 2023
b69626a
WIP docker setup
rohan-uiuc Nov 8, 2023
5293f9b
Working docker setup
rohan-uiuc Nov 9, 2023
cdcec7c
Fix openai version
KastanDay Nov 7, 2023
be0d25f
adding langchainhub
KastanDay Nov 7, 2023
87f83f5
add MemGPT custom implementation plan
KastanDay Nov 14, 2023
4d0f5e3
Initial attempts at MemoryCallbacks
KastanDay Nov 14, 2023
7254d77
working M1 docker builds
KastanDay Nov 14, 2023
900a845
proper .env path in Dockerfile
KastanDay Nov 14, 2023
0900156
can't get .env from above Dockerfile... need to do in bash/python
KastanDay Nov 15, 2023
cbd9a7f
working docker builds
KastanDay Nov 15, 2023
c2cec4c
Changes for handling new comment opened
rohan-uiuc Nov 16, 2023
51e3d73
Improve Docker launching; much better image re-build on all code changes
KastanDay Nov 22, 2023
0964cc7
Revert to before reformat Docker utils @ 51e3d7373d8b412f468b61c275e…
KastanDay Nov 27, 2023
bc5054e
Replace Docker with E2B Sandbox for code and shell execution (#177)
KastanDay Dec 19, 2023
57eff15
langgraph experiment
minump Jan 22, 2024
c015c36
gitignore node modules
minump Jan 22, 2024
2be2b19
added to gitignore
minump Jan 26, 2024
0f2d9a8
removed custom file
minump Jan 26, 2024
41a25d4
add langgraph requirements
minump Jan 26, 2024
0dd9c98
use langgraph agent instead of ml4bio agent
minump Jan 26, 2024
da0106e
workflowAgnet with langgraph
minump Jan 26, 2024
40b4044
removed unwanted import
minump Jan 26, 2024
e10cb09
Add Trunk formatting, same as main branch. All files updated.
KastanDay Jan 29, 2024
432f5b1
Add requirements, beginning of prompt_function
KastanDay Jan 29, 2024
88aefdd
agentState not keeping track of intermediate steps
minump Feb 1, 2024
b8868a7
Updating requirements to make them compatible with langchain-openai==…
rohan-uiuc Feb 6, 2024
f549858
Major version updates: update reqs, update imports, fix e2b sandbox
KastanDay Feb 8, 2024
3da4f20
Clean up linting bugs
KastanDay Feb 8, 2024
104ba0d
changes to langggraph agent
minump Feb 12, 2024
59bce34
azureChat and OpenAIChat llm
minump Feb 12, 2024
099c991
Switch default model to Azure GPT-4-turbo-0125 better for coding
KastanDay Feb 14, 2024
effb850
fmt only
KastanDay Feb 14, 2024
27d3a9d
update requirements to install our fork of langchain-openai, not the …
KastanDay Feb 15, 2024
daab116
My test script for testing langgraph
KastanDay Feb 15, 2024
56aa9f3
demo notebook for replanning step
KastanDay Feb 15, 2024
1b1d339
Fix intermediate_steps double usage... add example of adding custom i…
KastanDay Feb 15, 2024
04a5a43
Integrating demo plan and execute notebook with existing agent
rohan-uiuc Feb 21, 2024
49b53f4
Changing function names since langchain has a regex validation for it.
rohan-uiuc Feb 21, 2024
d07d2ef
Updated test file for agent v2
rohan-uiuc Feb 22, 2024
88a898d
Updated the import to use the new agent and fixed typo in filename
rohan-uiuc Feb 22, 2024
cc7e845
Move github tool to Langchain_community repo, fix imports
KastanDay Feb 22, 2024
caaa7b7
minor prompt and variable changes
KastanDay Feb 22, 2024
4dd3547
Move to async endpoint, set max iterations to 100 (up from 25)
KastanDay Feb 22, 2024
154a4b7
gitignore
minump Mar 1, 2024
811d73a
lats test
minump Mar 1, 2024
7bfa51d
lats testing with separate planner and executor
minump Mar 11, 2024
586a86d
testing
minump Mar 15, 2024
2311c70
added r code run
minump Mar 21, 2024
ee2b12c
rcode e2b changes
minump Mar 22, 2024
9bac224
using langgraph agent v2
minump Jun 7, 2024
7e75879
updated requirements
minump Jun 7, 2024
9c02c56
Fix conflicting openai requirements
KastanDay Jun 14, 2024
3474e05
Trunk upgrade
KastanDay Jun 14, 2024
aab6681
Fix versions, add uv to pip install on Railway
KastanDay Jun 14, 2024
f57d7e5
Fix uv python version
KastanDay Jun 14, 2024
fce501b
Set VIRTUAL_ENV for uv
KastanDay Jun 14, 2024
32ed3a2
try uv --system for using pip without virtualenv
KastanDay Jun 14, 2024
25de90a
Upgrade uv for --system command added
KastanDay Jun 14, 2024
6960dfd
Upgrade uv for --system command added, use manual install instead of pip
KastanDay Jun 14, 2024
350912b
Give up on UV, sigh
KastanDay Jun 14, 2024
cc2c612
Comment out e2b codeintrepreter, deprecated
KastanDay Jun 14, 2024
504b48d
Add Flask[async] dep
KastanDay Jun 14, 2024
0a785df
Print payload so we can test locally
KastanDay Jun 14, 2024
4847a64
Add example payload for local testing
KastanDay Jun 14, 2024
6e24d64
Fully format all code using trunk
KastanDay Jun 14, 2024
ddb3128
Print payload so we can test locally
KastanDay Jun 14, 2024
41fce2c
Save payload to file
KastanDay Jun 14, 2024
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
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# don't sync coursera docs
coursera-dl/
*parsed.json
*wandb*
*ipynb*
*.pem

# don't expose env files
dummy.ipynb
.env
# Created by https://www.toptal.com/developers/gitignore/api/python
# Edit at https://www.toptal.com/developers/gitignore?templates=python
Expand Down Expand Up @@ -37,6 +39,8 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
.idea/
node_modules/

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down Expand Up @@ -116,7 +120,7 @@ celerybeat.pid

# Environments
.env
.venv
.venv*
env/
venv/
ENV/
Expand Down Expand Up @@ -164,3 +168,10 @@ pip-selfcheck.json

# End of https://www.toptal.com/developers/gitignore/api/python
.aider*

# Input/Output files
*payload*.json
*sample*.json

#DS Store
.DS_Store
16 changes: 8 additions & 8 deletions .rules/no-bugs.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Make sure our code follows these best practices, UNLESS there's a comment explaining why it's okay to break the rule.
1. Avoid typos.
2. Don't have like, really obvious bugs.
3. Don't store secrets in code.
4. Comment on code smells and bugs, suggest better 'best practices' ways to achieve the same result. No need to be too strict, but please help me learn.
5. Avoid dangerous stuff, like things that could lead to template injection, SQL injection, broken access control, or really anything that would show up as a CVE somewhere.
6. If something looks like not best practice, please show how to do it better. We want to learn and improve our code quality and use modern, elegant patterns and practices.
Make sure our code follows these best practices, UNLESS there's a comment explaining why it's okay to break the rule.

1. Avoid typos.
2. Don't have like, really obvious bugs.
3. Don't store secrets in code.
4. Comment on code smells and bugs, suggest better 'best practices' ways to achieve the same result. No need to be too strict, but please help me learn.
5. Avoid dangerous stuff, like things that could lead to template injection, SQL injection, broken access control, or really anything that would show up as a CVE somewhere.
6. If something looks like not best practice, please show how to do it better. We want to learn and improve our code quality and use modern, elegant patterns and practices.
9 changes: 9 additions & 0 deletions .trunk/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*out
*logs
*actions
*notifications
*tools
plugins
user_trunk.yaml
user.yaml
tmp
2 changes: 2 additions & 0 deletions .trunk/configs/.isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[settings]
profile=google
10 changes: 10 additions & 0 deletions .trunk/configs/.markdownlint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Autoformatter friendly markdownlint config (all formatting rules disabled)
default: true
blank_lines: false
bullet: false
html: false
indentation: false
line_length: false
spaces: false
url: false
whitespace: false
7 changes: 7 additions & 0 deletions .trunk/configs/.shellcheckrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enable=all
source-path=SCRIPTDIR
disable=SC2154

# If you're having issues with shellcheck following source, disable the errors via:
# disable=SC1090
# disable=SC1091
4 changes: 4 additions & 0 deletions .trunk/configs/.style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[style]
based_on_style = google
column_limit = 140
indent_width = 2
10 changes: 10 additions & 0 deletions .trunk/configs/.yamllint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rules:
quoted-strings:
required: only-when-needed
extra-allowed: ["{|}"]
empty-values:
forbid-in-block-mappings: true
forbid-in-flow-mappings: true
key-duplicates: {}
octal-values:
forbid-implicit-octal: true
5 changes: 5 additions & 0 deletions .trunk/configs/ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Generic, formatter-friendly config.
select = ["B", "D3", "E", "F"]

# Never enforce `E501` (line length violations). This should be handled by formatters.
ignore = ["E501"]
55 changes: 55 additions & 0 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This file controls the behavior of Trunk: https://docs.trunk.io/cli
# To learn more about the format of this file, see https://docs.trunk.io/reference/trunk-yaml
version: 0.1
cli:
version: 1.22.2
# Trunk provides extensibility via plugins. (https://docs.trunk.io/plugins)
plugins:
sources:
- id: trunk
ref: v1.6.0
uri: https://github.com/trunk-io/plugins
# Many linters and tools depend on runtimes - configure them here. (https://docs.trunk.io/runtimes)
runtimes:
enabled:
- [email protected]
- [email protected]
- [email protected]
# This is the section where you manage your linters. (https://docs.trunk.io/check/configuration)
# - [email protected] # too sensitive, causing failures that make devs skip checks.
lint:
enabled:
# - [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
# - [email protected]
- [email protected]
- [email protected]
- [email protected]
- git-diff-check
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
ignore:
- linters: [ALL]
paths:
- .github/**/*
- .trunk/**/*
- .rules/**/*
- mkdocs.yml
- .DS_Store
- .vscode/**/*
- README.md
actions:
enabled:
- trunk-announce
- trunk-check-pre-push
- trunk-fmt-pre-commit
- trunk-upgrade-available
72 changes: 72 additions & 0 deletions ai_ta_backend/agents/MemoryCallbacks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import os
from typing import Any, Dict, Union

from langchain.agents import AgentType
from langchain.agents import initialize_agent
from langchain.agents import load_tools
from langchain.callbacks.base import BaseCallbackHandler
from langchain.llms import OpenAI
from langchain.schema import AgentAction
from langchain.schema import AgentFinish
import supabase


class MemoryCallbackHandler(BaseCallbackHandler):

def __init__(self):
self.tool_in_progress = False # usage TBD

self.supabase_client = supabase.create_client( # type: ignore
supabase_url=os.getenv('SUPABASE_URL'), # type: ignore
supabase_key=os.getenv('SUPABASE_API_KEY')) # type: ignore

def on_tool_start(self, serialized: Dict[str, Any], input_str: str, **kwargs: Any) -> Any:
print(f"on_tool_start {serialized}")
self.tool_in_progress = True

def on_tool_end(self, output: str, **kwargs: Any) -> Any:
"""Run when LLM errors."""
print(f"On tool end: {output}")
if self.tool_in_progress:
self.tool_in_progress = False
print(f"Tool output: {output}")

def on_tool_error(self, error: Union[Exception, KeyboardInterrupt], **kwargs: Any) -> Any:
"""Run when LLM errors."""
pass

def on_llm_error(self, error: Union[Exception, KeyboardInterrupt], **kwargs: Any) -> Any:
"""Run when LLM errors."""
pass

def on_agent_action(self, action: AgentAction, **kwargs: Any) -> Any:
print(f"on_agent_action {action}")

def on_agent_finish(self, finish: AgentFinish, **kwargs: Any) -> Any:
print(f"on_agent_finish {finish}")

# def on_llm_start(
# self, serialized: Dict[str, Any], prompts: List[str], **kwargs: Any
# ) -> Any:
# print(f"on_llm_start {serialized}")

# def on_llm_new_token(self, token: str, **kwargs: Any) -> Any:
# print(f"on_new_token {token}")

# def on_chain_start(
# self, serialized: Dict[str, Any], inputs: Dict[str, Any], **kwargs: Any
# ) -> Any:
# print(f"on_chain_start {serialized['name']}")


if __name__ == "__main__":
# just for testing
handler1 = MemoryCallbackHandler()

llm = OpenAI(temperature=0, streaming=True)
tools = load_tools(["llm-math"], llm=llm)
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION)

# Callbacks for handler1 will be issued by every object involved in the
# Agent execution (llm, llmchain, tool, agent executor)
agent.run("What is 2 raised to the 0.235 power?", callbacks=[handler1])
Loading