mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-06-04 07:36:45 +00:00
fin
This commit is contained in:
22
examples/agent-kit-langgraph/src/agents/readAgent.ts
Normal file
22
examples/agent-kit-langgraph/src/agents/readAgent.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
||||
import { gpt4o } from "../utils/model";
|
||||
import { solanaAgentState } from "../utils/state";
|
||||
import { HumanMessage } from "@langchain/core/messages";
|
||||
import { agentKit } from "../utils/solanaAgent";
|
||||
import {
|
||||
SolanaBalanceTool,
|
||||
SolanaFetchPriceTool,
|
||||
} from "solana-agent-kit/dist/langchain";
|
||||
|
||||
const readAgent = createReactAgent({
|
||||
llm: gpt4o,
|
||||
tools: [new SolanaBalanceTool(agentKit), new SolanaFetchPriceTool(agentKit)],
|
||||
});
|
||||
|
||||
export const readNode = async (state: typeof solanaAgentState.State) => {
|
||||
const { messages } = state;
|
||||
|
||||
const result = await readAgent.invoke({ messages });
|
||||
|
||||
return { messages: [...result.messages] };
|
||||
};
|
||||
@@ -3,3 +3,7 @@ import { HumanMessage } from "@langchain/core/messages";
|
||||
export const generalQuestion = [
|
||||
new HumanMessage("Who is the president of Ecuador?"),
|
||||
];
|
||||
|
||||
export const solanaReadQuery = [new HumanMessage("what is the price of SOL")];
|
||||
|
||||
export const solanaWriteQuery = [new HumanMessage("swap 0.1 usdc to sol")];
|
||||
|
||||
@@ -3,6 +3,7 @@ import { solanaAgentState } from "./utils/state";
|
||||
import { generalistNode } from "./agents/generalAgent";
|
||||
import { transferSwapNode } from "./agents/transferOrSwap";
|
||||
import { managerNode } from "./agents/manager";
|
||||
import { readNode } from "./agents/readAgent";
|
||||
import { START, END } from "@langchain/langgraph";
|
||||
import { managerRouter } from "./utils/route";
|
||||
import { HumanMessage } from "@langchain/core/messages";
|
||||
@@ -11,15 +12,17 @@ const workflow = new StateGraph(solanaAgentState)
|
||||
.addNode("generalist", generalistNode)
|
||||
.addNode("manager", managerNode)
|
||||
.addNode("transferSwap", transferSwapNode)
|
||||
.addNode("read", readNode)
|
||||
.addEdge(START, "manager")
|
||||
.addConditionalEdges("manager", managerRouter)
|
||||
.addEdge("generalist", END)
|
||||
.addEdge("transferSwap", END);
|
||||
.addEdge("transferSwap", END)
|
||||
.addEdge("read", END);
|
||||
|
||||
export const graph = workflow.compile();
|
||||
|
||||
const result = await graph.invoke({
|
||||
messages: [new HumanMessage("swap 0.1 usdc to sol")],
|
||||
messages: [new HumanMessage("what is the price of SOL")],
|
||||
});
|
||||
|
||||
console.log(result);
|
||||
|
||||
@@ -8,6 +8,8 @@ export const managerRouter = (state: typeof solanaAgentState.State) => {
|
||||
return "generalist";
|
||||
} else if (isSolanaWriteQuery) {
|
||||
return "transferSwap";
|
||||
} else if (isSolanaReadQuery) {
|
||||
return "read";
|
||||
} else {
|
||||
return END;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user