Skip to content

Commit

Permalink
Merge branch 'main' into multi-character-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrank-summit committed Jan 18, 2025
2 parents 097cfac + 294bc93 commit f048b12
Show file tree
Hide file tree
Showing 7 changed files with 389 additions and 46 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ The framework uses a YAML-based character system that allows you to create and r
2. Create new characters by copying the example:
```bash
# Create a new character
cp config/characters/joy_builder.yaml config/characters/my-character.yaml
cp config/characters/character.example.yaml config/characters/my-character.yaml
```

### Character Configuration
Expand Down Expand Up @@ -153,11 +153,14 @@ engagement_criteria:

Run the agent with a specific character:

You can run the agent with a specific character by providing the character name as an argument.

```bash
# Use default character (configured in config.yaml)
yarn dev # for development with auto-reload
yarn dev # for development with auto-reload - select from list of characters
# or
yarn start # for production build and run
yarn start # for production build and run - select from list of characters
# Use a specific character (omit .yaml extension)
yarn dev my-agent # for development with auto-reload
Expand Down Expand Up @@ -221,7 +224,7 @@ To use this feature:
1. Configure your AUTO_DRIVE_API_KEY in `.env` (obtain from https://ai3.storage)
2. Enable Auto Drive uploading in your `config.yaml`:
```yaml
autodrive:
auto_drive:
upload: true
```
3. Provide your Taurus EVM wallet details (PRIVATE_KEY) and Agent Memory Contract Address (CONTRACT_ADDRESS) in .env`
Expand All @@ -246,10 +249,10 @@ The KOL workflow enables agents to:
Start the agent with:

```bash
# Use default character
# Use example character or select from list of characters
yarn dev
# Use a specific character (without .ts extension)
# Use specific character
yarn dev my-agent
```

Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "auto-agents-framework",
"version": "0.0.1",
"version": "0.1.0",
"description": "Auto Agents Framework",
"main": "dist/index.js",
"type": "module",
"scripts": {
"build": "tsc && yarn copy-characters",
"start": "yarn build && node dist/index.js",
"dev": "tsx watch src/index.ts",
"dev": "NODE_ENV=development tsx --no-cache --watch src/index.ts",
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
"format:check": "prettier --check \"src/**/*.ts\" \"tests/**/*.ts\"",
"example:twitter": "tsx examples/twitter.ts",
Expand All @@ -33,13 +33,15 @@
"agent-twitter-client": "0.0.18",
"dotenv": "^16.3.1",
"ethers": "^6.13.4",
"inquirer": "^10.2.0",
"winston": "^3.11.0",
"zod": "^3.22.4",
"zod-to-json-schema": "^3.24.1"
},
"devDependencies": {
"@eslint/js": "^9.18.0",
"@tsconfig/node20": "^20.1.4",
"@types/inquirer": "^9.0.7",
"@types/jest": "^29.5.12",
"@types/js-yaml": "^4.0.9",
"@types/node": "22.10.0",
Expand Down
37 changes: 37 additions & 0 deletions src/cli/onboarding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import inquirer from 'inquirer';
import { createLogger } from '../utils/logger.js';
import { listAvailableCharacters } from './utils/characterLoader.js';

const logger = createLogger('onboarding');

interface UserAnswers {
character: string;
}

export const onboarding = async (preselectedCharacter?: string): Promise<UserAnswers> => {
const characters = await listAvailableCharacters();

if (preselectedCharacter) {
const character = characters.find(char => char.id === preselectedCharacter);
if (character) {
logger.info(`Using preselected character: ${character.id}`);
return { character: character.id };
}
throw new Error(`Character "${preselectedCharacter}" not found`);
}

const answers: UserAnswers = await inquirer.prompt([
{
type: 'list',
name: 'character',
message: 'Select a character to run the workflow:',
choices: characters.map(char => ({
name: `${char.id} - ${char.description.split('.')[0]}`,
value: char.id,
})),
},
]);
logger.info(`Character: ${answers.character}`);

return answers;
};
30 changes: 30 additions & 0 deletions src/cli/utils/characterLoader.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { readdir } from 'fs/promises';
import { join } from 'path';
import { loadCharacter } from '../../config/characters.js';

interface CharacterInfo {
id: string;
name: string;
description: string;
username: string;
}

export const listAvailableCharacters = async (): Promise<CharacterInfo[]> => {
const charactersPath = join(process.cwd(), 'config', 'characters');
const files = await readdir(charactersPath);
const characterFiles = files.filter(file => file.endsWith('.yaml'));

const characters = await Promise.all(
characterFiles.map(async file => {
const id = file.replace(/\.yaml$/, '');
const character = loadCharacter(id);
return {
id,
name: character.name,
description: character.description,
username: character.username,
};
}),
);
return characters;
};
2 changes: 1 addition & 1 deletion src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const config = (() => {
autoDriveConfig: {
AUTO_DRIVE_API_KEY: process.env.AUTO_DRIVE_API_KEY,
AUTO_DRIVE_ENCRYPTION_PASSWORD: process.env.AUTO_DRIVE_ENCRYPTION_PASSWORD,
AUTO_DRIVE_UPLOAD: yamlConfig.auto_drive?.upload ?? false,
AUTO_DRIVE_UPLOAD: yamlConfig.auto_drive.upload ?? false,
},
blockchainConfig: {
RPC_URL: process.env.RPC_URL || undefined,
Expand Down
33 changes: 23 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import { config } from './config/index.js';
import { createLogger } from './utils/logger.js';
import { runWorkflow } from './agents/workflows/kol/workflow.js';
import { onboarding } from './cli/onboarding.js';

const logger = createLogger('app');

// Get character name from command line args
const characterId = process.argv[2];
if (!characterId) {
logger.error('Please provide a character name as an argument (e.g., yarn dev argumint)');
process.exit(1);
}
process.on('SIGINT', () => {
logger.info('Received SIGINT. Gracefully shutting down...');
process.exit(0);
});

process.on('SIGTERM', () => {
logger.info('Received SIGTERM. Gracefully shutting down...');
process.exit(0);
});

// Strip any file extension
const cleanCharacterId = characterId.replace(/\.(ya?ml)$/, '');
const characterId = process.argv[2];

const startWorkflowPolling = async () => {
try {
const _result = await runWorkflow(cleanCharacterId);
logger.info('Workflow execution completed successfully');
const character = await onboarding(characterId);
const _result = await runWorkflow(character.character);
logger.info('Workflow execution completed successfully for character:', character.character);
} catch (error) {
if (error && typeof error === 'object' && 'name' in error && error.name === 'ExitPromptError') {
logger.info('Process terminated by user');
process.exit(0);
}
logger.error('Error running workflow:', error);
process.exit(1);
}
};

Expand All @@ -33,6 +42,10 @@ const main = async () => {
username: config.twitterConfig.USERNAME,
});
} catch (error) {
if (error && typeof error === 'object' && 'name' in error && error.name === 'ExitPromptError') {
logger.info('Process terminated by user');
process.exit(0);
}
logger.error('Failed to start application:', error);
process.exit(1);
}
Expand Down
Loading

0 comments on commit f048b12

Please sign in to comment.