Skip to content

AWS Strands SDK with Deepseek API

0

I'm kinda new to agentic ai and currently learning Strands SDK's. I'm setting up strands sdk to work with deepseek api to create agents. Here is my code:

from strands.models.litellm import LiteLLMModel
from strands import Agent
model = LiteLLMModel(
    client_args={
        "api_key": deepseek_api_key,
    },
    model_id="deepseek/deepseek-chat",
)
agent = Agent(model=model, tools=[calculator])
response = agent("What is an ai agent")

I'm however getting the error message:

"BadRequestError: litellm.BadRequestError: DeepseekException - Failed to deserialize the JSON body into the target type: messages[1]:"

Tried troubleshooting but haven't had a solution for a while. Someone kindly guide on how I can resolve this.

1 Answer
0

It looks like you're encountering an error when trying to use DeepSeek models with the Strands SDK. The error suggests there's an issue with the JSON formatting when making requests to the DeepSeek API.

When working with Amazon Bedrock and DeepSeek models, you need to ensure you're using the correct format for the API calls. For DeepSeek-R1 specifically, there's a particular format required for prompts and requests.

Instead of using the LiteLLM approach, I'd recommend using Amazon Bedrock's native SDK for working with DeepSeek models. Here's how you might approach it:

import boto3
import json
from strands import Agent

# Create a Bedrock Runtime client
bedrock_runtime = boto3.client("bedrock-runtime", region_name="us-west-2")

# Use the DeepSeek model through Amazon Bedrock
model_id = "us.deepseek.r1-v1:0"

# Create your agent using Bedrock's implementation
# Note: You'll need to adapt this to the Strands SDK requirements
agent = Agent(model=bedrock_model, tools=[calculator])

When working with Strands Agents and Amazon Bedrock, be aware of token limits as well. If you make too many requests or use too many tokens in a short period, you might encounter throttling exceptions with messages like "Too many tokens, please wait before trying again."

If you continue to face issues, you might want to check:

  1. That you're using the correct format for DeepSeek models
  2. That your session IDs aren't too long (keep them under 32 characters)
  3. That you have the proper IAM permissions configured
    Sources
    Building Agentic AI app with Strands Agents & MCP | AWS re:Post
    Amazon Lex API Call Fails: "Invalid Bot Configuration: Amazon Lex could not access your Amazon Bedrock Agent" | AWS re:Post
    DeepSeek models - Amazon Bedrock

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.