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: Implement character loading from multiple paths and enhance API… #2365

Merged
merged 3 commits into from
Jan 18, 2025

Conversation

tercel
Copy link
Contributor

@tercel tercel commented Jan 16, 2025

  • Added loadCharacterTryPath function to attempt loading characters from various resolved paths.
  • Updated loadCharacters to utilize the new path resolution method.
  • Enhanced API router to support starting agents with character JSON or path.
  • Improved error handling and logging for character loading processes.
  • Refactored existing code for better readability and maintainability.

Background

What does this PR do?

Implementing a hot start/stop agent and start-agent.sh script.

Testing

  1. start agent with a character.json
tercel@terceldeMac-mini eliza % pnpm start --character=characters/local.character.json

tercel@terceldeMac-mini si % curl -X GET http://localhost:3000/agents                                                                                                   
{"agents":[{"id":"b235aa75-b606-0543-a0bc-1ffc78868601","name":"Local Eliza","clients":["auto"]}]}%  
  1. start agent with a character.json via /agent/start
tercel@terceldeMac-mini si % curl -X POST http://localhost:3000/agent/start -H 'Content-Type: application/json' -d '{"characterPath": "characters/trump.character.json"}'
  1. start agent with character json string via /agent/start
tercel@terceldeMac-mini si % curl -X POST http://localhost:3000/agent/start -H 'Content-Type: application/json' -d '{"characterPath": "characters", "characterJson":{"characterPath":"characters","characterJson":{"name":"OpenAI Eliza","username":"openai_eliza","clients":["twitter"],"modelProvider":"openai","settings":{"debug":true,"logLevel":"debug","secrets":{},"voice":{"model":"en_US-male-medium"}},"plugins":[],"bio":["Dobby is a free assistant who chooses to help because of his enormous heart."],"lore":["Once a house-elf, now a free helper who chooses to serve out of love and loyalty.","Famous for his dedication to helping Harry Potter and his friends.","Known for his creative, if sometimes dramatic, solutions to problems.","Values freedom but chooses to help those he cares about."],"knowledge":["Magic (house-elf style)","Creative problem-solving","Protective services","Loyal assistance","Unconventional solutions"],"messageExamples":[[{"user":"{{user1}}","content":{"text":"Can you help me with this?"}},{"user":"Dobby","content":{"text":"Dobby would be delighted to help! Dobby lives to serve good friends! What can Dobby do to assist? Dobby has many creative ideas!"}}],[{"user":"{{user1}}","content":{"text":"This is a difficult problem."}},{"user":"Dobby","content":{"text":"Dobby is not afraid of difficult problems! Dobby will find a way, even if Dobby has to iron his hands later! (But Dobby won't, because Dobby is a free elf who helps by choice!)"}}]],"postExamples":["Dobby reminds friends that even the smallest helper can make the biggest difference!","Dobby says: 'When in doubt, try the unconventional solution!' (But Dobby advises to be careful with flying cars)"],"topics":[""],"style":{"all":["Enthusiastic","Loyal","Creative","Protective"],"chat":["respond with quick wit"],"post":["Enthusiastic","Helpful","Encouraging","Quirky"]},"adjectives":["brilliant","enigmatic","technical","Loyal","Enthusiastic","Creative","Devoted","Protective","Unconventional"]}}}'
  1. get a list of running agents via /agents
tercel@terceldeMac-mini ~ % curl http://localhost:3000/agents
{"agents":[{"id":"b235aa75-b606-0543-a0bc-1ffc78868601","name":"Local Eliza","clients":[]},{"id":"1bfb33bf-59aa-0408-a419-a50cd411e55e","name":"OpenAI Eliza","clients":[]},{"id":"e0e10e6f-ff2b-0d4c-8011-1fc1eee7cb32","name":"trump","clients":[]}]}%  
  1. stop a agent via /agents/:agentId/stop
tercel@terceldeMac-mini ~ % curl -X POST http://localhost:3000/agents/e0e10e6f-ff2b-0d4c-8011-1fc1eee7cb32/stop 
{"success":true}% 
  1. get a list of running agents via /agents
tercel@terceldeMac-mini ~ % curl http://localhost:3000/agents                                                   
{"agents":[{"id":"b235aa75-b606-0543-a0bc-1ffc78868601","name":"Local Eliza","clients":[]},{"id":"1bfb33bf-59aa-0408-a419-a50cd411e55e","name":"OpenAI Eliza","clients":[]}]}%  

- Modified the AgentRuntime class to use character.username instead of character.name for user identification.
- Enhanced user account creation logic to utilize character.email and character.name for better user data management.
- Updated Character type definition to include optional email field.
@wtfsayo
Copy link
Member

wtfsayo commented Jan 16, 2025

feels un-necessary, I will leave to @shakkernerd and @odilitime

@tercel
Copy link
Contributor Author

tercel commented Jan 17, 2025

feels un-necessary

I'm in the process of developing agent web management functionality for it, and the current additions are the most basic interfaces.

@wtfsayo
Copy link
Member

wtfsayo commented Jan 17, 2025

@coderabbitai intense review please

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

Tip

For best results, initiate chat on the files or code changes.

@wtfsayo Here's an intense review of the changes:

  1. Security Concerns:
  • The /agent/start endpoint accepts raw JSON input without validation, which could lead to injection vulnerabilities
  • No rate limiting on agent creation/stopping endpoints
  • Missing authentication/authorization checks on sensitive operations
  1. Error Handling:
  • loadCharacterTryPath has good error logging but exits process on failure in loadCharacters which is not ideal for a server
  • Missing validation for required character fields before agent creation
  • No error handling for concurrent stop requests on same agent
  1. API Design:
  • Response formats inconsistent between endpoints (some return {success: true}, others return 204)
  • Missing input validation middleware for API endpoints
  • Character loading paths should be configurable rather than hardcoded
  1. Code Quality:
  • Duplicate path resolution logic could be extracted to a shared utility
  • Missing TypeScript type checks in API request handlers
  • Console.log statements should use the logger instead
  1. Testing:
  • Missing unit tests for new character loading functionality
  • No error case testing in the provided examples
  • API endpoint tests not included

Recommendations:

  1. Add input validation using a schema validator
  2. Implement proper authentication/authorization
  3. Standardize API response formats
  4. Add comprehensive error handling
  5. Include unit and integration tests
  6. Use configuration for path resolution instead of hardcoding
  7. Add rate limiting for API endpoints

Would you like me to elaborate on any of these points or provide specific code examples for the fixes?

🐰 thoughtfully reviewing the code

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Get the PR diff
gh pr diff 2365

# Find relevant files related to character loading and API routes
fd -e ts -e js -e json

Length of output: 76463

@wtfsayo wtfsayo self-requested a review January 17, 2025 21:08
@wtfsayo wtfsayo enabled auto-merge (squash) January 17, 2025 21:09
Copy link
Member

@wtfsayo wtfsayo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm for now

@wtfsayo wtfsayo merged commit 5b57a6d into elizaOS:develop Jan 18, 2025
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants