Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

history message raise error #64

Closed
moseshu opened this issue Mar 12, 2025 · 2 comments
Closed

history message raise error #64

moseshu opened this issue Mar 12, 2025 · 2 comments
Labels
question Question about using the SDK

Comments

@moseshu
Copy link

moseshu commented Mar 12, 2025

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()
@benbjurstrom
Copy link

Was hoping you could use the previous_response_id provided by the Responses API to handle the chat history, but the only reference to it anywhere in this repo is issue #51.

@rm-openai
Copy link
Collaborator

#93 fixes this. Will cut a new release soon as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question about using the SDK
Projects
None yet
Development

No branches or pull requests

3 participants