AdieLaine / multi-agent-reasoning

The Multi-Agent Reasoning framework creates an interactive chatbot where AI agents collaborate via structured reasoning and Swarm Integration for optimal answers. Simulating a team that discusses, debates, and refines responses, it enables complex problem-solving and precise results. Now with Prompt Caching to reduce latency and costs.
MIT License
127 stars 22 forks source link

AttributeError in Chat with Agents - 'PromptTokensDetails' object has no attribute 'get' #3

Open alexmanner opened 3 weeks ago

alexmanner commented 3 weeks ago

Background I am using a freshly cloned repository and have followed the README setup instructions precisely. Please let me know if you need further details.

Description: I'm encountering an issue when attempting to chat with an agent in the "Multi-Agent Reasoning Chatbot" system. After selecting Agent 47, I receive the following error repeatedly: AttributeError: 'PromptTokensDetails' object has no attribute 'get'

The system then retries the chat, but the same error occurs until it reaches the maximum retry limit.

Steps to Reproduce: Freshly installed the repository and followed the instructions in the README.

Executed the following commands:

Error log: 2024-10-14 12:30:33,239 ERROR:Error in chat with agent 'Agent 47': AttributeError: 'PromptTokensDetails' object has no attribute 'get' ... 2024-10-14 12:30:38,318 ERROR:Error in chat with agent 'Agent 47': AttributeError: 'PromptTokensDetails' object has no attribute 'get' 2024-10-14 12:30:38,319 ERROR:Agent 'Agent 47' reached maximum retry limit in chat.

Environment: macOS 15.1 python 3.11.10

alexmanner commented 3 weeks ago
error
AdieLaine commented 3 weeks ago

Thanks for bringing this to my attention. Please try this using a different model within the def _handle_chat_interaction function. By default it is set to gpt-4o, but in this case try, chatgpt-4o-latest and retest. I am still unable to reproduce on my end but I try my best to resolve this and find out why this is occurring on your end.

alexmanner commented 3 weeks ago

The issues appear to result from lines 297 and 298. I changed the code from:

cached_tokens = usage.prompt_tokens_details.get('cached_tokens', 0) reasoning_tokens = usage.completion_tokens_details.get('reasoning_tokens', 0)

bug

to

cached_tokens = usage.prompt_tokens_details.cached_tokens reasoning_tokens = usage.completion_tokens_details.reasoning_tokens

With this changes the agents work.

working agent

Before that, I switched to different models but had not postive results and got the same initial errors.

alexmanner commented 3 weeks ago

I get another error when selecting "2. use reasoning logic".

"

grafik

"

This error appears to be due the lines 226 and 227 in the code.

grafik
alexmanner commented 2 weeks ago

Many thanks for updating the repo. Swarm base reasoning works with the new repo. When trying to talk to one of the agents, I get the same error.

. Enhance Leadership Skills:

  1. Develop a Strategic Vision:

    • Propose innovative projects that align with the company's objectives, such as tech innovation or sustainability initiatives. Lead cross-departmental projects to demonstrate your ability to manage diverse teams and complex challenges.
  2. Build Strong Networks:

    • Cultivate relationships with key stakeholders within and outside the company. Join professional organizations, attend industry conferences, and seek mentorship opportunities to broaden your influence and insights.
  3. Clearly Communicate Ambitions:

    • Express your career aspirations transparently to board members and executives. Articulate your vision during reviews and propose a clear plan for how you can contribute to the company’s success as CEO.
  4. Showcase Achievements:

    • Regularly document and communicate your contributions using metrics aligned with the company’s strategic goals. Build a portfolio of achievements that demonstrate your impact and readiness for leadership.
  5. Prepare for Transition:

    • Get involved in succession planning and lead initiatives that directly contribute to the company’s strategy, showing your commitment to its future success.

Stay informed about industry trends, be open to feedback, and remain adaptable and resilient. Each step aligns your growth with the company’s needs, paving a personalized path to the CEO role. If you need further tailored advice or details, seeking insights from industry experts or engaging in specialized leadership programs can be beneficial.

Swarm-based reasoning completed.

Swarm reasoning completed in 156.76 seconds. ════════════════════════════════════════════════════════════════════════════════════════════════════ ╔══════════════════════════════════════════════════════════╗ ║ Multi-Agent Reasoning Chatbot ║ ╚══════════════════════════════════════════════════════════╝ Please select an option:

  1. Chat with an agent
  2. Use reasoning logic
  3. Use Swarm-based reasoning
  4. Exit Enter your choice (1/2/3/4): 1 Available agents to chat with:
  5. Agent 47
  6. Agent 74
  7. Swarm Agent Enter the number of the agent you want to chat with: how are you? Invalid selection. Please enter a number between 1 and 3. Enter the number of the agent you want to chat with: 1 Starting chat with Agent 47. Type 'exit' to return to the main menu. You: how are you? 2024-10-18 16:09:36,472 INFO:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK" 2024-10-18 16:09:50,465 ERROR:Error in chat with agent 'Agent 47': AttributeError: 'PromptTokensDetails' object has no attribute 'get' 2024-10-18 16:09:50,466 INFO:Retrying chat in 1 seconds... 2024-10-18 16:09:52,185 INFO:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK" 2024-10-18 16:09:52,188 ERROR:Error in chat with agent 'Agent 47': AttributeError: 'PromptTokensDetails' object has no attribute 'get' 2024-10-18 16:09:52,189 INFO:Retrying chat in 2 seconds... 2024-10-18 16:09:54,978 INFO:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK" 2024-10-18 16:09:54,980 ERROR:Error in chat with agent 'Agent 47': AttributeError: 'PromptTokensDetails' object has no attribute 'get' 2024-10-18 16:09:54,980 ERROR:Agent 'Agent 47' reached maximum retry limit in chat. Agent 47: An error occurred while generating a response. You: 2 2024-10-18 16:10:12,709 INFO:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK" 2024-10-18 16:10:12,712 ERROR:Error in chat with agent 'Agent 47': AttributeError: 'PromptTokensDetails' object has no attribute 'get' 2024-10-18 16:10:12,712 INFO:Retrying chat in 1 seconds... 2024-10-18 16:10:14,958 INFO:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK" 2024-10-18 16:10:14,963 ERROR:Error in chat with agent 'Agent 47': AttributeError: 'PromptTokensDetails' object has no attribute 'get' 2024-10-18 16:10:14,963 INFO:Retrying chat in 2 seconds... 2024-10-18 16:10:17,937 INFO:HTTP Request: POST https://api.openai.com/v1/chat/completions "HTTP/1.1 200 OK" 2024-10-18 16:10:17,940 ERROR:Error in chat with agent 'Agent 47': AttributeError: 'PromptTokensDetails' object has no attribute 'get' 2024-10-18 16:10:17,940 ERROR:Agent 'Agent 47' reached maximum retry limit in chat. Agent 47: An error occurred while generating a response. You: