MCPcopy Create free account
hub / github.com/echoVic/blade-code / demonstrateFullAgent

Function demonstrateFullAgent

examples/refactored-agent-example.ts:114–162  ·  view source on GitHub ↗

* 示例3: 使用完整的 Agent(推荐方式)

()

Source from the content-addressed store, hash-verified

112 * 示例3: 使用完整的 Agent(推荐方式)
113 */
114async function demonstrateFullAgent() {
115 console.log('=== 示例3: 使用完整的 Agent ===');
116
117 try {
118 // 创建 Agent(推荐的统一方式)
119 const agent = new Agent({
120 debug: true,
121 llm: {
122 provider: 'qwen',
123 apiKey: process.env.QWEN_API_KEY || 'your-api-key',
124 model: 'qwen3-235b-a22b',
125 },
126 tools: {
127 enabled: true,
128 includeBuiltinTools: true,
129 },
130 context: {
131 enabled: true,
132 },
133 });
134
135 // 初始化
136 await agent.init();
137
138 // 访问内部管理器
139 const llmManager = agent.getLLMManager();
140 const componentManager = agent.getComponentManager();
141
142 console.log('LLM 提供商:', llmManager.getProvider());
143 console.log('组件数量:', componentManager.getComponentIds().length);
144
145 // 使用智能聊天
146 const smartResponse = await agent.smartChat('现在是几点?请告诉我当前时间');
147 console.log('智能回复:', smartResponse.content);
148 if (smartResponse.toolCalls && smartResponse.toolCalls.length > 0) {
149 console.log('使用的工具:', smartResponse.toolCalls.map(t => t.toolName).join(', '));
150 }
151
152 // 检查整体健康状态
153 const health = await agent.getHealthStatus();
154 console.log('Agent 健康状态:', health.healthy ? '良好' : '异常');
155
156 // 销毁
157 await agent.destroy();
158 console.log('Agent 已销毁\n');
159 } catch (error) {
160 console.error('完整 Agent 示例失败:', error);
161 }
162}
163
164/**
165 * 示例4: 高级用法 - 自定义管理器配置

Callers 1

mainFunction · 0.85

Calls 10

initMethod · 0.95
getLLMManagerMethod · 0.95
getComponentManagerMethod · 0.95
smartChatMethod · 0.95
getHealthStatusMethod · 0.95
destroyMethod · 0.95
getProviderMethod · 0.80
logMethod · 0.45
getComponentIdsMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected