-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add langchain project and langchainjs wire-up #7
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
Conversation
|
View your CI Pipeline Execution ↗ for commit b0c51ef.
☁️ Nx Cloud last updated this comment at |
This reverts commit 4fd4f40.
| const [isProcessing, setIsProcessing] = useState(false); | ||
|
|
||
| const handleSendMessage = async (content: string) => { | ||
| try { | ||
| setIsProcessing(true); | ||
|
|
||
| // Add user message | ||
| const userMessage: Message = { | ||
| id: (messages.length + 1).toString(), | ||
| sender: 'user', | ||
| content, | ||
| }; | ||
| setMessages((prev) => [...prev, userMessage]); | ||
|
|
||
| // Process message through LangGraph | ||
| const aiResponse = await runMessageGraph(content); | ||
|
|
||
| const handleSendMessage = (content: string) => { | ||
| const newMessage: Message = { | ||
| id: (messages.length + 1).toString(), // Simple ID generation for example | ||
| sender: 'user', | ||
| content, | ||
| }; | ||
| setMessages([...messages, newMessage]); | ||
| // Here you would typically trigger an AI response | ||
| // Add AI response | ||
| const aiMessage: Message = { | ||
| id: (messages.length + 2).toString(), | ||
| sender: 'ai', | ||
| content: aiResponse, | ||
| }; | ||
| setMessages((prev) => [...prev, aiMessage]); | ||
| } catch (error) { | ||
| console.error('Error processing message:', error); | ||
| // Add error message | ||
| const errorMessage: Message = { | ||
| id: (messages.length + 2).toString(), | ||
| sender: 'ai', | ||
| content: 'Sorry, I encountered an error processing your message.', | ||
| }; | ||
| setMessages((prev) => [...prev, errorMessage]); | ||
| } finally { | ||
| setIsProcessing(false); | ||
| } |
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.
Vibe-coded logic to get things working as a PoC
32ead04 to
2958562
Compare
0xApotheosis
left a comment
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.
Brilliant ser, I like the use of nx libraries and projects to separate concerns and allow for reusability.
Some comments, feel free to tackle in this PR, or in a later one in the name of progress.
| }).bindTools(tools); | ||
|
|
||
| // Define the function that determines whether to continue or not | ||
| function shouldContinue({ messages }: typeof MessagesAnnotation.State) { |
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.
Is there a tooling reason we don't use const/arrow function styles here, or just because this is LLM generated code for now?
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.
No reason, absolutely could! Will tackle in the follow-up PR not to rug the stack 🙏🏽
| const workflow = new StateGraph(MessagesAnnotation) | ||
| .addNode('agent', callModel) | ||
| .addEdge(START, 'agent') | ||
| .addNode('tools', toolNode) | ||
| .addEdge('tools', 'agent') | ||
| .addConditionalEdges('agent', shouldContinue); |
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.
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.
One thing to note here @0xApotheosis - langchain project and the webapp do work a bit differently because of the use of the (deprecated) system prompts in langchain projecs mostly, I haven't really gone back to it on the follow-up PR which wires up things a bit more, but it still exists for our convenience.
Not sure if we'll end up using the langchain project in the end (i.e langsmith app + https://agentchat.vercel.app/) but if we do, we'll probably want to ensure that we don't go with langgraph ReAct flavour there (reason + act) but rather go with the legacy langchain agents flow i.e the same used in the webapp, to ensure that the two models work similarly.
apps/langchain/static/studio.png
Outdated
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.
Should this be ignored?
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.
Seems to only be used for the README so might as well remove it 🙏🏽
b0c51ef
| import qs from 'qs'; | ||
| import { PortalsResponse, TokenSearchResult } from './types'; | ||
|
|
||
| export const tokensSearch = tool( |
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.
From a developer experience perspective we might want to use a pattern that separated the function param from the fields param, e.g.
const fn = ...
const fields = ...
export const tokenSearch = tool(fn, fields)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.
Happy to tackle in the follow-up PR as a few things change there tools-wise!
| - gnosis | ||
| - base | ||
| Use text proximity i.e if the user says on Binance Smart Chain, they mean bsc, if they say Avax, they mean avalanche, etc. |
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.
🧠

Description
This adds langchain as a separate project, taken from https://github.com/gomesalexandre/shapeshift-langchainjs
Also
nx formatdoing somecargo fmtstyle lint on the whole projectNotes:
Since there is a lot of boilerplate, here is the files you want to explicitly look at, mainly:
apps/langchain/src/agent/graph.ts- the agent graph for the agent running as a dedicated langgraph project. Don't focus on agent/tool logic there, it exists just as a PoC for now.apps/agentic-chat/src/lib/langchain.ts- the in-browser agent i.e the one that's actually consumed by the app/tools- agentic tools as a nx utils package (bebop rate and tokens search with portals), shared between the agentic standalone app and the agentic chat/utils- various utils as a nx utils package (BN utils for now), shared between the agentic standalone app and the agentic chatIssue
Testing
yarnnpx nx build @agentic-chat/utils && npx nx build @agentic-chat/toolscp .env.example .envand populate Portals and OpenAPI API keysLanggraph app
npx nx run langchain:devChat UI
npx nx serve agentic-chat