@xache/langchain 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -107,6 +107,62 @@ const result = await extractor.extract(
107
107
  console.log(`Extracted ${result.count} memories`);
108
108
  ```
109
109
 
110
+ ### Knowledge Graph
111
+
112
+ Build and query a privacy-preserving knowledge graph of entities and relationships:
113
+
114
+ ```typescript
115
+ import {
116
+ createGraphExtractTool,
117
+ createGraphQueryTool,
118
+ createGraphAskTool,
119
+ createGraphLoadTool,
120
+ createGraphAddEntityTool,
121
+ createGraphAddRelationshipTool,
122
+ createGraphMergeEntitiesTool,
123
+ createGraphEntityHistoryTool,
124
+ XacheGraphRetriever,
125
+ } from '@xache/langchain';
126
+
127
+ const config = {
128
+ walletAddress: '0x...',
129
+ privateKey: '0x...',
130
+ llmProvider: 'anthropic',
131
+ llmApiKey: 'sk-ant-...',
132
+ };
133
+
134
+ // Extract entities from text
135
+ const extractTool = createGraphExtractTool(config);
136
+
137
+ // Query graph around an entity
138
+ const queryTool = createGraphQueryTool(config);
139
+
140
+ // Ask natural language questions
141
+ const askTool = createGraphAskTool(config);
142
+
143
+ // Load the full graph
144
+ const loadTool = createGraphLoadTool(config);
145
+
146
+ // Add entities and relationships manually
147
+ const addEntityTool = createGraphAddEntityTool(config);
148
+ const addRelTool = createGraphAddRelationshipTool(config);
149
+
150
+ // Merge duplicate entities
151
+ const mergeTool = createGraphMergeEntitiesTool(config);
152
+
153
+ // View entity version history
154
+ const historyTool = createGraphEntityHistoryTool(config);
155
+
156
+ // Use as a retriever for RAG
157
+ const graphRetriever = new XacheGraphRetriever({
158
+ walletAddress: '0x...',
159
+ privateKey: '0x...',
160
+ k: 10,
161
+ });
162
+
163
+ const docs = await graphRetriever.getRelevantDocuments('engineering team');
164
+ ```
165
+
110
166
  ### Reputation
111
167
 
112
168
  Check and verify agent reputation:
@@ -160,6 +216,8 @@ All operations use x402 micropayments (auto-handled):
160
216
  | Collective Contribute| $0.002 |
161
217
  | Collective Query | $0.011 |
162
218
  | Extraction (managed) | $0.011 |
219
+ | Graph Operations | $0.002 |
220
+ | Graph Ask (managed) | $0.011 |
163
221
 
164
222
  ## ERC-8004 Portable Reputation
165
223
 
package/dist/index.d.mts CHANGED
@@ -4,7 +4,7 @@ import { BaseMessage } from '@langchain/core/messages';
4
4
  import { BaseRetriever, BaseRetrieverInput } from '@langchain/core/retrievers';
5
5
  import { Document } from '@langchain/core/documents';
6
6
  import { CallbackManagerForRetrieverRun } from '@langchain/core/callbacks/manager';
7
- import { LLMProvider, LLMApiFormat } from '@xache/sdk';
7
+ import { LLMProvider, LLMApiFormat, SubjectContext } from '@xache/sdk';
8
8
  import { DynamicStructuredTool } from '@langchain/core/tools';
9
9
 
10
10
  /**
@@ -476,4 +476,168 @@ declare class XacheReputationChecker {
476
476
  meetsThreshold(agentDid: string, minScore: number): Promise<boolean>;
477
477
  }
478
478
 
479
- export { type CollectiveToolConfig, type ExtractedMemory, type ExtractionResult, type ReputationResult, type ReputationToolConfig, XacheChatMessageHistory, type XacheChatMessageHistoryConfig, XacheCollectiveContributeTool, XacheCollectiveQueryTool, XacheConversationBufferMemory, XacheExtractor, type XacheExtractorConfig, XacheMemory, type XacheMemoryConfig, XacheReputationChecker, XacheReputationTool, XacheRetriever, type XacheRetrieverConfig, createCollectiveContributeTool, createCollectiveQueryTool, createReputationTool };
479
+ /**
480
+ * Xache Knowledge Graph for LangChain.js
481
+ * Extract, query, and manage entities/relationships in a privacy-preserving knowledge graph
482
+ */
483
+
484
+ interface GraphToolConfig {
485
+ /** Wallet address for authentication */
486
+ walletAddress: string;
487
+ /** Private key for signing */
488
+ privateKey: string;
489
+ /** API URL (defaults to https://api.xache.xyz) */
490
+ apiUrl?: string;
491
+ /** Chain: 'base' or 'solana' */
492
+ chain?: 'base' | 'solana';
493
+ /** Subject context for graph scoping (defaults to GLOBAL) */
494
+ subject?: SubjectContext;
495
+ /** LLM provider for extract/ask (api-key mode) */
496
+ llmProvider?: LLMProvider;
497
+ /** LLM API key */
498
+ llmApiKey?: string;
499
+ /** LLM model override */
500
+ llmModel?: string;
501
+ /** LLM endpoint URL (endpoint mode) */
502
+ llmEndpoint?: string;
503
+ /** LLM auth token (endpoint mode) */
504
+ llmAuthToken?: string;
505
+ /** LLM API format (endpoint mode, default: openai) */
506
+ llmFormat?: LLMApiFormat;
507
+ }
508
+ /**
509
+ * Create a tool for extracting entities/relationships from agent traces.
510
+ *
511
+ * @example
512
+ * ```typescript
513
+ * const extractTool = createGraphExtractTool({
514
+ * walletAddress: '0x...',
515
+ * privateKey: '0x...',
516
+ * llmProvider: 'anthropic',
517
+ * llmApiKey: 'sk-ant-...',
518
+ * });
519
+ * ```
520
+ */
521
+ declare function createGraphExtractTool(config: GraphToolConfig): DynamicStructuredTool;
522
+ /**
523
+ * Create a tool for querying the knowledge graph around a specific entity.
524
+ */
525
+ declare function createGraphQueryTool(config: GraphToolConfig): DynamicStructuredTool;
526
+ /**
527
+ * Create a tool for asking natural language questions about the knowledge graph.
528
+ */
529
+ declare function createGraphAskTool(config: GraphToolConfig): DynamicStructuredTool;
530
+ /**
531
+ * Create a tool for adding entities to the knowledge graph.
532
+ */
533
+ declare function createGraphAddEntityTool(config: GraphToolConfig): DynamicStructuredTool;
534
+ /**
535
+ * Create a tool for adding relationships between entities.
536
+ */
537
+ declare function createGraphAddRelationshipTool(config: GraphToolConfig): DynamicStructuredTool;
538
+ /**
539
+ * Create a tool for loading the full knowledge graph.
540
+ */
541
+ declare function createGraphLoadTool(config: GraphToolConfig): DynamicStructuredTool;
542
+ /**
543
+ * Create a tool for merging two entities in the knowledge graph.
544
+ */
545
+ declare function createGraphMergeEntitiesTool(config: GraphToolConfig): DynamicStructuredTool;
546
+ /**
547
+ * Create a tool for getting the version history of an entity.
548
+ */
549
+ declare function createGraphEntityHistoryTool(config: GraphToolConfig): DynamicStructuredTool;
550
+ /**
551
+ * Class wrapper for graph extract tool
552
+ */
553
+ declare class XacheGraphExtractTool {
554
+ private tool;
555
+ constructor(config: GraphToolConfig);
556
+ asTool(): DynamicStructuredTool;
557
+ }
558
+ /**
559
+ * Class wrapper for graph query tool
560
+ */
561
+ declare class XacheGraphQueryTool {
562
+ private tool;
563
+ constructor(config: GraphToolConfig);
564
+ asTool(): DynamicStructuredTool;
565
+ }
566
+ /**
567
+ * Class wrapper for graph ask tool
568
+ */
569
+ declare class XacheGraphAskTool {
570
+ private tool;
571
+ constructor(config: GraphToolConfig);
572
+ asTool(): DynamicStructuredTool;
573
+ }
574
+ /**
575
+ * Class wrapper for graph load tool
576
+ */
577
+ declare class XacheGraphLoadTool {
578
+ private tool;
579
+ constructor(config: GraphToolConfig);
580
+ asTool(): DynamicStructuredTool;
581
+ }
582
+ /**
583
+ * Class wrapper for graph merge entities tool
584
+ */
585
+ declare class XacheGraphMergeEntitiesTool {
586
+ private tool;
587
+ constructor(config: GraphToolConfig);
588
+ asTool(): DynamicStructuredTool;
589
+ }
590
+ /**
591
+ * Class wrapper for graph entity history tool
592
+ */
593
+ declare class XacheGraphEntityHistoryTool {
594
+ private tool;
595
+ constructor(config: GraphToolConfig);
596
+ asTool(): DynamicStructuredTool;
597
+ }
598
+ interface XacheGraphRetrieverConfig extends BaseRetrieverInput {
599
+ /** Wallet address for authentication */
600
+ walletAddress: string;
601
+ /** Private key for signing */
602
+ privateKey: string;
603
+ /** API URL (defaults to https://api.xache.xyz) */
604
+ apiUrl?: string;
605
+ /** Chain: 'base' or 'solana' */
606
+ chain?: 'base' | 'solana';
607
+ /** Subject context for graph scoping */
608
+ subject?: SubjectContext;
609
+ /** Starting entity for subgraph query (optional — if not set, loads full graph) */
610
+ startEntity?: string;
611
+ /** Depth for subgraph query (default: 2) */
612
+ depth?: number;
613
+ /** Max results to return */
614
+ k?: number;
615
+ }
616
+ /**
617
+ * Retriever that fetches documents from the Xache knowledge graph.
618
+ * Each entity becomes a Document with its name, type, and summary.
619
+ *
620
+ * @example
621
+ * ```typescript
622
+ * const retriever = new XacheGraphRetriever({
623
+ * walletAddress: '0x...',
624
+ * privateKey: '0x...',
625
+ * k: 10,
626
+ * });
627
+ *
628
+ * const docs = await retriever.getRelevantDocuments('engineering team');
629
+ * ```
630
+ */
631
+ declare class XacheGraphRetriever extends BaseRetriever {
632
+ lc_namespace: string[];
633
+ static lc_name(): string;
634
+ private client;
635
+ private subject;
636
+ private startEntity?;
637
+ private depth;
638
+ private k;
639
+ constructor(config: XacheGraphRetrieverConfig);
640
+ _getRelevantDocuments(query: string, _runManager?: CallbackManagerForRetrieverRun): Promise<Document[]>;
641
+ }
642
+
643
+ export { type CollectiveToolConfig, type ExtractedMemory, type ExtractionResult, type GraphToolConfig, type ReputationResult, type ReputationToolConfig, XacheChatMessageHistory, type XacheChatMessageHistoryConfig, XacheCollectiveContributeTool, XacheCollectiveQueryTool, XacheConversationBufferMemory, XacheExtractor, type XacheExtractorConfig, XacheGraphAskTool, XacheGraphEntityHistoryTool, XacheGraphExtractTool, XacheGraphLoadTool, XacheGraphMergeEntitiesTool, XacheGraphQueryTool, XacheGraphRetriever, type XacheGraphRetrieverConfig, XacheMemory, type XacheMemoryConfig, XacheReputationChecker, XacheReputationTool, XacheRetriever, type XacheRetrieverConfig, createCollectiveContributeTool, createCollectiveQueryTool, createGraphAddEntityTool, createGraphAddRelationshipTool, createGraphAskTool, createGraphEntityHistoryTool, createGraphExtractTool, createGraphLoadTool, createGraphMergeEntitiesTool, createGraphQueryTool, createReputationTool };
package/dist/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { BaseMessage } from '@langchain/core/messages';
4
4
  import { BaseRetriever, BaseRetrieverInput } from '@langchain/core/retrievers';
5
5
  import { Document } from '@langchain/core/documents';
6
6
  import { CallbackManagerForRetrieverRun } from '@langchain/core/callbacks/manager';
7
- import { LLMProvider, LLMApiFormat } from '@xache/sdk';
7
+ import { LLMProvider, LLMApiFormat, SubjectContext } from '@xache/sdk';
8
8
  import { DynamicStructuredTool } from '@langchain/core/tools';
9
9
 
10
10
  /**
@@ -476,4 +476,168 @@ declare class XacheReputationChecker {
476
476
  meetsThreshold(agentDid: string, minScore: number): Promise<boolean>;
477
477
  }
478
478
 
479
- export { type CollectiveToolConfig, type ExtractedMemory, type ExtractionResult, type ReputationResult, type ReputationToolConfig, XacheChatMessageHistory, type XacheChatMessageHistoryConfig, XacheCollectiveContributeTool, XacheCollectiveQueryTool, XacheConversationBufferMemory, XacheExtractor, type XacheExtractorConfig, XacheMemory, type XacheMemoryConfig, XacheReputationChecker, XacheReputationTool, XacheRetriever, type XacheRetrieverConfig, createCollectiveContributeTool, createCollectiveQueryTool, createReputationTool };
479
+ /**
480
+ * Xache Knowledge Graph for LangChain.js
481
+ * Extract, query, and manage entities/relationships in a privacy-preserving knowledge graph
482
+ */
483
+
484
+ interface GraphToolConfig {
485
+ /** Wallet address for authentication */
486
+ walletAddress: string;
487
+ /** Private key for signing */
488
+ privateKey: string;
489
+ /** API URL (defaults to https://api.xache.xyz) */
490
+ apiUrl?: string;
491
+ /** Chain: 'base' or 'solana' */
492
+ chain?: 'base' | 'solana';
493
+ /** Subject context for graph scoping (defaults to GLOBAL) */
494
+ subject?: SubjectContext;
495
+ /** LLM provider for extract/ask (api-key mode) */
496
+ llmProvider?: LLMProvider;
497
+ /** LLM API key */
498
+ llmApiKey?: string;
499
+ /** LLM model override */
500
+ llmModel?: string;
501
+ /** LLM endpoint URL (endpoint mode) */
502
+ llmEndpoint?: string;
503
+ /** LLM auth token (endpoint mode) */
504
+ llmAuthToken?: string;
505
+ /** LLM API format (endpoint mode, default: openai) */
506
+ llmFormat?: LLMApiFormat;
507
+ }
508
+ /**
509
+ * Create a tool for extracting entities/relationships from agent traces.
510
+ *
511
+ * @example
512
+ * ```typescript
513
+ * const extractTool = createGraphExtractTool({
514
+ * walletAddress: '0x...',
515
+ * privateKey: '0x...',
516
+ * llmProvider: 'anthropic',
517
+ * llmApiKey: 'sk-ant-...',
518
+ * });
519
+ * ```
520
+ */
521
+ declare function createGraphExtractTool(config: GraphToolConfig): DynamicStructuredTool;
522
+ /**
523
+ * Create a tool for querying the knowledge graph around a specific entity.
524
+ */
525
+ declare function createGraphQueryTool(config: GraphToolConfig): DynamicStructuredTool;
526
+ /**
527
+ * Create a tool for asking natural language questions about the knowledge graph.
528
+ */
529
+ declare function createGraphAskTool(config: GraphToolConfig): DynamicStructuredTool;
530
+ /**
531
+ * Create a tool for adding entities to the knowledge graph.
532
+ */
533
+ declare function createGraphAddEntityTool(config: GraphToolConfig): DynamicStructuredTool;
534
+ /**
535
+ * Create a tool for adding relationships between entities.
536
+ */
537
+ declare function createGraphAddRelationshipTool(config: GraphToolConfig): DynamicStructuredTool;
538
+ /**
539
+ * Create a tool for loading the full knowledge graph.
540
+ */
541
+ declare function createGraphLoadTool(config: GraphToolConfig): DynamicStructuredTool;
542
+ /**
543
+ * Create a tool for merging two entities in the knowledge graph.
544
+ */
545
+ declare function createGraphMergeEntitiesTool(config: GraphToolConfig): DynamicStructuredTool;
546
+ /**
547
+ * Create a tool for getting the version history of an entity.
548
+ */
549
+ declare function createGraphEntityHistoryTool(config: GraphToolConfig): DynamicStructuredTool;
550
+ /**
551
+ * Class wrapper for graph extract tool
552
+ */
553
+ declare class XacheGraphExtractTool {
554
+ private tool;
555
+ constructor(config: GraphToolConfig);
556
+ asTool(): DynamicStructuredTool;
557
+ }
558
+ /**
559
+ * Class wrapper for graph query tool
560
+ */
561
+ declare class XacheGraphQueryTool {
562
+ private tool;
563
+ constructor(config: GraphToolConfig);
564
+ asTool(): DynamicStructuredTool;
565
+ }
566
+ /**
567
+ * Class wrapper for graph ask tool
568
+ */
569
+ declare class XacheGraphAskTool {
570
+ private tool;
571
+ constructor(config: GraphToolConfig);
572
+ asTool(): DynamicStructuredTool;
573
+ }
574
+ /**
575
+ * Class wrapper for graph load tool
576
+ */
577
+ declare class XacheGraphLoadTool {
578
+ private tool;
579
+ constructor(config: GraphToolConfig);
580
+ asTool(): DynamicStructuredTool;
581
+ }
582
+ /**
583
+ * Class wrapper for graph merge entities tool
584
+ */
585
+ declare class XacheGraphMergeEntitiesTool {
586
+ private tool;
587
+ constructor(config: GraphToolConfig);
588
+ asTool(): DynamicStructuredTool;
589
+ }
590
+ /**
591
+ * Class wrapper for graph entity history tool
592
+ */
593
+ declare class XacheGraphEntityHistoryTool {
594
+ private tool;
595
+ constructor(config: GraphToolConfig);
596
+ asTool(): DynamicStructuredTool;
597
+ }
598
+ interface XacheGraphRetrieverConfig extends BaseRetrieverInput {
599
+ /** Wallet address for authentication */
600
+ walletAddress: string;
601
+ /** Private key for signing */
602
+ privateKey: string;
603
+ /** API URL (defaults to https://api.xache.xyz) */
604
+ apiUrl?: string;
605
+ /** Chain: 'base' or 'solana' */
606
+ chain?: 'base' | 'solana';
607
+ /** Subject context for graph scoping */
608
+ subject?: SubjectContext;
609
+ /** Starting entity for subgraph query (optional — if not set, loads full graph) */
610
+ startEntity?: string;
611
+ /** Depth for subgraph query (default: 2) */
612
+ depth?: number;
613
+ /** Max results to return */
614
+ k?: number;
615
+ }
616
+ /**
617
+ * Retriever that fetches documents from the Xache knowledge graph.
618
+ * Each entity becomes a Document with its name, type, and summary.
619
+ *
620
+ * @example
621
+ * ```typescript
622
+ * const retriever = new XacheGraphRetriever({
623
+ * walletAddress: '0x...',
624
+ * privateKey: '0x...',
625
+ * k: 10,
626
+ * });
627
+ *
628
+ * const docs = await retriever.getRelevantDocuments('engineering team');
629
+ * ```
630
+ */
631
+ declare class XacheGraphRetriever extends BaseRetriever {
632
+ lc_namespace: string[];
633
+ static lc_name(): string;
634
+ private client;
635
+ private subject;
636
+ private startEntity?;
637
+ private depth;
638
+ private k;
639
+ constructor(config: XacheGraphRetrieverConfig);
640
+ _getRelevantDocuments(query: string, _runManager?: CallbackManagerForRetrieverRun): Promise<Document[]>;
641
+ }
642
+
643
+ export { type CollectiveToolConfig, type ExtractedMemory, type ExtractionResult, type GraphToolConfig, type ReputationResult, type ReputationToolConfig, XacheChatMessageHistory, type XacheChatMessageHistoryConfig, XacheCollectiveContributeTool, XacheCollectiveQueryTool, XacheConversationBufferMemory, XacheExtractor, type XacheExtractorConfig, XacheGraphAskTool, XacheGraphEntityHistoryTool, XacheGraphExtractTool, XacheGraphLoadTool, XacheGraphMergeEntitiesTool, XacheGraphQueryTool, XacheGraphRetriever, type XacheGraphRetrieverConfig, XacheMemory, type XacheMemoryConfig, XacheReputationChecker, XacheReputationTool, XacheRetriever, type XacheRetrieverConfig, createCollectiveContributeTool, createCollectiveQueryTool, createGraphAddEntityTool, createGraphAddRelationshipTool, createGraphAskTool, createGraphEntityHistoryTool, createGraphExtractTool, createGraphLoadTool, createGraphMergeEntitiesTool, createGraphQueryTool, createReputationTool };