diff --git a/examples/agent-kit-langgraph/README.json b/examples/agent-kit-langgraph/README.json new file mode 100644 index 0000000..e69de29 diff --git a/examples/agent-kit-langgraph/index.ts b/examples/agent-kit-langgraph/index.ts new file mode 100644 index 0000000..8327600 --- /dev/null +++ b/examples/agent-kit-langgraph/index.ts @@ -0,0 +1,6 @@ +import { StateGraph } from "@langchain/langgraph"; +import { solanaAgentState } from "./utils/state"; + +const workflow = new StateGraph(solanaAgentState); + +export const graph = workflow.compile(); diff --git a/examples/agent-kit-langgraph/langgraph.json b/examples/agent-kit-langgraph/langgraph.json new file mode 100644 index 0000000..1e630f6 --- /dev/null +++ b/examples/agent-kit-langgraph/langgraph.json @@ -0,0 +1,7 @@ +{ + "graphs": { + "solana-agent": "./index.ts:graph" + }, + "env": ".env", + "node_version": "20" +} \ No newline at end of file diff --git a/examples/agent-kit-langgraph/utils/model.ts b/examples/agent-kit-langgraph/utils/model.ts new file mode 100644 index 0000000..7ab8d15 --- /dev/null +++ b/examples/agent-kit-langgraph/utils/model.ts @@ -0,0 +1,12 @@ +import { ChatOpenAI } from "@langchain/openai"; +import "dotenv/config"; + +export const gpt4o = new ChatOpenAI({ + modelName: "gpt-4o", + apiKey: process.env.OPENAI_API_KEY!, +}); + +export const gpt4oMini = new ChatOpenAI({ + modelName: "gpt-4o-mini", + apiKey: process.env.OPENAI_API_KEY!, +}); diff --git a/examples/agent-kit-langgraph/utils/route.ts b/examples/agent-kit-langgraph/utils/route.ts new file mode 100644 index 0000000..e69de29 diff --git a/examples/agent-kit-langgraph/utils/solanaAgent.ts b/examples/agent-kit-langgraph/utils/solanaAgent.ts new file mode 100644 index 0000000..eccdd76 --- /dev/null +++ b/examples/agent-kit-langgraph/utils/solanaAgent.ts @@ -0,0 +1,7 @@ +import { SolanaAgentKit } from "../../../src/agent"; + +export const agentKit = new SolanaAgentKit( + process.env.SOLANA_PRIVATE_KEY!, + process.env.RPC_URL!, + process.env.OPENAI_API_KEY!, +); diff --git a/examples/agent-kit-langgraph/utils/state.ts b/examples/agent-kit-langgraph/utils/state.ts new file mode 100644 index 0000000..ed4a1be --- /dev/null +++ b/examples/agent-kit-langgraph/utils/state.ts @@ -0,0 +1,25 @@ +import { Annotation } from "@langchain/langgraph"; +import { BaseMessage } from "@langchain/core/messages"; +import { messagesStateReducer } from "@langchain/langgraph"; + +export const solanaAgentState = Annotation.Root({ + messages: Annotation({ + reducer: messagesStateReducer, + default: () => [], + }), + + isSolanaReadQuery: Annotation({ + reducer: (x, y) => y ?? x ?? false, + default: () => false, + }), + + isSolanaWriteQuery: Annotation({ + reducer: (x, y) => y ?? x ?? false, + default: () => false, + }), + + isGeneralQuery: Annotation({ + reducer: (x, y) => y ?? x ?? false, + default: () => false, + }), +}); diff --git a/package.json b/package.json index abd3301..63597c1 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,9 @@ "dependencies": { "@bonfida/spl-name-service": "^3.0.7", "@coral-xyz/anchor": "0.29", - "@langchain/core": "^0.3.18", + "@langchain/core": "^0.3.26", "@langchain/groq": "^0.1.2", - "@langchain/langgraph": "^0.2.27", + "@langchain/langgraph": "^0.2.34", "@langchain/openai": "^0.3.13", "@lightprotocol/compressed-token": "^0.17.1", "@lightprotocol/stateless.js": "^0.17.1", @@ -56,13 +56,13 @@ "@types/bn.js": "^5.1.5", "@types/chai": "^5.0.1", "@types/node": "^22.9.0", - "ts-node": "^10.9.2", - "typescript": "^5.7.2", + "@typescript-eslint/eslint-plugin": "^7.0.0", + "@typescript-eslint/parser": "^7.0.0", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", "eslint-plugin-prettier": "^5.1.3", - "@typescript-eslint/eslint-plugin": "^7.0.0", - "@typescript-eslint/parser": "^7.0.0", - "prettier": "^3.2.5" + "prettier": "^3.2.5", + "ts-node": "^10.9.2", + "typescript": "^5.7.2" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ddfc583..8df6c67 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,13 +15,13 @@ importers: specifier: '0.29' version: 0.29.0(bufferutil@4.0.8)(utf-8-validate@5.0.10) '@langchain/core': - specifier: ^0.3.18 + specifier: ^0.3.26 version: 0.3.26(openai@4.77.0(zod@3.24.1)) '@langchain/groq': specifier: ^0.1.2 version: 0.1.2(@langchain/core@0.3.26(openai@4.77.0(zod@3.24.1))) '@langchain/langgraph': - specifier: ^0.2.27 + specifier: ^0.2.34 version: 0.2.34(@langchain/core@0.3.26(openai@4.77.0(zod@3.24.1))) '@langchain/openai': specifier: ^0.3.13