-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Primus zkTLS plugin to fully verify agent activities #2086
Conversation
# Conflicts: # agent/package.json # agent/src/index.ts # pnpm-lock.yaml
# Conflicts: # .env.example # agent/src/index.ts # packages/core/src/types.ts # pnpm-lock.yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @xiangxiecrypto! Welcome to the ai16z community. Thanks for submitting your first pull request; your efforts are helping us accelerate towards AGI. We'll review it shortly. You are now a ai16z contributor!
# Conflicts: # pnpm-lock.yaml
@wtfsayo thank you for approving the previous version! We just resolved conflict! |
@xiangxiecrypto in-conflict again; can't resolve myself due to your branch perms I think |
# Conflicts: # pnpm-lock.yaml
@wtfsayo I‘ve grant you access to the branch, and we resolved the conflicts. Thanks! |
@coderabbitai review |
📝 WalkthroughWalkthroughThis pull request introduces the Changes
Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 11
🧹 Nitpick comments (9)
packages/plugin-primus/src/adapter/primusAdapter.ts (1)
85-85
: Use consistent logging with 'elizaLogger'Replace
console.error
withelizaLogger.error
for consistent logging.- console.error("Error in Primus generateText:", error); + elizaLogger.error("Error in Primus generateText:", error);packages/plugin-primus/src/util/twitterScraper.ts (3)
8-8
: Remove unnecessary constructorThe empty constructor is unnecessary and can be removed.
- constructor() {}
🧰 Tools
🪛 Biome (1.9.4)
[error] 8-8: This constructor is unnecessary.
Unsafe fix: Remove the unnecessary constructor.
(lint/complexity/noUselessConstructor)
43-183
: Avoid using 'any' typecastingCasting
this.scraper
toany
bypasses type checking. Consider extending or properly typing theScraper
class to avoid usingany
.
132-132
: Correct typo in error messagesChange "illegality" to "illegal" in the error messages.
- "Verify attestation failed,data from source is illegality" + "Verify attestation failed, data from source is illegal" - "Verify attestation failed, data from source is illegality" + "Verify attestation failed, data from source is illegal"Also applies to: 252-252
packages/plugin-primus/src/util/primusUtil.ts (1)
24-24
: Remove commented out codeRemove the commented console.log statement.
- // console.log('requestParam:',requestParam)
packages/plugin-primus/README.md (4)
17-17
: Add missing commaAdd a comma after "actions" for better readability.
-An example for verifying actions, such as posting a tweet (this can be extended to any other actions). +An example for verifying actions, such as posting a tweet (this can be extended to any other actions,).🧰 Tools
🪛 LanguageTool
[uncategorized] ~17-~17: Possible missing comma found.
Context: ...be extended to any other actions). - An example to verify that the Bitcoin price is acc...(AI_HYDRA_LEO_MISSING_COMMA)
37-43
: Add validation for PrimusOptions interfaceConsider adding validation for the attMode field to restrict it to valid values.
interface PrimusOptions { appId: string; appSecret: string; - attMode: string; + attMode: "mpctls" | "proxytls"; modelProvider?: ModelProviderName; token?: string; }
93-93
: Add return type annotationThe provider's get method should specify its return type for better type safety.
- get: async (runtime: IAgentRuntime, message: Memory, _state?: State) => { + get: async (runtime: IAgentRuntime, message: Memory, _state?: State): Promise<string> => {
159-166
: Add environment variable validation stepsConsider adding a section about validating the environment variables and common troubleshooting steps.
Would you like me to generate a validation script and troubleshooting guide section for the README?
🧰 Tools
🪛 Markdownlint (0.37.0)
161-161: null
Fenced code blocks should have a language specified(MD040, fenced-code-language)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (16)
agent/package.json
(1 hunks)agent/src/index.ts
(3 hunks)packages/core/src/types.ts
(1 hunks)packages/plugin-primus/.npmignore
(1 hunks)packages/plugin-primus/README.md
(1 hunks)packages/plugin-primus/package.json
(1 hunks)packages/plugin-primus/src/actions/postTweetAction.ts
(1 hunks)packages/plugin-primus/src/adapter/primusAdapter.ts
(1 hunks)packages/plugin-primus/src/index.ts
(1 hunks)packages/plugin-primus/src/providers/tokenPriceProvider.ts
(1 hunks)packages/plugin-primus/src/providers/tweetProvider.ts
(1 hunks)packages/plugin-primus/src/templates.ts
(1 hunks)packages/plugin-primus/src/util/primusUtil.ts
(1 hunks)packages/plugin-primus/src/util/twitterScraper.ts
(1 hunks)packages/plugin-primus/tsconfig.json
(1 hunks)packages/plugin-primus/tsup.config.ts
(1 hunks)
✅ Files skipped from review due to trivial changes (3)
- packages/plugin-primus/tsconfig.json
- packages/plugin-primus/.npmignore
- packages/plugin-primus/tsup.config.ts
👮 Files not reviewed due to content moderation or server errors (4)
- packages/core/src/types.ts
- agent/src/index.ts
- packages/plugin-primus/package.json
- packages/plugin-primus/src/actions/postTweetAction.ts
🧰 Additional context used
🪛 LanguageTool
packages/plugin-primus/README.md
[uncategorized] ~17-~17: Possible missing comma found.
Context: ...be extended to any other actions). - An example to verify that the Bitcoin price is acc...
(AI_HYDRA_LEO_MISSING_COMMA)
🪛 Markdownlint (0.37.0)
packages/plugin-primus/README.md
98-98: Column: 20
Hard tabs
(MD010, no-hard-tabs)
161-161: null
Fenced code blocks should have a language specified
(MD040, fenced-code-language)
🪛 Biome (1.9.4)
packages/plugin-primus/src/util/twitterScraper.ts
[error] 8-8: This constructor is unnecessary.
Unsafe fix: Remove the unnecessary constructor.
(lint/complexity/noUselessConstructor)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: integration-tests
- GitHub Check: smoke-tests
🔇 Additional comments (1)
agent/package.json (1)
75-75
: LGTM! Dependency added correctlyThe new plugin dependency follows the established pattern and is correctly placed.
nope!!! but do check the ai flagged issues |
I think you need to accept the invite. Yeah, we are checking the issues. |
We fixed the issues, can you please let the bot review it again? Thanks |
@coderabbitai review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (2)
packages/plugin-primus/src/util/primusUtil.ts (1)
38-42
: 🛠️ Refactor suggestionAdd credential validation to verification function
Add environment variable validation.
export const verifyProof = async (attestation: Attestation): Promise<boolean> => { + if (!process.env.PRIMUS_APP_ID || !process.env.PRIMUS_APP_SECRET) { + throw new Error('Primus credentials not configured'); + } const zkTLS = new PrimusCoreTLS();packages/plugin-primus/src/providers/tokenPriceProvider.ts (1)
18-31
: 🛠️ Refactor suggestionImprove type safety and error handling
Replace type assertion and add proper error handling.
try { - const responseData = JSON.parse((attestation as any).data); + const responseData = JSON.parse(attestation.data); + if (!responseData?.content) { + throw new Error('Invalid response format'); + } const price = responseData.content;
🧹 Nitpick comments (10)
packages/plugin-primus/src/providers/tweetProvider.ts (3)
16-19
: Remove redundant login verification.The
isLoggedIn()
check is redundant since we already handle login failures in the try-catch block above.- if (!(await scraperWithPrimus.getScraper().isLoggedIn())) { - elizaLogger.error("Failed to login to Twitter"); - return false; - }
27-27
: Remove duplicate debug log.This log message is identical to the one on line 25.
- elizaLogger.debug(`Fetching tweets for user: ${userName}`);
4-37
: Add rate limiting for Twitter API calls.Consider implementing rate limiting to prevent API abuse and comply with Twitter's usage guidelines.
packages/plugin-primus/README.md (3)
48-49
: Make OpenAI endpoint configurableThe endpoint URL should be configurable through environment variables rather than hardcoded.
- endpoint: "https://api.openapi.com/chat/completions", + endpoint: process.env.OPENAI_API_ENDPOINT || "https://api.openapi.com/chat/completions",
157-161
: Add version compatibility informationPlease specify:
- Required Node.js version
- Compatible ElizaOS versions
- Any other dependencies
98-98
: Fix markdown formatting issues
- Replace hard tab with spaces in the headers section
- Add language specification to the environment variables code block
- 'Accept ': '*/*', + 'Accept': '*/*', -``` +```env PRIMUS_APP_ID=your_app_idAlso applies to: 167-172
🧰 Tools
🪛 Markdownlint (0.37.0)
98-98: Column: 20
Hard tabs(MD010, no-hard-tabs)
packages/plugin-primus/src/util/primusUtil.ts (2)
24-24
: Remove commented debug codeRemove the commented console.log statement.
25-35
: Validate response parse path formatAdd validation for the response parse path to ensure it follows JSONPath syntax.
+ if (!responseParsePath.startsWith('$')) { + throw new Error('Invalid response parse path format. Must be a valid JSONPath expression'); + } const attestationParams = zkTLS.generateRequestParams(requestParam, [packages/plugin-primus/src/providers/tokenPriceProvider.ts (2)
9-11
: Fix header formattingRemove the tab character from the Accept header.
const headers = { - 'Accept ': '*/*', + 'Accept': '*/*', };
21-27
: Consider using a template literalThe multi-line string could be more readable using a template literal.
- return ` - Get BTC price from Binance: - BTC: ${price} USDT - Time: ${new Date().toUTCString()} - POST by eliza #eliza - Attested by Primus #primus #zktls - ` + return `Get BTC price from Binance: +BTC: ${price} USDT +Time: ${new Date().toUTCString()} +POST by eliza #eliza +Attested by Primus #primus #zktls`;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
packages/plugin-primus/README.md
(1 hunks)packages/plugin-primus/src/providers/tokenPriceProvider.ts
(1 hunks)packages/plugin-primus/src/providers/tweetProvider.ts
(1 hunks)packages/plugin-primus/src/templates.ts
(1 hunks)packages/plugin-primus/src/util/primusUtil.ts
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/plugin-primus/src/templates.ts
🧰 Additional context used
🪛 Markdownlint (0.37.0)
packages/plugin-primus/README.md
98-98: Column: 20
Hard tabs
(MD010, no-hard-tabs)
167-167: null
Fenced code blocks should have a language specified
(MD040, fenced-code-language)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: integration-tests
- GitHub Check: smoke-tests
🔇 Additional comments (6)
packages/plugin-primus/src/providers/tweetProvider.ts (2)
1-4
: LGTM! Clean imports and provider definition.
28-35
: Well-implemented error handling for tweet retrieval.The error handling matches the previously suggested implementation.
packages/plugin-primus/README.md (1)
117-154
: Complete the action implementationThe action has several issues that need to be addressed:
- Empty examples array
- Missing error handling for the tweet posting
- Incomplete validate method
packages/plugin-primus/src/util/primusUtil.ts (2)
1-1
: LGTM! Clean import with proper types.
3-11
: 🛠️ Refactor suggestionAdd environment variable validation and improve type safety
The function should validate environment variables and use stricter types.
+interface RequestHeaders { + [key: string]: string; +} + export const generateProof = async ( endpoint: string, method: string, - headers: Record<string, any>, + headers: RequestHeaders, body: string, responseParsePath: string ): Promise<Attestation> => { + if (!process.env.PRIMUS_APP_ID || !process.env.PRIMUS_APP_SECRET) { + throw new Error('Primus credentials not configured'); + } const zkTLS = new PrimusCoreTLS();Likely invalid or redundant comment.
packages/plugin-primus/src/providers/tokenPriceProvider.ts (1)
1-3
: LGTM! Clean imports with proper types.
feat: Primus zkTLS plugin to fully verify agent activities
Risks
Low
Background
Verifiable agent is emerging and zkTLS is a promising way to enhance transparency and trust for AI Agents. The current solutions focus on the verifiability of LLM inference, but it is not all the behaviour of an agent. In the Eliza framework. LLM is the brain of agent, but it also have actions and external source providers. We aim to make all these activities verifiable.
Recap of zkTLS: zkTLS is a cryptographic protocol that allows third parties to verify the authenticity of TLS transcripts in a privacy-preserving way.
What does this PR do?
This PR introduces the Primus adapter and plugin, enabling verifiability for LLM inference, actions, and interactions with external providers. Different zkTLS modes are provided, including MPC-TLS and Proxy-TLS.
What kind of change is this?
Features
Why are we doing this? Any context or related work?
In the Eliza framework, an agent consists of three key components: a brain (accessing an LLM), actions (the tasks the
agent performs), and perception (gathering external information from providers). To fully verify agent activities, it's
essential to ensure that the agent's thoughts, actions, and external information requests are all verifiable.
Documentation changes needed?
The documentation in
packages/plugin-primus/README.md
has been updated, with no further changes needed.Testing
Where should a reviewer start?
packages/plugin-primus/README.md
Detailed testing steps
Please follow the steps in
packages/plugin-primus/README.md
.