|
1 |
| -import { elizaLogger } from "@ai16z/eliza"; |
2 |
| -import { |
3 |
| - Action, |
4 |
| - HandlerCallback, |
5 |
| - IAgentRuntime, |
6 |
| - Memory, |
7 |
| - Plugin, |
8 |
| - State, |
9 |
| -} from "@ai16z/eliza"; |
10 |
| -import { createGraphRAG } from "./driver"; |
11 |
| -import { validateRaggraphConfig } from "./environment"; |
12 |
| - |
13 |
| -export async function initializeRAGGraph(runtime: IAgentRuntime) { |
14 |
| - const config = await validateRaggraphConfig(runtime); |
15 |
| - return createGraphRAG({ |
16 |
| - neo4jUri: config.NEO4J_URI, |
17 |
| - neo4jUser: config.NEO4J_USER, |
18 |
| - neo4jPassword: config.NEO4J_PASSWORD, |
19 |
| - }); |
20 |
| -} |
21 |
| - |
22 |
| -const ragQuery: Action = { |
23 |
| - name: "RAG_QUERY", |
24 |
| - similes: [ |
25 |
| - "SEARCH_KNOWLEDGE", |
26 |
| - "QUERY_GRAPH", |
27 |
| - "FIND_RELATED", |
28 |
| - "SEARCH_DOCUMENTS", |
29 |
| - "RETRIEVE_INFO", |
30 |
| - ], |
31 |
| - description: "Query the knowledge graph for relevant information", |
32 |
| - validate: async (runtime: IAgentRuntime, _message: Memory) => { |
33 |
| - try { |
34 |
| - await validateRaggraphConfig(runtime); |
35 |
| - return true; |
36 |
| - } catch { |
37 |
| - return false; |
38 |
| - } |
39 |
| - }, |
40 |
| - handler: async ( |
41 |
| - runtime: IAgentRuntime, |
42 |
| - message: Memory, |
43 |
| - state: State, |
44 |
| - _options: Record<string, any>, |
45 |
| - callback: HandlerCallback |
46 |
| - ) => { |
47 |
| - elizaLogger.log("Composing state for message:", message); |
48 |
| - state = (await runtime.composeState(message)) as State; |
49 |
| - |
50 |
| - try { |
51 |
| - const rag = await initializeRAGGraph(runtime); |
52 |
| - const query = message.content.text; |
53 |
| - |
54 |
| - elizaLogger.log("Executing RAG query:", query); |
55 |
| - const result = await rag.query(query); |
56 |
| - |
57 |
| - // Close the connection after query |
58 |
| - await rag.close(); |
59 |
| - |
60 |
| - callback({ |
61 |
| - text: "Here's what I found:", |
62 |
| - attachments: [ |
63 |
| - { |
64 |
| - id: crypto.randomUUID(), |
65 |
| - title: "Search Results", |
66 |
| - source: "raggraph", |
67 |
| - description: "Knowledge Graph Query Results", |
68 |
| - text: result.fullContext, |
69 |
| - metadata: { |
70 |
| - confidence: result.confidence, |
71 |
| - sources: result.sources, |
72 |
| - }, |
73 |
| - }, |
74 |
| - ], |
75 |
| - }); |
76 |
| - } catch (error) { |
77 |
| - elizaLogger.error("RAG query failed:", error); |
78 |
| - throw error; |
79 |
| - } |
80 |
| - }, |
81 |
| - examples: [ |
82 |
| - [ |
83 |
| - { |
84 |
| - user: "{{user1}}", |
85 |
| - content: { text: "What do you know about neural networks?" }, |
86 |
| - }, |
87 |
| - { |
88 |
| - user: "{{agentName}}", |
89 |
| - content: { |
90 |
| - text: "Let me search our knowledge base for information about neural networks.", |
91 |
| - action: "RAG_QUERY", |
92 |
| - }, |
93 |
| - }, |
94 |
| - ], |
95 |
| - [ |
96 |
| - { |
97 |
| - user: "{{user1}}", |
98 |
| - content: { text: "Find information about machine learning" }, |
99 |
| - }, |
100 |
| - { |
101 |
| - user: "{{agentName}}", |
102 |
| - content: { |
103 |
| - text: "I'll search our knowledge graph for machine learning information.", |
104 |
| - action: "RAG_QUERY", |
105 |
| - }, |
106 |
| - }, |
107 |
| - ], |
108 |
| - ], |
109 |
| -} as Action; |
| 1 | +import { Plugin } from "@ai16z/eliza"; |
| 2 | +import { ragGraphProvider } from "./provider"; |
110 | 3 |
|
111 | 4 | export const raggraphPlugin: Plugin = {
|
112 | 5 | name: "raggraph",
|
113 |
| - description: "Knowledge graph querying and retrieval", |
114 |
| - actions: [ragQuery], |
| 6 | + description: "RAGGraph Plugin for Eliza", |
| 7 | + actions: [], |
115 | 8 | evaluators: [],
|
116 |
| - providers: [], |
| 9 | + providers: [ragGraphProvider], |
117 | 10 | };
|
| 11 | + |
| 12 | +export default raggraphPlugin; |
0 commit comments