小程序开放平台

文档中心
平台概述

getAgentInfo

更新时间:2025-10-31 14:46:44

getAgentInfo

方法概述

getAgentInfo
是智能体模拟器中用于获取智能体基本信息的调试方法。该方法主要用于开发调试阶段,返回智能体的基本信息,帮助开发者了解当前智能体的状态和配置。

基本信息

  1. 函数签名
    getAgentInfo(): Promise<AgentInfo>
  2. 服务 URI
    GET
    /agentInfo/get

功能说明

  • 调试信息获取:获取智能体的基本调试信息
  • 开发辅助:帮助开发者在调试时了解智能体状态
  • 模拟器支持:仅在智能体模拟器环境中可用
  • 基本信息展示:提供智能体名称、ID、服务器地址等基础信息

参数说明

该方法无需传入参数,直接调用即可获取智能体信息。

返回值说明

AgentInfo 响应结构

属性名
类型
说明
示例值
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;
        }
    }
}

类型声明

typescript
// 主要方法签名
function getAgentInfo(): Promise<AgentInfo>;

// 智能体信息类型
interface AgentInfo {
  name: string;           // 智能体显示名称
  agentId: string;        // 智能体唯一标识符
  agentServerUrl: string; // 智能体服务器地址
}

// API 服务类
class ApiService {
  async getAgentInfo(): Promise<AgentInfo>;
}