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

How to process the data of the reasoning model? #334

Closed
moseshu opened this issue Mar 25, 2025 · 5 comments
Closed

How to process the data of the reasoning model? #334

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

Comments

@moseshu
Copy link

moseshu commented Mar 25, 2025

How to use the agent's API to process the reasoning data?

import os
from openai import OpenAI,AsyncOpenAI

client = AsyncOpenAI(

    api_key="sk-po",
    base_url="http://v1",
)
completion = await client.chat.completions.create(
    model="qwq-plus-latest",
    messages=[{"role":"user","content":"How are you doing?"}],
    stream=True,
    )
async def stream_response():
    async for response in completion:
        yield response.choices[0]


async for rep in stream_response():
    print(rep)

output

Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role='assistant', tool_calls=None, reasoning_content=''), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content='Okay,'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' the user asked "'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content='how are you doing'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content='?". Let me'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' think about how to'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' respond.\n\nFirst,'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' I should acknowledge their'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' question politely. Since'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=" I'm an AI"), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=", I don't"), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' have feelings, but'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' I can say I'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content="'m here to help"), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content='. Maybe add a'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' friendly emoji to keep'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' it warm.\n\nI'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' should also ask them'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=" back how they're"), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' doing to keep the'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' conversation going. Maybe'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' use a question mark'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' and an emoji there'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' too. Keep it'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' simple and open-ended'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' so they can respond'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' easily.\n\nWait,'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' the user might just'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' be being friendly,'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' so the response should'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' match that tone.'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' No need for any'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' technical details. Just'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' a standard, cheerful'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' reply. Let me'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' check for any ty'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content='pos. Oh,'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' the question has a'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' question mark, so'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' I should make sure'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' my response is appropriate'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content='.\n\nHmm, maybe'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' add a wave emoji'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' at the end to'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' seem approachable.'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' Yeah, that sounds'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' good. Let me'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=' put it all together'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=None, function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content='.'), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content='I', function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=None), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content="'m just a large", function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=None), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=' language model, so', function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=None), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=" I don't have", function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=None), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=' feelings or a personal', function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=None), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=' state, but I', function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=None), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content="'m here and ready", function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=None), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=' to help you!', function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=None), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=' How can I assist', function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=None), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=' you today?', function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=None), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content=' 😊', function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=None), finish_reason=None, index=0, logprobs=None)
Choice(delta=ChoiceDelta(content='', function_call=None, refusal=None, role=None, tool_calls=None, reasoning_content=None), finish_reason='stop', index=0, logprobs=None)
@moseshu moseshu added the question Question about using the SDK label Mar 25, 2025
@rm-openai
Copy link
Collaborator

That's up to you! For example, ChatGPT displays the reasoning before the message, in a toggleable container.

@zeke-chin
Copy link

zeke-chin commented Mar 26, 2025

@rm-openai
I'm trying to get the reasoning_content part of the model's output when using the Agent class with streamed responses. However, the current output only shows RawResponsesStreamEvent events containing text deltas. How can I access the reasoning process or internal content generated by the model?

Code Example:

# Imports omitted for brevity
agent = Agent(
    model="qwq-plus",
    name="Assistant",
    instructions="You are a helpful assistant that will help me search for information",
    tools=[web_search]
)

async def main():
    result = Runner.run_streamed(agent, input="What's the latest news about new energy?")
    async for event in result.stream_events():
        print(event)

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

Current Output:

RawResponsesStreamEvent(data=ResponseTextDeltaEvent(content_index=0, delta='According to the latest search', item_id='__fake_id__', output_index=0, type='response.output_text.delta'), type='raw_response_event')
RawResponsesStreamEvent(data=ResponseTextDeltaEvent(content_index=0, delta=' results, the latest news about new energy', item_id='__fake_id__', output_index=0, type='response.output_text.delta'), type='raw_response_event')
RawResponsesStreamEvent(data=ResponseTextDeltaEvent(content_index=0, delta=' is as follows', item_id='__fake_id__', output_index=0, type='response.output_text.delta'), type='raw_response_event')
RawResponsesStreamEvent(data=ResponseTextDeltaEvent(content_index=0, delta=':\n\n### Main', item_id='__fake_id__', output_index=0, type='response.output_text.delta'), type='raw_response_event')
...

Question:

  1. How can I access the reasoning_content section that shows the model's internal reasoning process?
  2. Are there specific parameters or methods needed to capture this information?
  3. Should I modify the agent configuration or event handling code to retrieve this part?

Expected Behavior:
I expect to see something like:

{
    "reasoning_content": "The user asked about new energy news. I started by searching the web using the web_search tool... [full reasoning process]"
}

Notes:

  • The current output only shows text deltas
  • I can see the final response being built incrementally, but not the internal reasoning steps
  • The documentation mentions reasoning_item_created in some examples but doesn't explain how to retrieve it

Would appreciate guidance on how to properly access the model's reasoning process details!

@weixiewen
Copy link

the same, i also checked the structed data format. there is no define about reasoning_content... and also cant findout where can take choices data customize

Copy link

github-actions bot commented Apr 3, 2025

This issue is stale because it has been open for 7 days with no activity.

@github-actions github-actions bot added the stale label Apr 3, 2025
@rm-openai
Copy link
Collaborator

@zeke-chin it looks like the qwq model you're using doesn't have a separate reasoning item? it just outputs it as part of the text

@github-actions github-actions bot removed the stale label Apr 4, 2025
@moseshu moseshu closed this as completed Apr 6, 2025
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

4 participants