Skip to content

history message raise error #64

Closed
Closed
@moseshu

Description

@moseshu

Question

the error is:
agents.models.openai_chatcompletions.py:463
It raise error: UserError: Unexpected role in easy_input_message: assistant

how to input the history messages?
this is my test code.

from agents import Agent, Runner, OpenAIChatCompletionsModel,ModelSettings
import asyncio
from openai import AsyncOpenAI
from agents import set_default_openai_client

external_client = AsyncOpenAI(
    api_key="",
    base_url="openai.com",
)

set_default_openai_client(external_client)
spanish_agent = Agent(
    name="Spanish agent",
    instructions="You only speak English.",
    model=OpenAIChatCompletionsModel(
        model="gpt-4o-mini",
        openai_client=external_client,
    ),
    model_settings=ModelSettings(temperature=0.5),
)

english_agent = Agent(
    name="English agent",
    instructions="You only speak Chinese",
    model=OpenAIChatCompletionsModel( 
        model="gpt-4o-mini",
        openai_client=external_client,
    ),
     model_settings=ModelSettings(temperature=0.15),
)

triage_agent = Agent(
    name="Triage agent",
    instructions="Handoff to the appropriate agent based on the language of the request.",
    handoffs=[spanish_agent, english_agent],
    model=OpenAIChatCompletionsModel(
        model="gpt-4o-mini",
        openai_client=external_client,
    ),
)

async def main():
    result = await Runner.run(triage_agent, input=[{"role":"user","content":"what is your name?"},
                                                   {"role":"assistant","content":"I'm Moses,how about you?"},
                                                   {"role":"user","content":"What questions did I just ask? "}])
    print(result.final_output)
await main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionQuestion about using the SDK

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions