mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-05-30 23:26:49 +00:00
added write functionalities ie, swap and transfer
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
||||
import { gpt4o } from "../utils/model.js";
|
||||
import { solanaAgentState } from "../utils/state.js";
|
||||
import { gpt4o } from "../utils/model";
|
||||
import { solanaAgentState } from "../utils/state";
|
||||
import { TavilySearchResults } from "@langchain/community/tools/tavily_search";
|
||||
import { HumanMessage } from "@langchain/core/messages";
|
||||
|
||||
// Initialize tools array
|
||||
const searchTools = [];
|
||||
@@ -12,7 +11,7 @@ if (process.env.TAVILY_API_KEY) {
|
||||
searchTools.push(new TavilySearchResults());
|
||||
}
|
||||
|
||||
export const generalAgent = createReactAgent({
|
||||
const generalAgent = createReactAgent({
|
||||
llm: gpt4o,
|
||||
tools: searchTools,
|
||||
});
|
||||
@@ -24,9 +23,3 @@ export const generalistNode = async (state: typeof solanaAgentState.State) => {
|
||||
|
||||
return { messages: [...result.messages] };
|
||||
};
|
||||
|
||||
const messages = [new HumanMessage("What is the best way to buy SOL?")];
|
||||
|
||||
const result = await generalAgent.invoke({ messages });
|
||||
|
||||
console.log(result.messages);
|
||||
|
||||
23
examples/agent-kit-langgraph/src/agents/manager.ts
Normal file
23
examples/agent-kit-langgraph/src/agents/manager.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { prompt, parser } from "../prompts/manager";
|
||||
import { RunnableSequence } from "@langchain/core/runnables";
|
||||
import { solanaAgentState } from "../utils/state";
|
||||
import { gpt4o } from "../utils/model";
|
||||
|
||||
const chain = RunnableSequence.from([prompt, gpt4o, parser]);
|
||||
|
||||
export const managerNode = async (state: typeof solanaAgentState.State) => {
|
||||
const { messages } = state;
|
||||
|
||||
const result = await chain.invoke({
|
||||
formatInstructions: parser.getFormatInstructions(),
|
||||
messages: messages,
|
||||
});
|
||||
|
||||
const { isSolanaReadQuery, isSolanaWriteQuery, isGeneralQuery } = result;
|
||||
|
||||
return {
|
||||
isSolanaReadQuery,
|
||||
isSolanaWriteQuery,
|
||||
isGeneralQuery,
|
||||
};
|
||||
};
|
||||
25
examples/agent-kit-langgraph/src/agents/transferOrSwap.ts
Normal file
25
examples/agent-kit-langgraph/src/agents/transferOrSwap.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { gpt4o } from "../utils/model";
|
||||
import { agentKit } from "../utils/solanaAgent";
|
||||
import { solanaAgentState } from "../utils/state";
|
||||
import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
||||
import { SolanaTransferTool } from "solana-agent-kit/dist/langchain";
|
||||
import { transferSwapPrompt } from "../prompts/transferSwap";
|
||||
import { swapTool } from "../tools/swap";
|
||||
|
||||
const transferOrSwapAgent = createReactAgent({
|
||||
stateModifier: transferSwapPrompt,
|
||||
llm: gpt4o,
|
||||
tools: [new SolanaTransferTool(agentKit), swapTool],
|
||||
});
|
||||
|
||||
export const transferSwapNode = async (
|
||||
state: typeof solanaAgentState.State,
|
||||
) => {
|
||||
const { messages } = state;
|
||||
|
||||
const result = await transferOrSwapAgent.invoke({
|
||||
messages,
|
||||
});
|
||||
|
||||
return result;
|
||||
};
|
||||
Reference in New Issue
Block a user