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

Enhance Character Selection UX and Fix Minor Typos #153

Merged
merged 8 commits into from
Jan 18, 2025
Merged
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
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
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;
};
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);
}
jfrank-summit marked this conversation as resolved.
Show resolved Hide resolved
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
Loading