Skip to content

Commit

Permalink
Merge branch 'elizaOS:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
astinz authored Dec 26, 2024
2 parents 8d92049 + cc4af0f commit b48ef3a
Show file tree
Hide file tree
Showing 25 changed files with 2,193 additions and 1,385 deletions.
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
1 change: 1 addition & 0 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@elizaos/plugin-multiversx": "workspace:*",
"@elizaos/plugin-near": "workspace:*",
"@elizaos/plugin-zksync-era": "workspace:*",
"@elizaos/plugin-3d-generation": "workspace:*",
"readline": "1.3.0",
"ws": "8.18.0",
"yargs": "17.7.2"
Expand Down
23 changes: 23 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 Down Expand Up @@ -178,6 +179,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 +536,9 @@ 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
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
Loading

0 comments on commit b48ef3a

Please sign in to comment.