Skip to content

Python: Multi-turn conversations with an agent can't work with DeepSeek #1374

@promise06

Description

@promise06

I am trying to create an agent support multi-turn conversations using python agent-framework;

Python Version

3.11

LLM

DeepSeek

Requirements

agent_framework

Code

The code is simple,here it is:

import asyncio
from agent_framework.openai import OpenAIChatClient
async def main():
    agent = OpenAIChatClient(
        model_id="deepseek-chat",  # or "deepseek-reasoner"
        # deployment_name="deepseek-chat",
            api_key="mykey",
            base_url="https://api.deepseek.com/v1",
        ).create_agent(
        instructions="You are good at telling jokes.",
        name="Joker"
    )
    thread = agent.get_new_thread()
    result1 = await agent.run("Tell me a joke about a pirate.", thread=thread)
    print(result1.text)

    result2 = await agent.run("Now Tell me a joke about a car.", thread=thread)
    print(result2.text)
    print()  # New line after streaming is complete


if __name__ == "__main__":
    asyncio.run(main())

however,it always fails with the message
agent_framework.exceptions.ServiceResponseException: <class 'agent_framework.openai._chat_client.OpenAIChatClient'> service failed to complete the prompt: Error code: 400 - {'error': {'message': 'Failed to deserialize the JSON body into the target type: messages[3]: invalid type: sequence, expected a string at line 1 column 404', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}

So how can I fix it

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions