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: Direct Client API - Add Delete Agent functionality #2267

Merged
merged 8 commits into from
Jan 14, 2025

Conversation

jason51553262
Copy link
Contributor

@jason51553262 jason51553262 commented Jan 14, 2025

Risks

Low

Background

For my use case, I'm building a web app that can start and stop agents with characters configured in a UI. For this application it's not practical to restart the Eliza Docker Service each time a new agent is added or removed as this will offline existing active agents.
The existing Direct Client API has a POST /agents/:agentId/set endpoint which can be used to either create or update an agent with a character JSON passed into the request body. It makes sense to also implement Delete.

What does this PR do?

Adds the following APIs to Direct Client:

  • DELETE /agents/:agentId (Stops agent clients and unregisters the agent)

I've also added support for an environment variable PREVENT_UNHANDLED_EXIT which when set, will handle both uncaughtException and unhandledRejection and send the exception to console.error instead of allowing the process to terminate.

What kind of change is this?

Improvements (to existing Direct Client API functionality)

Why are we doing this? Any context or related work?

So that an integrated application can start and stop agents without requiring a restart of Eliza

Documentation changes needed?

My changes require a change to the project documentation.

Testing

image

Where should a reviewer start?

Only one change in api.ts

Detailed testing steps

Execute the follow REST calls in Postman:

(Create and Update)
POST http://localhost:3000/agents/:agentId/set { character }

(Delete)
DELETE http://localhost:3000/agents/:agentId

In the character file use a client with a required secret such as telegram and TELEGRAM_BOT_TOKEN.
Test with a valid TELEGRAM_BOT_TOKEN and also test without the TELEGRAM_BOT_TOKEN at all.
In the current build, when you POST /agents/:agentId/set with a telegram client but a missing TELEGRAM_BOT_TOKEN, a validation error will be thrown and the system will exit as the existing code that calls startAgent is not catching this error. Fixing in this PR.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hi @jseparovic! Welcome to the elizaOS community. Thanks for submitting your first pull request; your efforts are helping us accelerate towards AGI. We'll review it shortly. You are now an elizaOS contributor!

@jason51553262 jason51553262 changed the title Improvement: Direct Client API - Add Create and Delete Agent functionality Improvement: Direct Client API - Add Delete Agent functionality Jan 14, 2025
@wtfsayo wtfsayo self-requested a review January 14, 2025 14:30
@wtfsayo
Copy link
Member

wtfsayo commented Jan 14, 2025

lgtm

@wtfsayo wtfsayo enabled auto-merge January 14, 2025 19:43
@wtfsayo wtfsayo merged commit a3bbaf6 into elizaOS:develop Jan 14, 2025
3 checks passed
@odilitime odilitime changed the title Improvement: Direct Client API - Add Delete Agent functionality feat: Direct Client API - Add Delete Agent functionality Jan 16, 2025
@jason51553262 jason51553262 deleted the direct-client_agent-crud branch January 16, 2025 23:54
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