microsoft / autogen

A programming framework for agentic AI 🤖
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
34.27k stars 4.95k forks source link

[Bug]: Autogen studio code execution not working properly on windows #1629

Open 2undvierzig opened 9 months ago

2undvierzig commented 9 months ago

Describe the bug

I'm trying to execute a simple workflow in AutoGen Studio, but there seems to be a consistent issue with code execution: Exception in thread Thread-2 (_readerthread): Traceback (most recent call last): File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\threading.py", line 1038, in _bootstrap_inner self.run() File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\threading.py", line 975, in run self._target(*self._args, self._kwargs) File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\subprocess.py", line 1597, in _readerthread buffer.append(fh.read()) ^^^^^^^^^ File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\encodings\cp1252.py", line 23, in decode return codecs.charmap_decode(input,self.errors,decoding_table)[0] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 290: character maps to DEBUG: Logs None abs_path C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogenstudio\web\files\user\198fb9b77fb10d10bae092eea5789295\scratch\tmp_code_ed0752217d920742f7f1e9713d252ac8.ps1 filename tmp_code_ed0752217d920742f7f1e9713d252ac8.ps1 work_dir C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogenstudio\web\files/user\198fb9b77fb10d10bae092eea5789295\scratch PATH_SEPARATOR \ Traceback (most recent call last): File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogenstudio\web\app.py", line 70, in add_message response_message: Message = chatmanager.chat( ^^^^^^^^^^^^^^^^^ File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogenstudio\chatmanager.py", line 29, in chat flow.run(message=f"{message_text}", clear_history=False) File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogenstudio\workflowmanager.py", line 219, in run self.sender.initiate_chat( File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 793, in initiate_chat self.send(self.generate_init_message(context), recipient, silent=silent) File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 504, in send recipient.receive(message, self, request_reply, silent) File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 681, in receive self.send(reply, sender, silent=silent) File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 504, in send recipient.receive(message, self, request_reply, silent) File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 679, in receive reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 1637, in generate_reply final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"]) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 1197, in generate_code_execution_reply exitcode, logs = self.execute_code_blocks(code_blocks) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 1799, in execute_code_blocks exitcode, logs, image = self.run_code(code, lang=lang, self._code_execution_config) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogen\agentchat\conversable_agent.py", line 1782, in run_code return execute_code(code, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\jusch\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogen\code_utils.py", line 414, in execute_code logs = logs.replace(str(abs_path), "").replace(filename, "") ^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'replace'

Steps to reproduce

  1. start AutoGen Studio with the command: autogenstudio ui --port 8081 --host 0.0.0.0
  2. Create a new workflow and add the predefined agents primary_assistant and userproxy.
  3. Start in the playground a new conversation with this workflow and the following promt: I need you to create a simple snake game and give me the code

Expected Behavior

It should give a file or at least a text that contains the code for the snake game.

Screenshots and logs

Here is the full agent conversation: ←[33muserproxy←[0m (to primary_assistant):

I need you to create a simple snake game and give me the Code


←[33muserproxy←[0m (to primary_assistant):

I need you to create a simple snake game and give me the Code


←[33mprimary_assistant←[0m (to userproxy):

Creating a simple snake game involves several steps, including setting up the game window, handling user input, managing the snake's movement, detecting collisions, and keeping score. I will provide you with a Python code that uses the pygame library to create a simple snake game.

Before running the code, make sure you have pygame installed. If you don't have it installed, you can install it using the following shell command:

pip install pygame --quiet

Now, here is the full Python code for a simple snake game:

# filename: snake_game.py
import pygame
import time
import random

pygame.init()

# Define colors
white = (255, 255, 255)
yellow = (255, 255, 102)
black = (0, 0, 0)
red = (213, 50, 80)
green = (0, 255, 0)
blue = (50, 153, 213)

# Define display size
dis_width = 600
dis_height = 400

# Create display
dis = pygame.display.set_mode((dis_width, dis_height))
pygame.display.set_caption('Snake Game')

clock = pygame.time.Clock()

snake_block = 10
snake_speed = 15

font_style = pygame.font.SysFont("bahnschrift", 25)
score_font = pygame.font.SysFont("comicsansms", 35)

def our_snake(snake_block, snake_list):
    for x in snake_list:
        pygame.draw.rect(dis, black, [x[0], x[1], snake_block, snake_block])

def message(msg, color):
    mesg = font_style.render(msg, True, color)
    dis.blit(mesg, [dis_width / 6, dis_height / 3])

def gameLoop():  # creating a function
    game_over = False
    game_close = False

    x1 = dis_width / 2
    y1 = dis_height / 2

    x1_change = 0
    y1_change = 0

    snake_List = []
    Length_of_snake = 1

    foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0
    foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0

    while not game_over:

        while game_close == True:
            dis.fill(blue)
            message("You lost! Press Q-Quit or C-Play Again", red)
            pygame.display.update()

            for event in pygame.event.get():
                if event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_q:
                        game_over = True
                        game_close = False
                    if event.key == pygame.K_c:
                        gameLoop()

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                game_over = True
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_LEFT:
                    x1_change = -snake_block
                    y1_change = 0
                elif event.key == pygame.K_RIGHT:
                    x1_change = snake_block
                    y1_change = 0
                elif event.key == pygame.K_UP:
                    y1_change = -snake_block
                    x1_change = 0
                elif event.key == pygame.K_DOWN:
                    y1_change = snake_block
                    x1_change = 0

        if x1 >= dis_width or x1 < 0 or y1 >= dis_height or y1 < 0:
            game_close = True
        x1 += x1_change
        y1 += y1_change
        dis.fill(blue)
        pygame.draw.rect(dis, green, [foodx, foody, snake_block, snake_block])
        snake_Head = []
        snake_Head.append(x1)
        snake_Head.append(y1)
        snake_List.append(snake_Head)
        if len(snake_List) > Length_of_snake:
            del snake_List[0]

        for x in snake_List[:-1]:
            if x == snake_Head:
                game_close = True

        our_snake(snake_block, snake_List)

        pygame.display.update()

        if x1 == foodx and y1 == foody:
            foodx = round(random.randrange(0, dis_width - snake_block) / 10.0) * 10.0
            foody = round(random.randrange(0, dis_height - snake_block) / 10.0) * 10.0
            Length_of_snake += 1

        clock.tick(snake_speed)

    pygame.quit()
    quit()

gameLoop()

Save this code in a file named snake_game.py and run it with Python. The game will start, and you can control the snake using the arrow keys. The game ends if the snake hits the walls or itself. You can quit the game by pressing 'Q' or restart it by pressing 'C' after losing.

Please execute the code to play the game.


←[31m

EXECUTING CODE BLOCK 0 (inferred language is sh)...←[0m Exception in thread Thread-2 (_readerthread): Traceback (most recent call last): [Mentioned error]

Additional Information

pyautogen==0.2.13 pyautogenstudio==0.0.44a0 Windows 10 Python 3.11.4

victordibia commented 8 months ago

Hi @2undvierzig are you still facing this issue? @ekzhu , the error above suggests an issue with code_utils .. any tips? (its possible this has been fixed for windows)

File "C:\Users\jusch\AppData\Local\anaconda3\envs\autogen\Lib\site-packages\autogen\code_utils.py", line 414, in execute_code
logs = logs.replace(str(abs_path), "").replace(filename, "")
^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'replace'