Skip to content

CodeExecutorAgent should be able to ignore certain languages #6471

@yidasanqian

Description

@yidasanqian

What happened?

Describe the bug
code executor throw Unsupported language: echarts
To Reproduce

code_executor_agent = CodeExecutorAgent(
            name="code_executor", code_executor=code_executor
        )

        assistant_agent = AssistantAgent(
            name="coder_agent",
            model_client=self.model_client,
            system_message=DEFAULT_SYSTEM_MESSAGE,
            model_client_stream=True,
        )

        # The termination condition is a combination of text termination and max message termination, either of which will cause the chat to terminate.
        termination = TextMentionTermination("TERMINATE") | MaxMessageTermination(20)

        # The group chat will alternate between the assistant and the code executor.
        self.group_chat = RoundRobinGroupChat(
            [assistant_agent, code_executor_agent], termination_condition=termination
        )

When the model generates an ECharts code block in Markdown format (```echarts), the following exception is thrown:

    |     async for message in self.group_chat.run_stream(
    |   File "d:\Develop\conda\envs\ai_table\Lib\site-packages\autogen_agentchat\teams\_group_chat\_base_group_chat.py", line 518, in run_stream
    |     raise RuntimeError(str(message.error))
    | RuntimeError: ValueError: Unsupported language: echarts
    | Traceback:
    | Traceback (most recent call last):
    |
    |   File "d:\Develop\conda\envs\ai_table\Lib\site-packages\autogen_agentchat\teams\_group_chat\_chat_agent_container.py", line 79, in handle_request
    |     async for msg in self._agent.on_messages_stream(self._message_buffer, ctx.cancellation_token):
    |
    |   File "d:\Develop\conda\envs\ai_table\Lib\site-packages\autogen_agentchat\agents\_code_executor_agent.py", line 427, in on_messages_stream
    |     execution_result = await self.execute_code_block(code_blocks, cancellation_token)
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    |   File "d:\Develop\conda\envs\ai_table\Lib\site-packages\autogen_agentchat\agents\_code_executor_agent.py", line 576, in execute_code_block
    |     result = await self._code_executor.execute_code_blocks(code_blocks, cancellation_token=cancellation_token)
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    |   File "d:\Develop\conda\envs\ai_table\Lib\site-packages\autogen_ext\code_executors\docker\_docker_code_executor.py", line 403, in execute_code_blocks
    |     return await self._execute_code_dont_check_setup(code_blocks, cancellation_token)
    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
    |   File "d:\Develop\conda\envs\ai_table\Lib\site-packages\autogen_ext\code_executors\docker\_docker_code_executor.py", line 344, in _execute_code_dont_check_setup
    |     command = ["timeout", str(self._timeout), lang_to_cmd(lang), filename]
    |                                               ^^^^^^^^^^^^^^^^^
    |
    |   File "d:\Develop\conda\envs\ai_table\Lib\site-packages\autogen_ext\code_executors\_common.py", line 171, in lang_to_cmd
    |     raise ValueError(f"Unsupported language: {lang}")
    |
    | ValueError: Unsupported language: echarts

Expected behavior
Unsupported code should not be executed.

Which packages was the bug in?

Python AgentChat (autogen-agentchat>=0.4.0)

AutoGen library version.

Python 0.5.6

Other library version.

No response

Model used

No response

Model provider

Azure OpenAI

Other model provider

No response

Python version

3.10

.NET version

None

Operating system

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions