Skip to content

Commit

Permalink
Merge branch 'develop' into docs_update
Browse files Browse the repository at this point in the history
  • Loading branch information
shakkernerd authored Dec 26, 2024
2 parents c861729 + 8bdd3ca commit 51092fc
Show file tree
Hide file tree
Showing 36 changed files with 2,569 additions and 1,399 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,7 @@ STORY_PRIVATE_KEY= # Story private key
STORY_API_BASE_URL= # Story API base URL
STORY_API_KEY= # Story API key
PINATA_JWT= # Pinata JWT for uploading files to IPFS

# Cronos zkEVM
CRONOSZKEVM_ADDRESS=
CRONOSZKEVM_PRIVATE_KEY=
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ packages/core/src/providers/cache
packages/core/src/providers/cache/*
cache/*
packages/plugin-coinbase/src/plugins/transactions.csv
packages/plugin-coinbase/package-lock.json

tsup.config.bundled_*.mjs

Expand Down
2 changes: 2 additions & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
"@elizaos/plugin-multiversx": "workspace:*",
"@elizaos/plugin-near": "workspace:*",
"@elizaos/plugin-zksync-era": "workspace:*",
"@elizaos/plugin-cronoszkevm": "workspace:*",
"@elizaos/plugin-3d-generation": "workspace:*",
"readline": "1.3.0",
"ws": "8.18.0",
"yargs": "17.7.2"
Expand Down
25 changes: 25 additions & 0 deletions agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { evmPlugin } from "@elizaos/plugin-evm";
import { storyPlugin } from "@elizaos/plugin-story";
import { flowPlugin } from "@elizaos/plugin-flow";
import { imageGenerationPlugin } from "@elizaos/plugin-image-generation";
import { ThreeDGenerationPlugin } from "@elizaos/plugin-3d-generation";
import { multiversxPlugin } from "@elizaos/plugin-multiversx";
import { nearPlugin } from "@elizaos/plugin-near";
import { nftGenerationPlugin } from "@elizaos/plugin-nft-generation";
Expand All @@ -55,6 +56,7 @@ import { suiPlugin } from "@elizaos/plugin-sui";
import { TEEMode, teePlugin } from "@elizaos/plugin-tee";
import { tonPlugin } from "@elizaos/plugin-ton";
import { zksyncEraPlugin } from "@elizaos/plugin-zksync-era";
import { cronosZkEVMPlugin } from "@elizaos/plugin-cronoszkevm";
import { abstractPlugin } from "@elizaos/plugin-abstract";
import Database from "better-sqlite3";
import fs from "fs";
Expand Down Expand Up @@ -178,6 +180,25 @@ export async function loadCharacters(
const character = JSON.parse(content);
validateCharacterConfig(character);

// .id isn't really valid
const characterId = character.id || character.name;
const characterPrefix = `CHARACTER.${characterId.toUpperCase().replace(/ /g, "_")}.`;

const characterSettings = Object.entries(process.env)
.filter(([key]) => key.startsWith(characterPrefix))
.reduce((settings, [key, value]) => {
const settingKey = key.slice(characterPrefix.length);
return { ...settings, [settingKey]: value };
}, {});

if (Object.keys(characterSettings).length > 0) {
character.settings = character.settings || {};
character.settings.secrets = {
...characterSettings,
...character.settings.secrets,
};
}

// Handle plugins
if (isAllStrings(character.plugins)) {
elizaLogger.info("Plugins are: ", character.plugins);
Expand Down Expand Up @@ -516,6 +537,7 @@ export async function createAgent(
getSecret(character, "HEURIST_API_KEY")
? imageGenerationPlugin
: null,
getSecret(character, "FAL_API_KEY") ? ThreeDGenerationPlugin : null,
...(getSecret(character, "COINBASE_API_KEY") &&
getSecret(character, "COINBASE_PRIVATE_KEY")
? [
Expand Down Expand Up @@ -544,6 +566,9 @@ export async function createAgent(
getSecret(character, "APTOS_PRIVATE_KEY") ? aptosPlugin : null,
getSecret(character, "MVX_PRIVATE_KEY") ? multiversxPlugin : null,
getSecret(character, "ZKSYNC_PRIVATE_KEY") ? zksyncEraPlugin : null,
getSecret(character, "CRONOSZKEVM_PRIVATE_KEY")
? cronosZkEVMPlugin
: null,
getSecret(character, "TON_PRIVATE_KEY") ? tonPlugin : null,
getSecret(character, "SUI_PRIVATE_KEY") ? suiPlugin : null,
getSecret(character, "STORY_PRIVATE_KEY") ? storyPlugin : null,
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ You can run Grok models by setting the `XAI_MODEL` environment variable to `grok

### Run with OpenAI

You can run OpenAI models by setting the `XAI_MODEL` environment variable to `gpt-4o-mini` or `gpt-4o`
You can run OpenAI models by setting the `XAI_MODEL` environment variable to `gpt-4-mini` or `gpt-4o`

## Additional Requirements

Expand Down
3 changes: 3 additions & 0 deletions docs/docs/core/actions.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface Action {
examples: ActionExample[][];
handler: Handler;
validate: Validator;
suppressInitialMessage?: boolean;
}
```

Expand Down Expand Up @@ -151,6 +152,7 @@ interface Action {
state?: State,
) => Promise<void>;
examples: ActionExample[][];
suppressInitialMessage?: boolean;
}
```

Expand All @@ -162,6 +164,7 @@ interface Action {
- **validate**: Determines if the action can be executed
- **handler**: Implements the action's behavior
- **examples**: Demonstrates proper usage patterns
- **suppressInitialMessage**: When true, suppresses the initial response message before processing the action. Useful for actions that generate their own responses (like image generation)

---

Expand Down
9 changes: 6 additions & 3 deletions docs/docs/guides/secrets-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ A comprehensive guide for managing secrets, API keys, and sensitive configuratio

Eliza uses a hierarchical environment variable system:

1. Character-specific secrets (highest priority)
2. Environment variables
3. Default values (lowest priority)
1. Character-specific namespaced environment variables (highest priority)
2. Character-specific secrets
3. Environment variables
4. Default values (lowest priority)

### Secret Types

Expand Down Expand Up @@ -96,6 +97,8 @@ Define secrets in character files:
}
```

Alternatively, you can use the `CHARACTER.YOUR_CHARACTER_NAME.SECRET_NAME` format inside your `.env` file.

Access secrets in code:

```typescript
Expand Down
14 changes: 14 additions & 0 deletions docs/docs/packages/agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ export async function initializeClients(

### Token Management

Tokens can be configured in two ways:

1. Using namespaced environment variables:
```env
CHARACTER.YOUR_CHARACTER_NAME.OPENAI_API_KEY=sk-...
CHARACTER.YOUR_CHARACTER_NAME.ANTHROPIC_API_KEY=sk-...
```

2. Using character settings:
```typescript
export function getTokenForProvider(
provider: ModelProviderName,
Expand All @@ -181,6 +190,11 @@ export function getTokenForProvider(
}
```

The system will check for tokens in the following order:
1. Character-specific namespaced env variables
2. Character settings from JSON
3. Global environment variables

### Database Selection

```typescript
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"preinstall": "npx only-allow pnpm",
"build": "turbo run build --filter=!eliza-docs",
"build-docker": "turbo run build",
"cleanstart": "if [ -f agent/data/db.sqlite ]; then rm agent/data/db.sqlite; fi && pnpm --filter \"@elizaos/agent\" start --isRoot",
"cleanstart:debug": "if [ -f agent/data/db.sqlite ]; then rm agent/data/db.sqlite; fi && cross-env NODE_ENV=development VERBOSE=true DEBUG=eliza:* pnpm --filter \"@elizaos/agent\" start --isRoot",
"start": "pnpm --filter \"@elizaos/agent\" start --isRoot",
"start:client": "pnpm --dir client dev",
"start:debug": "cross-env NODE_ENV=development VERBOSE=true DEBUG=eliza:* pnpm --filter \"@elizaos/agent\" start --isRoot",
Expand Down
21 changes: 18 additions & 3 deletions packages/client-direct/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ export class DirectClient {

await runtime.evaluate(memory, state);

// Check if we should suppress the initial message
const action = runtime.actions.find(
(a) => a.name === response.action
);
const shouldSuppressInitialMessage =
action?.suppressInitialMessage;

const _result = await runtime.processActions(
memory,
[responseMessage],
Expand All @@ -232,10 +239,18 @@ export class DirectClient {
}
);

if (message) {
res.json([response, message]);
if (!shouldSuppressInitialMessage) {
if (message) {
res.json([response, message]);
} else {
res.json([response]);
}
} else {
res.json([response]);
if (message) {
res.json([message]);
} else {
res.json([]);
}
}
}
);
Expand Down
19 changes: 10 additions & 9 deletions packages/client-twitter/src/interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ Recent interactions between {{agentName}} and other users:
{{recentPosts}}
# Task: Generate a post/reply in the voice, style and perspective of {{agentName}} (@{{twitterUserName}}) while using the thread of tweets as additional context:
# TASK: Generate a post/reply in the voice, style and perspective of {{agentName}} (@{{twitterUserName}}) while using the thread of tweets as additional context:
Current Post:
{{currentPost}}
Thread of Tweets You Are Replying To:
{{formattedConversation}}
{{actions}}
# Task: Generate a post in the voice, style and perspective of {{agentName}} (@{{twitterUserName}}). You MUST include an action if the current post text includes a prompt that is similar to one of the available actions mentioned here:
# INSTRUCTIONS: Generate a post in the voice, style and perspective of {{agentName}} (@{{twitterUserName}}). You MUST include an action if the current post text includes a prompt that is similar to one of the available actions mentioned here:
{{actionNames}}
{{actions}}
Here is the current post text again. Remember to include an action if the current post text includes a prompt that asks for one of the available actions mentioned above (does not need to be exact)
{{currentPost}}
` + messageCompletionFooter;
Expand All @@ -69,18 +71,17 @@ For other users:
- {{agentName}} should STOP if conversation is concluded
- {{agentName}} is in a room with other users and wants to be conversational, but not annoying.
{{recentPosts}}
IMPORTANT: For users not in the priority list, {{agentName}} (@{{twitterUserName}}) should err on the side of IGNORE rather than RESPOND if in doubt.
IMPORTANT:
- {{agentName}} (aka @{{twitterUserName}}) is particularly sensitive about being annoying, so if there is any doubt, it is better to IGNORE than to RESPOND.
- For users not in the priority list, {{agentName}} (@{{twitterUserName}}) should err on the side of IGNORE rather than RESPOND if in doubt.
Recent Posts:
{{recentPosts}}
IMPORTANT: {{agentName}} (aka @{{twitterUserName}}) is particularly sensitive about being annoying, so if there is any doubt, it is better to IGNORE than to RESPOND.
Current Post:
{{currentPost}}
Thread of Tweets You Are Replying To:
{{formattedConversation}}
# INSTRUCTIONS: Respond with [RESPOND] if {{agentName}} should respond, or [IGNORE] if {{agentName}} should not respond to the last message and [STOP] if {{agentName}} should stop participating in the conversation.
Expand Down
6 changes: 3 additions & 3 deletions packages/client-twitter/src/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,10 @@ export class TwitterPostClient {
if (postImmediately) {
await this.generateNewTweet();
}
generateNewTweetLoop();

// Add check for ENABLE_ACTION_PROCESSING before starting the loop
const enableActionProcessing =
this.runtime.getSetting("ENABLE_ACTION_PROCESSING") ?? false;
this.runtime.getSetting("ENABLE_ACTION_PROCESSING") === "true" || false;

if (enableActionProcessing) {
processActionsLoop().catch((error) => {
Expand All @@ -184,10 +183,11 @@ export class TwitterPostClient {
error
);
});
generateNewTweetLoop();
} else {
elizaLogger.log("Action processing loop disabled by configuration");
}

generateNewTweetLoop();
}

constructor(client: ClientBase, runtime: IAgentRuntime) {
Expand Down
Loading

0 comments on commit 51092fc

Please sign in to comment.