mirror of
https://github.com/d0zingcat/solana-agent-kit.git
synced 2026-06-01 07:36:46 +00:00
added pnpm
This commit is contained in:
32
examples/agent-kit-langgraph/src/agents/generalAgent.ts
Normal file
32
examples/agent-kit-langgraph/src/agents/generalAgent.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { createReactAgent } from "@langchain/langgraph/prebuilt";
|
||||
import { gpt4o } from "../utils/model.js";
|
||||
import { solanaAgentState } from "../utils/state.js";
|
||||
import { TavilySearchResults } from "@langchain/community/tools/tavily_search";
|
||||
import { HumanMessage } from "@langchain/core/messages";
|
||||
|
||||
// Initialize tools array
|
||||
const searchTools = [];
|
||||
|
||||
// Only add Tavily search if API key is available
|
||||
if (process.env.TAVILY_API_KEY) {
|
||||
searchTools.push(new TavilySearchResults());
|
||||
}
|
||||
|
||||
export const generalAgent = createReactAgent({
|
||||
llm: gpt4o,
|
||||
tools: searchTools,
|
||||
});
|
||||
|
||||
export const generalistNode = async (state: typeof solanaAgentState.State) => {
|
||||
const { messages } = state;
|
||||
|
||||
const result = await generalAgent.invoke({ messages });
|
||||
|
||||
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);
|
||||
6
examples/agent-kit-langgraph/src/index.ts
Normal file
6
examples/agent-kit-langgraph/src/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { StateGraph } from "@langchain/langgraph";
|
||||
import { solanaAgentState } from "./utils/state";
|
||||
|
||||
const workflow = new StateGraph(solanaAgentState);
|
||||
|
||||
export const graph = workflow.compile();
|
||||
12
examples/agent-kit-langgraph/src/utils/model.ts
Normal file
12
examples/agent-kit-langgraph/src/utils/model.ts
Normal file
@@ -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!,
|
||||
});
|
||||
0
examples/agent-kit-langgraph/src/utils/route.ts
Normal file
0
examples/agent-kit-langgraph/src/utils/route.ts
Normal file
7
examples/agent-kit-langgraph/src/utils/solanaAgent.ts
Normal file
7
examples/agent-kit-langgraph/src/utils/solanaAgent.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { SolanaAgentKit } from "solana-agent-kit";
|
||||
|
||||
export const agentKit = new SolanaAgentKit(
|
||||
process.env.SOLANA_PRIVATE_KEY!,
|
||||
process.env.RPC_URL!,
|
||||
process.env.OPENAI_API_KEY!,
|
||||
);
|
||||
25
examples/agent-kit-langgraph/src/utils/state.ts
Normal file
25
examples/agent-kit-langgraph/src/utils/state.ts
Normal file
@@ -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<BaseMessage[]>({
|
||||
reducer: messagesStateReducer,
|
||||
default: () => [],
|
||||
}),
|
||||
|
||||
isSolanaReadQuery: Annotation<boolean>({
|
||||
reducer: (x, y) => y ?? x ?? false,
|
||||
default: () => false,
|
||||
}),
|
||||
|
||||
isSolanaWriteQuery: Annotation<boolean>({
|
||||
reducer: (x, y) => y ?? x ?? false,
|
||||
default: () => false,
|
||||
}),
|
||||
|
||||
isGeneralQuery: Annotation<boolean>({
|
||||
reducer: (x, y) => y ?? x ?? false,
|
||||
default: () => false,
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user