service-registry
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTable of Contents
目录
Service Registry
服务注册(Service Registry)
Overview
概述
A registry pattern for managing connections to external services. Handles configuration, health checking, and execution across multiple service integrations.
一种用于管理外部服务连接的注册模式,可处理多服务集成中的配置、健康检查和执行操作。
When To Use
适用场景
- Managing multiple external services.
- Need consistent execution interface.
- Want health monitoring across services.
- Building service failover logic.
- 管理多个外部服务
- 需要统一的执行接口
- 希望对所有服务进行健康监控
- 构建服务故障转移逻辑
When NOT To Use
不适用场景
- Single service integration without registry needs
- 无需注册中心的单一服务集成场景
Core Concepts
核心概念
Service Configuration
服务配置
python
@dataclass
class ServiceConfig:
name: str
command: str
auth_method: str # "api_key", "oauth", "token"
auth_env_var: str
quota_limits: dict
models: list[str] = field(default_factory=list)Verification: Run the command with flag to verify availability.
--helppython
@dataclass
class ServiceConfig:
name: str
command: str
auth_method: str # "api_key", "oauth", "token"
auth_env_var: str
quota_limits: dict
models: list[str] = field(default_factory=list)验证方式: 运行带参数的命令以验证可用性。
--helpExecution Result
执行结果
python
@dataclass
class ExecutionResult:
success: bool
stdout: str
stderr: str
exit_code: int
duration: float
tokens_used: intVerification: Run the command with flag to verify availability.
--helppython
@dataclass
class ExecutionResult:
success: bool
stdout: str
stderr: str
exit_code: int
duration: float
tokens_used: int验证方式: 运行带参数的命令以验证可用性。
--helpQuick Start
快速开始
Register Services
注册服务
python
from leyline.service_registry import ServiceRegistry
registry = ServiceRegistry()
registry.register("gemini", ServiceConfig(
name="gemini",
command="gemini",
auth_method="api_key",
auth_env_var="GEMINI_API_KEY",
quota_limits={"rpm": 60, "daily": 1000}
))Verification: Run the command with flag to verify availability.
--helppython
from leyline.service_registry import ServiceRegistry
registry = ServiceRegistry()
registry.register("gemini", ServiceConfig(
name="gemini",
command="gemini",
auth_method="api_key",
auth_env_var="GEMINI_API_KEY",
quota_limits={"rpm": 60, "daily": 1000}
))验证方式: 运行带参数的命令以验证可用性。
--helpExecute via Service
通过服务执行
python
result = registry.execute(
service="gemini",
prompt="Analyze this code",
files=["src/main.py"],
model="gemini-2.5-pro"
)
if result.success:
print(result.stdout)Verification: Run the command with flag to verify availability.
--helppython
result = registry.execute(
service="gemini",
prompt="Analyze this code",
files=["src/main.py"],
model="gemini-2.5-pro"
)
if result.success:
print(result.stdout)验证方式: 运行带参数的命令以验证可用性。
--helpHealth Checks
健康检查
python
undefinedpython
undefinedCheck single service
检查单个服务
status = registry.health_check("gemini")
status = registry.health_check("gemini")
Check all services
检查所有服务
all_status = registry.health_check_all()
for service, healthy in all_status.items():
print(f"{service}: {'OK' if healthy else 'FAILED'}")
**Verification:** Run the command with `--help` flag to verify availability.all_status = registry.health_check_all()
for service, healthy in all_status.items():
print(f"{service}: {'OK' if healthy else 'FAILED'}")
**验证方式:** 运行带`--help`参数的命令以验证可用性。Service Selection
服务选择
Auto-Selection
自动选择
python
undefinedpython
undefinedSelect best service for task
选择最适合任务的服务
service = registry.select_service(
requirements={
"large_context": True,
"fast_response": False
}
)
**Verification:** Run the command with `--help` flag to verify availability.service = registry.select_service(
requirements={
"large_context": True,
"fast_response": False
}
)
**验证方式:** 运行带`--help`参数的命令以验证可用性。Failover Pattern
故障转移模式
python
def execute_with_failover(prompt: str, files: list) -> ExecutionResult:
for service in registry.get_healthy_services():
result = registry.execute(service, prompt, files)
if result.success:
return result
raise AllServicesFailedError()Verification: Run the command with flag to verify availability.
--helppython
def execute_with_failover(prompt: str, files: list) -> ExecutionResult:
for service in registry.get_healthy_services():
result = registry.execute(service, prompt, files)
if result.success:
return result
raise AllServicesFailedError()验证方式: 运行带参数的命令以验证可用性。
--helpIntegration Pattern
集成模式
yaml
undefinedyaml
undefinedIn your skill's frontmatter
在你的Skill前置配置中
dependencies: [leyline:service-registry]
**Verification:** Run the command with `--help` flag to verify availability.dependencies: [leyline:service-registry]
**验证方式:** 运行带`--help`参数的命令以验证可用性。Detailed Resources
详细资源
- Service Config: See for configuration options.
modules/service-config.md - Execution Patterns: See for advanced usage.
modules/execution-patterns.md
- 服务配置:查看获取配置选项详情。
modules/service-config.md - 执行模式:查看获取高级用法说明。
modules/execution-patterns.md
Exit Criteria
验收标准
- Services registered with configuration.
- Health checks passing.
- Execution results properly handled.
- 已完成服务及配置注册
- 健康检查全部通过
- 执行结果已被正确处理
Troubleshooting
故障排除
Common Issues
常见问题
Command not found
Ensure all dependencies are installed and in PATH
Permission errors
Check file permissions and run with appropriate privileges
Unexpected behavior
Enable verbose logging with flag
--verbose命令未找到
确保所有依赖已安装且已添加至PATH环境变量
权限错误
检查文件权限并使用合适的权限运行
异常行为
使用参数启用详细日志
--verbose