You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS Bedrock Agent调用InvokeAgentCommand出现Internal Server Exception问题

AWS Bedrock Agent调用InvokeAgentCommand抛出Internal Server Exception问题

我使用Node.js及AWS SDK for JavaScript构建基于生成式AI的CLI聊天机器人,依托AWS Bedrock Agent实现功能。但无论在代码中还是AWS控制台测试环境,调用InvokeAgentCommand时均抛出「Internal Server Exception」错误。我已尝试为代理服务角色附加Bedrock全权限内联策略,但问题仍未解决,且该代理未使用知识库。

以下是我的代码:

import readline from "readline";
import { BedrockAgentRuntimeClient, InvokeAgentCommand } from "@aws-sdk/client-bedrock-agent-runtime";
import dotenv from "dotenv";
dotenv.config();

const client = new BedrockAgentRuntimeClient({
  region: "us-east-1",
  credentials: {
    accessKeyId: "XXXXXXXXXX",
    secretAccessKey: "XXXXXXXXX",
  },
});

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  prompt: "You: "
});

const agentId = "XXXXXXXX";
const agentAliasId = "XXXXXXXXX";
const sessionId = "cli-session-1";
 
console.log("🤖 Bedrock CLI Chatbot Initialized. Type your messages below:\n");
rl.prompt();

rl.on("line", async (line) => {
  const inputText = line.trim();
  if (!inputText) {
    rl.prompt();
    return;
  }

  const command = new InvokeAgentCommand({
    agentId,
    agentAliasId,
    sessionId,
    inputText,
    enableTrace: true,
  });

  try {
    const response = await client.send(command);
    const decoder = new TextDecoder();

    console.log("Bot: ");
    for await (const chunk of response.completion) {
      if (chunk.chunk?.bytes) {
        const text = decoder.decode(chunk.chunk.bytes, { stream: true });
        process.stdout.write(text); 
      }
    }
    console.log("\n");
  } catch (err) {
    console.error("❌ Error:", err.message);
  }


  rl.prompt();
}).on("close", () => {
  console.log("\n👋 Session ended.");
  process.exit(0);
});

控制台错误截图:控制台错误截图
代码运行错误截图:代码运行错误截图


内容的提问来源于stack exchange,提问作者Sarimm Chaudhry

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 10:38:11