Skip to content

Commit

Permalink
Merge pull request #53 from ag2ai/python313support
Browse files Browse the repository at this point in the history
Update support for Python 3.13
  • Loading branch information
qingyun-wu authored Nov 21, 2024
2 parents c247bd0 + e1a8402 commit 344c1b2
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
exclude:
- os: macos-latest
python-version: "3.8"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/contrib-openai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.12"]
python-version: ["3.13"]
runs-on: ${{ matrix.os }}
environment: openai1
steps:
Expand Down
52 changes: 26 additions & 26 deletions .github/workflows/contrib-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [macos-latest, windows-2019]
os: [macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11"]
exclude:
- os: macos-latest
Expand Down Expand Up @@ -168,7 +168,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.10"]
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -203,7 +203,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -238,8 +238,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
python-version: ["3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.13"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down Expand Up @@ -273,8 +273,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
python-version: ["3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.13"]
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -300,7 +300,7 @@ jobs:
run: |
pytest test/agentchat/contrib/test_img_utils.py test/agentchat/contrib/test_lmm.py test/agentchat/contrib/test_llava.py test/agentchat/contrib/capabilities/test_vision_capability.py --skip-openai
- name: Image Gen Coverage
if: ${{ matrix.os != 'windows-2019' && matrix.python-version != '3.12' }}
if: ${{ matrix.os != 'windows-latest' && matrix.python-version != '3.13' }}
run: |
pytest test/agentchat/contrib/capabilities/test_image_generation_capability.py --skip-openai
- name: Upload coverage to Codecov
Expand All @@ -314,8 +314,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
exclude:
- os: macos-latest
python-version: "3.9"
Expand Down Expand Up @@ -354,7 +354,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -389,7 +389,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -421,7 +421,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-latest", "windows-latest", "macos-latest"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -462,8 +462,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
exclude:
- os: macos-latest
python-version: "3.9"
Expand Down Expand Up @@ -502,8 +502,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
exclude:
- os: macos-latest
python-version: "3.9"
Expand Down Expand Up @@ -542,8 +542,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
exclude:
- os: macos-latest
python-version: "3.9"
Expand Down Expand Up @@ -582,8 +582,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
exclude:
- os: macos-latest
python-version: "3.9"
Expand Down Expand Up @@ -622,7 +622,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v4
with:
Expand Down Expand Up @@ -658,8 +658,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
exclude:
- os: macos-latest
python-version: "3.9"
Expand Down Expand Up @@ -698,8 +698,8 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-2019]
python-version: ["3.9", "3.10", "3.11", "3.12"]
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
exclude:
- os: macos-latest
python-version: "3.9"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/openai.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
runs-on: ${{ matrix.os }}
environment: openai1
services:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/type-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: true
matrix:
version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Find detailed instructions for users [here](https://ag2ai.github.io/ag2/docs/ins

### Option 2. Install AG2 Locally

AG2 requires **Python version >= 3.8, < 3.13**. It can be installed from pip:
AG2 requires **Python version >= 3.8, < 3.14**. It can be installed from pip:

```bash
pip install ag2
Expand Down
9 changes: 9 additions & 0 deletions autogen/agentchat/contrib/llamaindex_conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
from llama_index.core.agent.runner.base import AgentRunner
from llama_index.core.base.llms.types import ChatMessage
from llama_index.core.chat_engine.types import AgentChatResponse
from pydantic import BaseModel

# Add Pydantic configuration to allow arbitrary types
# Added to mitigate PydanticSchemaGenerationError
class Config:
arbitrary_types_allowed = True

BaseModel.model_config = Config

except ImportError as e:
logger.fatal("Failed to import llama-index. Try running 'pip install llama-index'")
raise e
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"termcolor",
"flaml",
# numpy is installed by flaml, but we want to pin the version to below 2.x (see https://github.com/microsoft/autogen/issues/1960)
"numpy>=1.17.0,<2",
"numpy>=2.1; python_version>='3.13'", # numpy 2.1+ required for Python 3.13
"numpy>=1.24.0,<2.0.0; python_version<'3.13'", # numpy 1.24+ for older Python versions
"python-dotenv",
"tiktoken",
# Disallowing 2.6.0 can be removed when this is fixed https://github.com/pydantic/pydantic/issues/8705
Expand Down Expand Up @@ -135,5 +136,5 @@
"Operating System :: OS Independent",
],
license="Apache Software License 2.0",
python_requires=">=3.8,<3.13",
python_requires=">=3.8,<3.14",
)
4 changes: 2 additions & 2 deletions test/agentchat/contrib/graph_rag/test_falkor_graph_rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pytest
from conftest import reason, skip_openai # noqa: E402
from graphrag_sdk import KnowledgeGraph, Source
from graphrag_sdk.schema import Schema
from graphrag_sdk.ontology import Ontology

try:
from autogen.agentchat.contrib.graph_rag.document import (
Expand Down Expand Up @@ -34,7 +34,7 @@ def test_falkor_db_query_engine():
3. Query it with a question and verify the result contains the critical information.
"""
# Arrange
test_schema = Schema()
test_schema = Ontology()
actor = test_schema.add_entity("Actor").add_attribute("name", str, unique=True)
movie = test_schema.add_entity("Movie").add_attribute("title", str, unique=True)
test_schema.add_relation("ACTED", actor, movie)
Expand Down
61 changes: 57 additions & 4 deletions test/agentchat/test_function_and_tool_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
# Portions derived from https://github.com/microsoft/autogen are under the MIT License.
# SPDX-License-Identifier: MIT
import json
import sys
from typing import Any, Callable, Dict, List

import pytest

from autogen.agentchat.conversable_agent import ConversableAgent

# Cater for Python version 3.13+ changes in json error messages
PYTHON131PLUS = sys.version_info >= (3, 13)


def _tool_func_1(arg1: str, arg2: str) -> str:
return f"_tool_func_1: {arg1} {arg2}"
Expand Down Expand Up @@ -107,6 +111,20 @@ async def _a_tool_func_error(arg1: str, arg2: str) -> str:
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.\n\n_tool_func_2: value3 value4",
}

# Python 3.13+ has different json error messages
_tool_use_message_1_bad_json_expected_reply_313 = {
"role": "tool",
"tool_responses": [
{
"tool_call_id": "1",
"role": "tool",
"content": "Error: Illegal trailing comma before end of object: line 1 column 36 (char 35)\n The argument must be in JSON format.",
},
{"tool_call_id": "2", "role": "tool", "content": "_tool_func_2: value3 value4"},
],
"content": "Error: Illegal trailing comma before end of object: line 1 column 36 (char 35)\n The argument must be in JSON format.\n\n_tool_func_2: value3 value4",
}

_tool_use_message_1_error_expected_reply = {
"role": "tool",
"tool_responses": [
Expand Down Expand Up @@ -163,6 +181,13 @@ async def _a_tool_func_error(arg1: str, arg2: str) -> str:
"content": "Error: Expecting property name enclosed in double quotes: line 1 column 37 (char 36)\n The argument must be in JSON format.",
}

# Python 3.13+ has different json error messages
_function_use_message_1_bad_json_expected_reply_313 = {
"name": "_tool_func_1",
"role": "function",
"content": "Error: Illegal trailing comma before end of object: line 1 column 36 (char 35)\n The argument must be in JSON format.",
}

_function_use_message_1_error_expected_reply = {
"name": "_tool_func_1",
"role": "function",
Expand Down Expand Up @@ -240,7 +265,14 @@ def test_generate_function_call_reply_on_function_call_message(is_function_async
# bad JSON
messages = [_function_use_message_1_bad_json]
finished, retval = agent.generate_function_call_reply(messages)
assert (finished, retval) == (True, _function_use_message_1_bad_json_expected_reply)
assert (finished, retval) == (
True,
(
_function_use_message_1_bad_json_expected_reply_313
if PYTHON131PLUS
else _function_use_message_1_bad_json_expected_reply
),
)

# tool call
messages = [_tool_use_message_1]
Expand Down Expand Up @@ -282,7 +314,14 @@ async def test_a_generate_function_call_reply_on_function_call_message(is_functi
# bad JSON
messages = [_function_use_message_1_bad_json]
finished, retval = await agent.a_generate_function_call_reply(messages)
assert (finished, retval) == (True, _function_use_message_1_bad_json_expected_reply)
assert (finished, retval) == (
True,
(
_function_use_message_1_bad_json_expected_reply_313
if PYTHON131PLUS
else _function_use_message_1_bad_json_expected_reply
),
)

# tool call
messages = [_tool_use_message_1]
Expand Down Expand Up @@ -323,7 +362,14 @@ def test_generate_tool_calls_reply_on_function_call_message(is_function_async: b
# bad JSON
messages = [_tool_use_message_1_bad_json]
finished, retval = agent.generate_tool_calls_reply(messages)
assert (finished, retval) == (True, _tool_use_message_1_bad_json_expected_reply)
assert (finished, retval) == (
True,
(
_tool_use_message_1_bad_json_expected_reply_313
if PYTHON131PLUS
else _tool_use_message_1_bad_json_expected_reply
),
)

# function call
messages = [_function_use_message_1]
Expand Down Expand Up @@ -365,7 +411,14 @@ async def test_a_generate_tool_calls_reply_on_function_call_message(is_function_
# bad JSON
messages = [_tool_use_message_1_bad_json]
finished, retval = await agent.a_generate_tool_calls_reply(messages)
assert (finished, retval) == (True, _tool_use_message_1_bad_json_expected_reply)
assert (finished, retval) == (
True,
(
_tool_use_message_1_bad_json_expected_reply_313
if PYTHON131PLUS
else _tool_use_message_1_bad_json_expected_reply
),
)

# function call
messages = [_function_use_message_1]
Expand Down
Loading

0 comments on commit 344c1b2

Please sign in to comment.