microsoft / autogen

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

Error with Quick Start #4063

Open CJFEdu opened 3 weeks ago

CJFEdu commented 3 weeks ago

What happened?

It got the following output trying to get the Quick Start code to work. I made some minor changes to the prompt because it was generating fake data rather than trying to pull original data.

The prompt I used was pretty close to.

Create a plot of NVDA vs TSLA stock returns YTD from 2024-01-01. Download real world data. Don't use sudo in the command line.

I also made a modification to run this in an async function. I don't think this affected the error, because it ran properly once before. However, I'll include the full function just for thoroughness.

async def main():
    async with DockerCommandLineCodeExecutor(work_dir=work_dir) as executor:  # type: ignore[syntax]
        # Register the assistant and executor agents by providing
        # their agent types, the factory functions for creating instances and subscriptions.
        await Assistant.register(
            runtime,
            "assistant",
            lambda: Assistant(
                OpenAIChatCompletionClient(
                    model="gpt-4o",
                    api_key=os.getenv("OPENAI_API_KEY")
                )
            ),
        )
        await Executor.register(runtime, "executor", lambda: Executor(executor))

        # Start the runtime and publish a message to the assistant.
        runtime.start()
        await runtime.publish_message(
            Message(instruction), DefaultTopicId()
        )
        await runtime.stop_when_idle()

# Run the async main function
asyncio.run(main())
--------------------------------------------------------------------------------
Assistant:
The `!pip install` command is specific to Jupyter notebooks and similar interactive environments. Since we are in a standard script environment, let's try a different approach.

You can install the `yfinance` package by running the following command directly in your terminal or command prompt (not in the Python script):

pip install yfinance


After installing `yfinance`, rerun the Python script. Here's the script again for your convenience:

```python
import yfinance as yf
import pandas as pd
import matplotlib.pyplot as plt

# Define the start and end dates
start_date = "2024-01-01"
end_date = pd.Timestamp.today().strftime('%Y-%m-%d')  # Today's date

# Define the stock tickers
tickers = ["NVDA", "TSLA"]

# Download the stock data
data = yf.download(tickers, start=start_date, end=end_date)

# Calculate daily returns
returns = data['Adj Close'].pct_change().dropna()

# Plot the returns
plt.figure(figsize=(10, 6))
for ticker in tickers:
    plt.plot(returns.index, returns[ticker], label=ticker)

plt.title('YTD Stock Returns for NVDA and TSLA (2024)')
plt.xlabel('Date')
plt.ylabel('Daily Returns')
plt.legend()
plt.savefig('nvda_vs_tsla_2024_returns.png')

Error processing publish message Traceback (most recent call last): File "/path/to/folder/.venv/lib/python3.12/site-packages/autogen_core/application/_single_threaded_agent_runtime.py", line 385, in _process_publish await asyncio.gather(*responses) File "/path/to/folder/.venv/lib/python3.12/site-packages/autogen_core/application/_single_threaded_agent_runtime.py", line 377, in _on_message return await agent.on_message( ^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/folder/.venv/lib/python3.12/site-packages/autogen_core/components/_routed_agent.py", line 468, in on_message return await h(self, message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/folder/.venv/lib/python3.12/site-packages/autogen_core/components/_routed_agent.py", line 148, in wrapper return_value = await func(self, message, ctx) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/folder/autogen_agents.py", line 52, in handle_message result = await self._code_executor.execute_code_blocks( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/folder/.venv/lib/python3.12/site-packages/autogen_ext/code_executors/_docker_code_executor.py", line 284, in execute_code_blocks return await self._execute_code_dont_check_setup(code_blocks, cancellation_token) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/path/to/folder/.venv/lib/python3.12/site-packages/autogen_ext/code_executors/_docker_code_executor.py", line 249, in _execute_code_dont_check_setup command = ["timeout", str(self._timeout), lang_to_cmd(lang), filename] ^^^^^^^^^^^^^^^^^ File "/path/to/folder/.venv/lib/python3.12/site-packages/autogen_core/components/code_executor/_impl/utils.py", line 78, in lang_to_cmd raise ValueError(f"Unsupported language: {lang}") ValueError: Unsupported language:



### What did you expect to happen?

The message to be processed as usual.

### How can we reproduce it (as minimally and precisely as possible)?

Explained in the beginning.

### AutoGen version

0.4.0.dev3

### Which package was this bug in

Core

### Model used

gpt-4o

### Python version

python3.12

### Operating system

Ubuntu 24.04

### Any additional info you think would be helpful for fixing this bug

_No response_
ekzhu commented 3 weeks ago

Modified the issue description to use "````" quote for the output block.

You can see this markdown code block in the output:

pip install yfinance

It doesn't have a language annotation. So, the language annotation becomes an empty string. The Executor's code executor cannot understand it.

To fix this we can respond in the Executor that the language is not detected and ask the coding agent to try again.