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: register custom service method #2348

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

tcm390
Copy link
Collaborator

@tcm390 tcm390 commented Jan 16, 2025

related: #2315

Currently, when someone want to create a new service, they must add new type as string to enum ServiceType in packages/core/src/types.

For example, right now, WebSearchService is defined in a community plugin, not in the core package. As a result, there's no ServiceType.WEB_SEARCH nor IWebSearchService in core. This makes it impossible to write code like:

import { IWebSearchService, ServiceType } from "@elizaos/core";

const websearchService = runtime.getService<IWebSearchService>(ServiceType.WEB_SEARCH);

outside the plugin, because IWebSearchService and WEB_SEARCH only exist inside the websearch plugin.

To work around this, I currently have to add WEB_SEARCH and IWebSearchService to core’s types.ts file. That defeats the purpose of having a decoupled, community-managed plugin.

This PR aims to resolve that by allowing external code to create the custom service without needing to modify or depend on core’s enums and interfaces

For example, if I need to call the web search service from the image plugin, I could do:

const latestNews = await runtime.callServiceMethod(
            "web_search",
            "search",
            {
                query: "latest news on AI Agents",
                limit: 5,
                includeImages: true,
            }
); 

@tcm390 tcm390 marked this pull request as draft January 16, 2025 03:02
@odilitime odilitime changed the title register custom service method feat: register custom service method Jan 16, 2025
@tcm390 tcm390 marked this pull request as ready for review January 16, 2025 04:48
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.

1 participant