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: Add State of Mika plugin to Eliza #3304

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,8 @@ DEFAULT_FROM_EMAIL= # Default sender
EMAIL_AUTOMATION_ENABLED=false # Enable AI detection. If this is enabled, the plugin will automatically detect email-worthy conversations and handle generation/delivery and only that.
EMAIL_EVALUATION_PROMPT= # Custom detection criteria for shouldEmail# ####################################

# State of Mika Plugin Configuration
SOM_API_KEY=1ef4dccd-c80a-410b-86c6-220df04ab589 # public shared api key

# #### ANKR Configuration ####
# ####################################
Expand Down
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
"@elizaos/plugin-solana-v2": "workspace:*",
"@elizaos/plugin-injective": "workspace:*",
"@elizaos/plugin-solana-agent-kit": "workspace:*",
"@elizaos/plugin-som": "workspace:*",
"@elizaos/plugin-squid-router": "workspace:*",
"@elizaos/plugin-autonome": "workspace:*",
"@elizaos/plugin-starknet": "workspace:*",
Expand Down
6 changes: 4 additions & 2 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import { sgxPlugin } from "@elizaos/plugin-sgx";
import { solanaPlugin } from "@elizaos/plugin-solana";
import { solanaPluginV2 } from "@elizaos/plugin-solana-v2";
import { solanaAgentkitPlugin } from "@elizaos/plugin-solana-agent-kit";
import { somPlugin } from "@elizaos/plugin-som";
import { squidRouterPlugin } from "@elizaos/plugin-squid-router";
import { stargazePlugin } from "@elizaos/plugin-stargaze";
import { storyPlugin } from "@elizaos/plugin-story";
Expand Down Expand Up @@ -1058,6 +1059,7 @@ export async function createAgent(
getSecret(character, "SOLANA_PRIVATE_KEY")
? solanaAgentkitPlugin
: null,
getSecret(character, "SOM_API_KEY") ? somPlugin : null,
getSecret(character, "AUTONOME_JWT_TOKEN") ? autonomePlugin : null,
(getSecret(character, "NEAR_ADDRESS") ||
getSecret(character, "NEAR_WALLET_PUBLIC_KEY")) &&
Expand All @@ -1069,8 +1071,8 @@ export async function createAgent(
getSecret(character, "WALLET_PUBLIC_KEY")?.startsWith("0x"))
? evmPlugin
: null,
(getSecret(character, "EVM_PRIVATE_KEY") ||
getSecret(character, "SOLANA_PRIVATE_KEY"))
getSecret(character, "EVM_PRIVATE_KEY") ||
getSecret(character, "SOLANA_PRIVATE_KEY")
? edwinPlugin
: null,
(getSecret(character, "EVM_PUBLIC_KEY") ||
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-som/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*

!dist/**
!package.json
!readme.md
!tsup.config.ts
148 changes: 148 additions & 0 deletions packages/plugin-som/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# @elizaos/plugin-som

A plugin for integrating the State of Mika AI engine into the ElizaOS ecosystem, enabling real-time, self-improving AI inferences and high-performance insights.

## Description

The SoM plugin provides various AI-powered functionalities to enhance the capabilities of ElizaOS. With this plugin, users can perform advanced AI-driven tasks such as image recognition, content scraping, market data retrieval, mathematical computations, and cryptocurrency analytics.

## Features

- Image Recognition - Analyze and describe images using AI vision.
- Web Scraper - Scrape and process content from external websites.
- News Aggregation - Fetch and analyze cryptocurrency and blockchain-related news.
- Token Information - Retrieve token prices and market data from DEX aggregators.
- Mathematical Computation - Perform complex mathematical calculations.
- Solana DEX Sales - Retrieve decentralized exchange (DEX) sales data for a Solana mint address within a specified time window.
- Solana DEX Buys - Get buy orders for a specific Solana token by a particular signer address.

## Configuration

To get credentials contact [ChasmNetwork](https://x.com/chasmnetwork)

To use the plugin, an API key for the SoM service is required. Ensure the following environment variable is set:

```bash
SOM_API_KEY=<your_som_api_key>
```

## Installation

```bash
pnpm install @elizaos/plugin-som
```

## Usage

### Basic Integration

```typescript
import { somPlugin } from "@elizaos/plugin-som";
```

### Query Routing Example

The plugin automatically handles requests based on the type of query:

```typescript
"What is the current price of Ethereum?";
"Fetch the latest news on blockchain technology.";
"Analyze this image and describe its contents.";
```

## API Reference

### Actions

1. ROUTE_QUERIES

Routes AI-driven queries to the appropriate service, including:

- News
- Token Information
- Math Calculations
- Solana DEX Transactions
- Scraping
- Image Recognition

**Aliases:**

- ROUTE
- QUERY
- PROCESS

**Input Content:**

```typescript
export interface SOMRequestFormData extends FormData {
append(name: "query", value: string): void;
}
```

## Common Issues & Troubleshooting

**API Key Issues**

- Ensure SOM_API_KEY is set correctly in your environment variables.
- Verify that the API key is valid and has the necessary permissions.

**Response Issues**

- If the API does not return a response, check for network connectivity.
- Ensure that the request data is correctly formatted.

## Security Best Practices

**API Key Management**

- Never commit API keys to version control.
- Store API keys securely using environment variables or secret management tools.
- Rotate API keys periodically for enhanced security.

## Development Guide

### Setting Up Development Environment

1. Clone the repository
2. Install dependencies:

```bash
pnpm install
```

3. Build the plugin:

```bash
pnpm run build
```

4. Run the plugin:

```bash
pnpm run dev
```

## Future Enhancements

- Extend support for additional blockchain networks beyond Solana.
- Improve natural language processing capabilities for better query interpretation.
- Integrate AI-based forecasting models for financial predictions.

## Contributing

Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information.

## Credits

This plugin integrates with and builds upon several key technologies:

- State of Mika AI: AI-powered inference and analytics.
- ElizaOS: Modular AI-powered OS framework.

Special thanks to:

- The ElizaOS community for their contributions and support.

## License

This plugin is part of the ElizaOS project. See the main project repository for license information.
33 changes: 33 additions & 0 deletions packages/plugin-som/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"name": "@elizaos/plugin-som",
"version": "0.1.0",
"type": "module",
"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"@elizaos/source": "./src/index.ts",
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"files": [
"dist"
],
"dependencies": {
"@elizaos/core": "workspace:*",
"axios": "^1.7.9"
},
"devDependencies": {
"tsup": "8.3.5",
"vitest": "^3.0.0"
},
"scripts": {
"build": "tsup --format esm --dts",
"dev": "tsup --format esm --dts --watch"
}
}
124 changes: 124 additions & 0 deletions packages/plugin-som/src/actions/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import {
Action,
composeContext,
elizaLogger,
generateObject,
IAgentRuntime,
Memory,
ModelClass,
State,
} from "@elizaos/core";
import { buildRequestData, callSomApi, validateApiKey } from "../utils";
import { z } from "zod";

const getQueryTemplate = `Respond with a JSON markdown block containing only the extracted values. Use null for any values that cannot be determined.

Example response:
\`\`\`json
{
"query": "What is the weather in Nairobi?",
}
\`\`\`

{{recentMessages}}

Given the recent messages, extract the following information about the user query:
- The original query

Respond with a JSON markdown block containing only the extracted values.`;

export const routeQueries: Action = {
name: "ROUTE_QUERIES",
similes: ["route", "query", "process"],
description: `Route any of the below queries to get the required information:
- News
- Token information
- Math
- Solana dex
- Scraping
- Image recognition`,

validate: async (
runtime: IAgentRuntime,
_message: Memory
): Promise<boolean> => {
return !!runtime.getSetting("SOM_API_KEY");
},

handler: async (runtime, message, state, _options, callback) => {
if (!state) {
state = (await runtime.composeState(message)) as State;
} else {
state = await runtime.updateRecentMessageState(state);
}

const context = composeContext({
state,
template: getQueryTemplate,
});

const schema = z.object({
query: z.string(),
});

const content = await generateObject({
runtime,
context: context,
schema: schema,
modelClass: ModelClass.SMALL,
});

const parseResult = schema.safeParse(content.object);
if (!parseResult.success) {
elizaLogger.info(
"somPlugin: Failed to parse query from user message."
);
return;
}

const requestData = buildRequestData(parseResult.data.query);

try {
const apiKey = validateApiKey();
const result = await callSomApi(
"https://state.gmika.io/api/v1/",
requestData,
apiKey
);

if (!result || !result.response.processed_response) {
throw new Error("Failed to get the response from the api");
}
if (callback) {
callback({
text: result.response.processed_response,
});
}
return;
} catch (error) {
elizaLogger.error("somPlugin: failed to call the api", error);
if (callback) {
callback({
text: "Failed to call the api",
});
}
}
},
examples: [
[
{
user: "{{user1}}",
content: {
text: "What is the current price of bitcoin?",
},
},
{
user: "{{user2}}",
content: {
text: "Let me find out the current price of bitcoin",
action: "ROUTE_QUERIES",
},
},
],
],
};
1 change: 1 addition & 0 deletions packages/plugin-som/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_TIMEOUT = 30000; // 30 seconds
22 changes: 22 additions & 0 deletions packages/plugin-som/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import type { Plugin } from "@elizaos/core";
import { routeQueries } from "./actions/router.ts";

// Simple terminal output
console.log("\n===============================");
console.log(" SoM Plugin Loaded ");
console.log("===============================");
console.log("Name : SoM-plugin");
console.log("Version : 0.1.0");
console.log("X Account : https://x.com/ChasmNetwork");
console.log("GitHub : https://github.com/chasmnetwork");
console.log("Author : https://x.com/cloudre01");
console.log("===============================\n");

export const somPlugin: Plugin = {
name: "som",
description: "State of Mika integration plugin for ElizaOS",
actions: [routeQueries],
evaluators: [],
providers: [],
};
export default somPlugin;
Loading