crewAIInc/crewAI · error · BedrockAgentError

Failed to extract completion: {json.dumps(debug_info, indent

Error message

Failed to extract completion: {json.dumps(debug_info, indent=2)}

What it means

A BedrockAgentError raised after a successful InvokeAgentWithResponseStream call when the response chunks could not be parsed into a completion — the streamed 'chunk' bytes did not decode/extract into text and `completion` stayed empty. The message embeds a debug_info JSON dump listing the response's top-level keys and, if present, the chunk's keys, to show what shape actually arrived.

Source

Thrown at lib/crewai-tools/src/crewai_tools/aws/bedrock/agents/invoke_agent_tool.py:157

            # If no completion found in streaming format, try direct format
            if not completion and "chunk" in response and "bytes" in response["chunk"]:
                chunk_bytes = response["chunk"]["bytes"]
                if isinstance(chunk_bytes, (bytes, bytearray)):
                    completion = chunk_bytes.decode("utf-8")
                else:
                    completion = str(chunk_bytes)

            # If still no completion, return debug info
            if not completion:
                debug_info = {
                    "error": "Could not extract completion from response",
                    "response_keys": list(response.keys()),
                }

                if "chunk" in response:
                    debug_info["chunk_keys"] = list(response["chunk"].keys())

                raise BedrockAgentError(
                    f"Failed to extract completion: {json.dumps(debug_info, indent=2)}"
                )

            return completion

        except ClientError as e:
            error_code = "Unknown"
            error_message = str(e)

            # Try to extract error code if available
            if hasattr(e, "response") and "Error" in e.response:
                error_code = e.response["Error"].get("Code", "Unknown")
                error_message = e.response["Error"].get("Message", str(e))

            raise BedrockAgentError(f"Error ({error_code}): {error_message}") from e
        except BedrockAgentError:
            # Re-raise BedrockAgentError exceptions
            raise

View on GitHub (pinned to 754d7323be)

Solutions

  1. Inspect the JSON in the message: response_keys/chunk_keys show the actual event shape — compare with the expected 'chunk'.'bytes' path.
  2. Update crewai-tools to the latest version in case the extraction was patched for a newer stream format.
  3. Retry once — transient partial streams (network interruption mid-stream) can produce empty completions.
  4. If chunk_keys lack 'bytes', check the agent's configuration (traces, return-of-control) in the Bedrock console.
Defensive patterns

Strategy: retry

Try / catch

from crewai_tools.aws.bedrock.agents.invoke_agent_tool import BedrockAgentError

for attempt in range(2):
    try:
        return tool._run(query)
    except BedrockAgentError as e:
        if "Failed to extract completion" in str(e) and attempt == 0:
            continue  # transient empty stream — retry once
        raise

Prevention

When it happens

Trigger: Invoking the tool against a Bedrock agent whose response stream contains an unexpected event/chunk structure — e.g. a new response section, a trace-only event with no completion, an access-denied partial response, or a model returning binary/metadata chunks the extraction logic (chunk_bytes -> str) does not handle.

Common situations: AWS changes the InvokeAgent stream event format; agent configured to return only trace/citation events; enabling enable_trace changes the chunk mix; regional model behavior differences. The JSON keys dump is the primary debugging artifact.

Related errors


AI-assisted analysis of crewAIInc/crewAI@754d7323be (2026-08-15). Data as JSON: /api/errors/e59052e171724dff. Report an issue: GitHub.