Skip to content

Commit 5a46b30

Browse files
authored
Merge pull request #1558 from Gajesh2007/main
feat: added new plugin - zktls - reclaim
2 parents 645dc9e + 0167682 commit 5a46b30

File tree

11 files changed

+3964
-2027
lines changed

11 files changed

+3964
-2027
lines changed

agent/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"@elizaos/plugin-tee-marlin": "workspace:*",
5959
"@elizaos/plugin-multiversx": "workspace:*",
6060
"@elizaos/plugin-near": "workspace:*",
61+
"@elizaos/plugin-reclaim": "workspace:*",
6162
"@elizaos/plugin-zksync-era": "workspace:*",
6263
"@elizaos/plugin-twitter": "workspace:*",
6364
"@elizaos/plugin-cronoszkevm": "workspace:*",

agent/src/index.ts

+18
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { LensAgentClient } from "@elizaos/client-lens";
88
import { SlackClientInterface } from "@elizaos/client-slack";
99
import { TelegramClientInterface } from "@elizaos/client-telegram";
1010
import { TwitterClientInterface } from "@elizaos/client-twitter";
11+
import { ReclaimAdapter } from "@elizaos/plugin-reclaim";
1112
import {
1213
AgentRuntime,
1314
CacheManager,
@@ -524,6 +525,22 @@ export async function createAgent(
524525
);
525526
}
526527

528+
// Initialize Reclaim adapter if environment variables are present
529+
let verifiableInferenceAdapter;
530+
if (
531+
process.env.RECLAIM_APP_ID &&
532+
process.env.RECLAIM_APP_SECRET &&
533+
process.env.VERIFIABLE_INFERENCE_ENABLED === "true"
534+
) {
535+
verifiableInferenceAdapter = new ReclaimAdapter({
536+
appId: process.env.RECLAIM_APP_ID,
537+
appSecret: process.env.RECLAIM_APP_SECRET,
538+
modelProvider: character.modelProvider,
539+
token,
540+
});
541+
elizaLogger.log("Verifiable inference adapter initialized");
542+
}
543+
527544
return new AgentRuntime({
528545
databaseAdapter: db,
529546
token,
@@ -631,6 +648,7 @@ export async function createAgent(
631648
managers: [],
632649
cacheManager: cache,
633650
fetch: logFetch,
651+
verifiableInferenceAdapter,
634652
});
635653
}
636654

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
},
4848
"pnpm": {
4949
"overrides": {
50-
"onnxruntime-node": "1.20.1"
50+
"onnxruntime-node": "1.20.1",
51+
"viem": "2.21.58"
5152
}
5253
},
5354
"engines": {

packages/core/src/generation.ts

+72-18
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ import {
4242
ServiceType,
4343
SearchResponse,
4444
ActionResponse,
45+
IVerifiableInferenceAdapter,
46+
VerifiableInferenceOptions,
47+
VerifiableInferenceResult,
48+
VerifiableInferenceProvider,
4549
TelemetrySettings,
4650
TokenizerType,
4751
} from "./types.ts";
@@ -181,6 +185,8 @@ export async function generateText({
181185
maxSteps = 1,
182186
stop,
183187
customSystemPrompt,
188+
verifiableInference = process.env.VERIFIABLE_INFERENCE_ENABLED === "true",
189+
verifiableInferenceOptions,
184190
}: {
185191
runtime: IAgentRuntime;
186192
context: string;
@@ -190,6 +196,9 @@ export async function generateText({
190196
maxSteps?: number;
191197
stop?: string[];
192198
customSystemPrompt?: string;
199+
verifiableInference?: boolean;
200+
verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
201+
verifiableInferenceOptions?: VerifiableInferenceOptions;
193202
}): Promise<string> {
194203
if (!context) {
195204
console.error("generateText context is empty");
@@ -201,8 +210,33 @@ export async function generateText({
201210
elizaLogger.info("Generating text with options:", {
202211
modelProvider: runtime.modelProvider,
203212
model: modelClass,
213+
verifiableInference,
204214
});
205215

216+
// If verifiable inference is requested and adapter is provided, use it
217+
if (verifiableInference && runtime.verifiableInferenceAdapter) {
218+
try {
219+
const result =
220+
await runtime.verifiableInferenceAdapter.generateText(
221+
context,
222+
modelClass,
223+
verifiableInferenceOptions
224+
);
225+
226+
// Verify the proof
227+
const isValid =
228+
await runtime.verifiableInferenceAdapter.verifyProof(result);
229+
if (!isValid) {
230+
throw new Error("Failed to verify inference proof");
231+
}
232+
233+
return result.text;
234+
} catch (error) {
235+
elizaLogger.error("Error in verifiable inference:", error);
236+
throw error;
237+
}
238+
}
239+
206240
const provider = runtime.modelProvider;
207241
const endpoint =
208242
runtime.character.modelEndpointOverride || getEndpoint(provider);
@@ -345,7 +379,7 @@ export async function generateText({
345379
});
346380

347381
response = openaiResponse;
348-
elizaLogger.debug("Received response from OpenAI model.");
382+
console.log("Received response from OpenAI model.");
349383
break;
350384
}
351385

@@ -1520,6 +1554,9 @@ export interface GenerationOptions {
15201554
stop?: string[];
15211555
mode?: "auto" | "json" | "tool";
15221556
experimental_providerMetadata?: Record<string, unknown>;
1557+
verifiableInference?: boolean;
1558+
verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
1559+
verifiableInferenceOptions?: VerifiableInferenceOptions;
15231560
}
15241561

15251562
/**
@@ -1551,6 +1588,9 @@ export const generateObject = async ({
15511588
schemaDescription,
15521589
stop,
15531590
mode = "json",
1591+
verifiableInference = false,
1592+
verifiableInferenceAdapter,
1593+
verifiableInferenceOptions,
15541594
}: GenerationOptions): Promise<GenerateObjectResult<unknown>> => {
15551595
if (!context) {
15561596
const errorMessage = "generateObject context is empty";
@@ -1594,6 +1634,9 @@ export const generateObject = async ({
15941634
runtime,
15951635
context,
15961636
modelClass,
1637+
verifiableInference,
1638+
verifiableInferenceAdapter,
1639+
verifiableInferenceOptions,
15971640
});
15981641

15991642
return response;
@@ -1619,6 +1662,9 @@ interface ProviderOptions {
16191662
modelOptions: ModelSettings;
16201663
modelClass: ModelClass;
16211664
context: string;
1665+
verifiableInference?: boolean;
1666+
verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
1667+
verifiableInferenceOptions?: VerifiableInferenceOptions;
16221668
}
16231669

16241670
/**
@@ -1630,7 +1676,15 @@ interface ProviderOptions {
16301676
export async function handleProvider(
16311677
options: ProviderOptions
16321678
): Promise<GenerateObjectResult<unknown>> {
1633-
const { provider, runtime, context, modelClass } = options;
1679+
const {
1680+
provider,
1681+
runtime,
1682+
context,
1683+
modelClass,
1684+
verifiableInference,
1685+
verifiableInferenceAdapter,
1686+
verifiableInferenceOptions,
1687+
} = options;
16341688
switch (provider) {
16351689
case ModelProviderName.OPENAI:
16361690
case ModelProviderName.ETERNALAI:
@@ -1681,7 +1735,7 @@ async function handleOpenAI({
16811735
schema,
16821736
schemaName,
16831737
schemaDescription,
1684-
mode,
1738+
mode = "json",
16851739
modelOptions,
16861740
}: ProviderOptions): Promise<GenerateObjectResult<unknown>> {
16871741
const baseURL = models.openai.endpoint || undefined;
@@ -1691,7 +1745,7 @@ async function handleOpenAI({
16911745
schema,
16921746
schemaName,
16931747
schemaDescription,
1694-
mode,
1748+
mode: "json",
16951749
...modelOptions,
16961750
});
16971751
}
@@ -1708,7 +1762,7 @@ async function handleAnthropic({
17081762
schema,
17091763
schemaName,
17101764
schemaDescription,
1711-
mode,
1765+
mode = "json",
17121766
modelOptions,
17131767
}: ProviderOptions): Promise<GenerateObjectResult<unknown>> {
17141768
const anthropic = createAnthropic({ apiKey });
@@ -1717,7 +1771,7 @@ async function handleAnthropic({
17171771
schema,
17181772
schemaName,
17191773
schemaDescription,
1720-
mode,
1774+
mode: "json",
17211775
...modelOptions,
17221776
});
17231777
}
@@ -1734,7 +1788,7 @@ async function handleGrok({
17341788
schema,
17351789
schemaName,
17361790
schemaDescription,
1737-
mode,
1791+
mode = "json",
17381792
modelOptions,
17391793
}: ProviderOptions): Promise<GenerateObjectResult<unknown>> {
17401794
const grok = createOpenAI({ apiKey, baseURL: models.grok.endpoint });
@@ -1743,7 +1797,7 @@ async function handleGrok({
17431797
schema,
17441798
schemaName,
17451799
schemaDescription,
1746-
mode,
1800+
mode: "json",
17471801
...modelOptions,
17481802
});
17491803
}
@@ -1760,7 +1814,7 @@ async function handleGroq({
17601814
schema,
17611815
schemaName,
17621816
schemaDescription,
1763-
mode,
1817+
mode = "json",
17641818
modelOptions,
17651819
}: ProviderOptions): Promise<GenerateObjectResult<unknown>> {
17661820
const groq = createGroq({ apiKey });
@@ -1769,7 +1823,7 @@ async function handleGroq({
17691823
schema,
17701824
schemaName,
17711825
schemaDescription,
1772-
mode,
1826+
mode: "json",
17731827
...modelOptions,
17741828
});
17751829
}
@@ -1786,7 +1840,7 @@ async function handleGoogle({
17861840
schema,
17871841
schemaName,
17881842
schemaDescription,
1789-
mode,
1843+
mode = "json",
17901844
modelOptions,
17911845
}: ProviderOptions): Promise<GenerateObjectResult<unknown>> {
17921846
const google = createGoogleGenerativeAI();
@@ -1795,7 +1849,7 @@ async function handleGoogle({
17951849
schema,
17961850
schemaName,
17971851
schemaDescription,
1798-
mode,
1852+
mode: "json",
17991853
...modelOptions,
18001854
});
18011855
}
@@ -1812,7 +1866,7 @@ async function handleRedPill({
18121866
schema,
18131867
schemaName,
18141868
schemaDescription,
1815-
mode,
1869+
mode = "json",
18161870
modelOptions,
18171871
}: ProviderOptions): Promise<GenerateObjectResult<unknown>> {
18181872
const redPill = createOpenAI({ apiKey, baseURL: models.redpill.endpoint });
@@ -1821,7 +1875,7 @@ async function handleRedPill({
18211875
schema,
18221876
schemaName,
18231877
schemaDescription,
1824-
mode,
1878+
mode: "json",
18251879
...modelOptions,
18261880
});
18271881
}
@@ -1838,7 +1892,7 @@ async function handleOpenRouter({
18381892
schema,
18391893
schemaName,
18401894
schemaDescription,
1841-
mode,
1895+
mode = "json",
18421896
modelOptions,
18431897
}: ProviderOptions): Promise<GenerateObjectResult<unknown>> {
18441898
const openRouter = createOpenAI({
@@ -1850,7 +1904,7 @@ async function handleOpenRouter({
18501904
schema,
18511905
schemaName,
18521906
schemaDescription,
1853-
mode,
1907+
mode: "json",
18541908
...modelOptions,
18551909
});
18561910
}
@@ -1866,7 +1920,7 @@ async function handleOllama({
18661920
schema,
18671921
schemaName,
18681922
schemaDescription,
1869-
mode,
1923+
mode = "json",
18701924
modelOptions,
18711925
provider,
18721926
}: ProviderOptions): Promise<GenerateObjectResult<unknown>> {
@@ -1879,7 +1933,7 @@ async function handleOllama({
18791933
schema,
18801934
schemaName,
18811935
schemaDescription,
1882-
mode,
1936+
mode: "json",
18831937
...modelOptions,
18841938
});
18851939
}

packages/core/src/runtime.ts

+17
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ import {
4444
type Actor,
4545
type Evaluator,
4646
type Memory,
47+
IVerifiableInferenceAdapter,
48+
VerifiableInferenceOptions,
49+
VerifiableInferenceProvider,
4750
} from "./types.ts";
4851
import { stringToUuid } from "./uuid.ts";
4952

@@ -149,6 +152,8 @@ export class AgentRuntime implements IAgentRuntime {
149152
cacheManager: ICacheManager;
150153
clients: Record<string, any>;
151154

155+
verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
156+
152157
registerMemoryManager(manager: IMemoryManager): void {
153158
if (!manager.tableName) {
154159
throw new Error("Memory manager must have a tableName");
@@ -230,6 +235,7 @@ export class AgentRuntime implements IAgentRuntime {
230235
speechModelPath?: string;
231236
cacheManager: ICacheManager;
232237
logging?: boolean;
238+
verifiableInferenceAdapter?: IVerifiableInferenceAdapter;
233239
}) {
234240
elizaLogger.info("Initializing AgentRuntime with options:", {
235241
character: opts.character?.name,
@@ -388,6 +394,8 @@ export class AgentRuntime implements IAgentRuntime {
388394
(opts.evaluators ?? []).forEach((evaluator: Evaluator) => {
389395
this.registerEvaluator(evaluator);
390396
});
397+
398+
this.verifiableInferenceAdapter = opts.verifiableInferenceAdapter;
391399
}
392400

393401
async initialize() {
@@ -664,6 +672,7 @@ export class AgentRuntime implements IAgentRuntime {
664672
runtime: this,
665673
context,
666674
modelClass: ModelClass.SMALL,
675+
verifiableInferenceAdapter: this.verifiableInferenceAdapter,
667676
});
668677

669678
const evaluators = parseJsonArrayFromText(
@@ -1296,6 +1305,14 @@ Text: ${attachment.text}
12961305
attachments: formattedAttachments,
12971306
} as State;
12981307
}
1308+
1309+
getVerifiableInferenceAdapter(): IVerifiableInferenceAdapter | undefined {
1310+
return this.verifiableInferenceAdapter;
1311+
}
1312+
1313+
setVerifiableInferenceAdapter(adapter: IVerifiableInferenceAdapter): void {
1314+
this.verifiableInferenceAdapter = adapter;
1315+
}
12991316
}
13001317

13011318
const formatKnowledge = (knowledge: KnowledgeItem[]) => {

0 commit comments

Comments
 (0)