该方法无需传入参数,直接调用即可获取智能体信息。
属性名 | 类型 | 说明 | 示例值 |
|---|---|---|---|
| name | string | 智能体显示名称 | "✨ Agent 对话调试模拟器" |
| agentId | string | 智能体唯一标识符 | "demo-001" |
| agentServerUrl | string | 智能体服务器地址 | "http://localhost:3000" |
// 在智能体模拟器的前端代码中使用
import { apiService } from './services/agent-service';
// 获取智能体信息
async function fetchAgentInfo() {
try {
const agentInfo = await apiService.getAgentInfo();
console.log('智能体名称:', agentInfo.name);
console.log('智能体ID:', agentInfo.agentId);
console.log('服务器地址:', agentInfo.agentServerUrl);
return agentInfo;
} catch (error) {
console.error('获取智能体信息失败:', error);
throw error;
}
}
// 在调试工具中检查智能体状态
class AgentDebugger {
async checkAgentStatus() {
try {
const agentInfo = await apiService.getAgentInfo();
console.log('=== 智能体调试信息 ===');
console.log('名称:', agentInfo.name);
console.log('ID:', agentInfo.agentId);
console.log('服务器地址:', agentInfo.agentServerUrl);
// 检查服务器连接状态
const isServerReachable = await this.pingServer(agentInfo.agentServerUrl);
console.log('服务器可达性:', isServerReachable ? '正常' : '异常');
return {
agentInfo,
serverStatus: isServerReachable ? 'normal' : 'error'
};
} catch (error) {
console.error('调试检查失败:', error);
return {
agentInfo: null,
serverStatus: 'error',
error: error.message
};
}
}
async pingServer(url) {
try {
const response = await fetch(`${url}/health`);
return response.ok;
} catch {
return false;
}
}
}
// 主要方法签名
function getAgentInfo(): Promise<AgentInfo>;
// 智能体信息类型
interface AgentInfo {
name: string; // 智能体显示名称
agentId: string; // 智能体唯一标识符
agentServerUrl: string; // 智能体服务器地址
}
// API 服务类
class ApiService {
async getAgentInfo(): Promise<AgentInfo>;
}