Skip to content
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: plugin for OriginTrail Decentralized Knowledge Graph #2380

Merged
merged 17 commits into from
Jan 22, 2025

Conversation

brkagithub
Copy link
Contributor

@brkagithub brkagithub commented Jan 16, 2025

Relates to

N/A - New plugin contribution

Risks

Low:

  • Requires you to explicitly provide your private key in the environment variable before it does anything with your funds
  • Creation of OriginTrail Knowledge Assets spends your TRAC token based on the network's average ask, so there's no way to overspend tokens

Background

What does this PR do?

Adds support for a plugin which provides additional context to the agent by querying the OriginTrail DKG, as well as creating each memory on the OriginTrail DKG.

What kind of change is this?

Features (non-breaking change which adds functionality)

Documentation changes needed?

My changes do not require a change to the project documentation. A README has been added for this plugin as a guideline for any users.

Testing

Where should a reviewer start?

src/actions/dkgInsert (action that inserts a memory to the DKG)
src/providers/graphSearch (provider that searches the graph and provides additional context)

Detailed testing steps

Add your DKG Node and wallet details to the .env (description of each variable is either obvious or explained in the .env.example). You can DM me on Discord (@Brka) and I can provide a testnet node, as well as testnet funds in case you don't have one on one of the supported networks (Base, Gnosis, NeuroWeb)

Initiate a conversation with the agent, the provider should run and provide additional info to the context, which you can confirm by checking whether new logs are being printed (that the graph is being queried). After that, the action should run and a Knowledge Asset should succesfully be created on the DKG, which should also be logged

Screenshots

None needed

Deploy Notes

N/A

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @brkagithub! Welcome to the elizaOS community. Thanks for submitting your first pull request; your efforts are helping us accelerate towards AGI. We'll review it shortly. You are now an elizaOS contributor!

@brkagithub brkagithub changed the title feat: plugin for OriginTrail Decentralized Knowledge Graph (NOT READY) feat: plugin for OriginTrail Decentralized Knowledge Graph Jan 16, 2025
@JoeyKhd
Copy link
Member

JoeyKhd commented Jan 16, 2025

@brkagithub can you please make this a draft pr since it's not ready. thanks

@brkagithub brkagithub changed the title (NOT READY) feat: plugin for OriginTrail Decentralized Knowledge Graph feat: plugin for OriginTrail Decentralized Knowledge Graph Jan 16, 2025
@brkagithub
Copy link
Contributor Author

apologies @JoeyKhd, it's ready now

also some notes:

  • after merging with develop I found a potential bug with hasValidRemoteUrls function which made the agent crash on start
  • happened to me once that pnpm install told me that there are conflicting packages, tho those packages are not at all used by any of the dependencies i added to my plugin (it also stopped happening so i believe it's fine and was caused by the quick development on the develop branch)

@monilpat
Copy link
Collaborator

Thanks so much for adding this plugin - been waiting for elizaOS to have a DKG integration let me review rn :)

Copy link
Collaborator

@monilpat monilpat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You really crushed it! Thank you SO much for integrating with elizaOS! We are so stoked to use it! I understand it is a WIP PR but wanted to share feedback to make it easier for you to iterate! Thanks so much for this honestly gamechanging addition to eliza! Appreciate you and your hard work here!

packages/plugin-dkg/src/actions/dkgInsert.ts Outdated Show resolved Hide resolved
packages/plugin-dkg/src/actions/dkgInsert.ts Outdated Show resolved Hide resolved
packages/plugin-dkg/src/actions/dkgInsert.ts Show resolved Hide resolved
packages/plugin-dkg/src/actions/dkgInsert.ts Outdated Show resolved Hide resolved
packages/plugin-dkg/src/actions/dkgInsert.ts Outdated Show resolved Hide resolved
packages/plugin-dkg/src/providers/graphSearch.ts Outdated Show resolved Hide resolved
packages/plugin-dkg/src/providers/graphSearch.ts Outdated Show resolved Hide resolved
@brkagithub
Copy link
Contributor Author

brkagithub commented Jan 17, 2025

You really crushed it! Thank you SO much for integrating with elizaOS! We are so stoked to use it! I understand it is a WIP PR but wanted to share feedback to make it easier for you to iterate! Thanks so much for this honestly gamechanging addition to eliza! Appreciate you and your hard work here!

Thanks for the nice words, I'm glad you know about the DKG :D Also thanks a lot for the suggestions, still getting used to the repo and the style, happy to implement these and improve the code readability and make it more useful with types

Just for clarification, we have some // TODO comments which I would like to leave in the code so the contributors know where they can contribute potentially, and also for devs from our side so that's it's obvious from the code which could be the future improvements. The PR itself is not WIP, will implement these improvements tho

Our long term plan for Eliza is to be a KG adapter - however atm this seems like a bunch of work so we wanted to go for a plugin first and iterate, also since the V2 will be releasing soon we thought it might be better to wait for it before we go for such a big push, would be amazing if we could get early access also (would love to discuss it outside of the PR convo :D)

Anyways PR is ready for review again, and if it's all good I'm excited to get it merged! Also let me know if I should be constantly merging with the elizaOS remote or wait until you're done reviewing so I don't have to merge all the time, since new changes are always added to the develop branch, causing conflicts

@monilpat

@brkagithub brkagithub requested a review from monilpat January 17, 2025 14:43
@wtfsayo
Copy link
Member

wtfsayo commented Jan 17, 2025

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This pull request introduces the OriginTrail Decentralized Knowledge Graph (DKG) plugin for ElizaOS, expanding the agent's capabilities to interact with decentralized knowledge networks. The changes include configuration updates, a new plugin package, and supporting infrastructure for storing and retrieving knowledge assets across different blockchain environments.

Changes

File Change Summary
.env.example Added DKG-related configuration variables for environment, hostname, port, keys, and blockchain name
agent/package.json Added @elizaos/plugin-dkg as a workspace dependency
agent/src/index.ts Imported DKG plugin and conditionally added to agent initialization
packages/plugin-dkg/* Created new plugin package with comprehensive configuration, actions, providers, and documentation for DKG integration

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (10)
packages/plugin-dkg/src/actions/dkgInsert.ts (2)

81-86: Simplify conditional checks with optional chaining

You can use optional chaining to simplify the condition when checking match[1].

Apply this diff:

- if (match && match[1]) {
+ if (match?.[1]) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 81-81: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


92-97: Simplify conditional checks with optional chaining

Similarly, simplify the condition for match[1] using optional chaining.

Apply this diff:

- if (match && match[1]) {
+ if (match?.[1]) {
🧰 Tools
🪛 Biome (1.9.4)

[error] 92-92: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/plugin-dkg/src/providers/graphSearch.ts (1)

200-201: Correct the error log message

The error message mentions "wallet provider" instead of "graphSearch provider".

Apply this diff:

- elizaLogger.error("Error in wallet provider:", error);
+ elizaLogger.error("Error in graphSearch provider:", error);
packages/plugin-dkg/tsup.config.ts (1)

8-8: Fix misleading comment.

The comment suggests CommonJS but the configuration is set to ESM format.

-    format: ["esm"], // Ensure you're targeting CommonJS
+    format: ["esm"],
packages/plugin-dkg/src/types.ts (2)

25-27: Strengthen SPARQL query validation.

The current validation only checks if the query starts with "SELECT". Consider adding more comprehensive validation for SPARQL syntax.

-    query: z.string().startsWith("SELECT"),
+    query: z.string()
+      .regex(/^SELECT\s+(?:DISTINCT\s+)?[?]\w+(?:\s+[?]\w+)*\s+WHERE\s*{[\s\S]*}\s*(?:LIMIT\s+\d+\s*)?$/i, 
+        "Invalid SPARQL SELECT query format"),

32-34: Improve type guard parameter types.

Replace any with unknown for better type safety.

-export const isDKGMemoryContent = (object: any): object is DKGMemoryContent => {
+export const isDKGMemoryContent = (object: unknown): object is DKGMemoryContent => {

-export const isDKGSelectQuery = (object: any): object is DKGSelectQuery => {
+export const isDKGSelectQuery = (object: unknown): object is DKGSelectQuery => {

Also applies to: 36-38

packages/plugin-dkg/src/constants.ts (2)

1-1: Track TODO comment.

The TODO comment about connecting Knowledge Assets should be tracked in the issue system.

Would you like me to create a GitHub issue to track this enhancement for connecting Knowledge Assets?


93-96: Parameterize example values in SPARQL queries.

Replace hardcoded example values with template parameters for better reusability.

-        CONTAINS(LCASE(?headline), "example_keyword") ||
+        CONTAINS(LCASE(?headline), ${keyword}) ||

Also applies to: 119-122, 133-134, 147-148, 161-162

packages/plugin-dkg/README.md (1)

70-72: Fix list indentation.

Adjust the indentation to use 2 spaces for nested lists to comply with markdown standards:

- Node information.
- LLM key.
- Twitter credentials.
+ - Node information.
+ - LLM key.
+ - Twitter credentials.
🧰 Tools
🪛 Markdownlint (0.37.0)

70-70: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


71-71: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


72-72: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)

.env.example (1)

639-647: Consider adding validation hints for DKG configuration.

The environment variables are well-documented, but consider adding:

  1. Example values for DKG_HOSTNAME
  2. Format requirements for DKG_PUBLIC_KEY and DKG_PRIVATE_KEY
  3. Default value for DKG_ENVIRONMENT
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5256560 and d725b87.

📒 Files selected for processing (17)
  • .env.example (1 hunks)
  • agent/package.json (1 hunks)
  • agent/src/index.ts (6 hunks)
  • packages/plugin-dkg/.npmignore (1 hunks)
  • packages/plugin-dkg/README.md (1 hunks)
  • packages/plugin-dkg/eslint.config.mjs (1 hunks)
  • packages/plugin-dkg/package.json (1 hunks)
  • packages/plugin-dkg/src/actions/dkgInsert.ts (1 hunks)
  • packages/plugin-dkg/src/actions/index.ts (1 hunks)
  • packages/plugin-dkg/src/constants.ts (1 hunks)
  • packages/plugin-dkg/src/index.ts (1 hunks)
  • packages/plugin-dkg/src/providers/graphSearch.ts (1 hunks)
  • packages/plugin-dkg/src/providers/index.ts (1 hunks)
  • packages/plugin-dkg/src/templates.ts (1 hunks)
  • packages/plugin-dkg/src/types.ts (1 hunks)
  • packages/plugin-dkg/tsconfig.json (1 hunks)
  • packages/plugin-dkg/tsup.config.ts (1 hunks)
✅ Files skipped from review due to trivial changes (6)
  • packages/plugin-dkg/src/actions/index.ts
  • packages/plugin-dkg/src/providers/index.ts
  • packages/plugin-dkg/.npmignore
  • packages/plugin-dkg/eslint.config.mjs
  • packages/plugin-dkg/tsconfig.json
  • packages/plugin-dkg/package.json
🧰 Additional context used
🪛 Markdownlint (0.37.0)
packages/plugin-dkg/README.md

70-70: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


71-71: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)


72-72: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)

🪛 Biome (1.9.4)
packages/plugin-dkg/src/actions/dkgInsert.ts

[error] 81-81: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 92-92: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (5)
packages/plugin-dkg/src/index.ts (1)

1-16: LGTM!

The plugin is correctly defined and exports are appropriately handled.

packages/plugin-dkg/src/templates.ts (1)

17-17: Clarify UUID format requirements.

The instruction mentions using UUIDs but doesn't specify the format (v4, v5, etc.) or how to generate them consistently.

agent/src/index.ts (1)

98-98: LGTM! DKG plugin integration follows established patterns.

The plugin is properly imported and conditionally initialized based on the presence of required environment variables.

Also applies to: 816-819, 960-960

packages/plugin-dkg/README.md (1)

77-77: Verify the file path reference.

The path plugin-dkg/constants.ts might be incorrect. Consider using the full package name @elizaos/plugin-dkg/src/constants.ts or providing the relative path from the project root.

agent/package.json (1)

102-102: LGTM! Dependency correctly added.

The DKG plugin is properly added as a workspace dependency.

packages/plugin-dkg/src/actions/dkgInsert.ts Show resolved Hide resolved
packages/plugin-dkg/src/actions/dkgInsert.ts Show resolved Hide resolved
packages/plugin-dkg/tsup.config.ts Show resolved Hide resolved
packages/plugin-dkg/src/constants.ts Show resolved Hide resolved
@wtfsayo
Copy link
Member

wtfsayo commented Jan 20, 2025

can you fix conflicts @brkagithub and also give access to push changes

@brkagithub
Copy link
Contributor Author

Conflicts are resolved @wtfsayo, hopefully there will be no more pushes to elizaOS/develop until you see it :D Giving you write access

@brkagithub
Copy link
Contributor Author

is there a problem @wtfsayo? Would be great to merge if you're happy with the PR, since every time something new gets pushed to develop, we get more conflicts

@wtfsayo
Copy link
Member

wtfsayo commented Jan 21, 2025

is there a problem @wtfsayo? Would be great to merge if you're happy with the PR, since every time something new gets pushed to develop, we get more conflicts

i will take care tomorrow

@wtfsayo wtfsayo enabled auto-merge (squash) January 22, 2025 09:11
@wtfsayo wtfsayo removed the request for review from monilpat January 22, 2025 09:14
@wtfsayo wtfsayo merged commit 066f49b into elizaOS:develop Jan 22, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants