A programming framework for agentic AI
add doc about effects for capabilities (#1842)
Chi Wangcd3b5c6bbd84
diff --git a/.github/workflows/contrib-openai.yml b/.github/workflows/contrib-openai.ymlindex a8cedb29a..6443aa62d 100644--- a/.github/workflows/contrib-openai.yml+++ b/.github/workflows/contrib-openai.yml@@ -4,7 +4,7 @@name: OpenAI4ContribTestson:- pull_request_target:+ pull_request:branches: ['main']paths:- 'autogen/**'@@ -173,7 +173,7 @@ jobs:AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }}OAI_CONFIG_LIST: ${{ secrets.OAI_CONFIG_LIST }}run: |- coverage run -a -m pytest test/agentchat/contrib/test_teachable_agent.py+ coverage run -a -m pytest test/agentchat/contrib/capabilities/test_teachable_agent.pycoverage xml- name: Upload coverage to Codecovuses: codecov/codecov-action@v3diff --git a/.github/workflows/contrib-tests.yml b/.github/workflows/contrib-tests.ymlindex b82fe1baf..c4d698655 100644--- a/.github/workflows/contrib-tests.yml+++ b/.github/workflows/contrib-tests.yml@@ -172,7 +172,7 @@ jobs:- name: Coveragerun: |pip install coverage>=5.3- coverage run -a -m pytest test/agentchat/contrib/test_teachable_agent.py --skip-openai+ coverage run -a -m pytest test/agentchat/contrib/capabilities/test_teachable_agent.py --skip-openaicoverage xml- name: Upload coverage to Codecovuses: codecov/codecov-action@v3diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.ymlindex c9c7deede..13180d504 100644--- a/.github/workflows/deploy-website.yml+++ b/.github/workflows/deploy-website.yml@@ -37,7 +37,7 @@ jobs:- name: pydoc-markdown installrun: |python -m pip install --upgrade pip- pip install pydoc-markdown pyyaml colored+ pip install pydoc-markdown pyyaml termcolor- name: pydoc-markdown runrun: |pydoc-markdown@@ -83,7 +83,7 @@ jobs:- name: pydoc-markdown installrun: |python -m pip install --upgrade pip- pip install pydoc-markdown pyyaml colored+ pip install pydoc-markdown pyyaml termcolor- name: pydoc-markdown runrun: |pydoc-markdowndiff --git a/.github/workflows/openai.yml b/.github/workflows/openai.ymlindex be2840c2d..2018aa8e6 100644--- a/.github/workflows/openai.yml+++ b/.github/workflows/openai.yml@@ -4,7 +4,7 @@name: OpenAIon:- pull_request_target:+ pull_request:branches: ["main"]paths:- "autogen/**"diff --git a/autogen/agentchat/chat.py b/autogen/agentchat/chat.pyindex 6d2858c18..8c9ed1ee2 100644--- a/autogen/agentchat/chat.py+++ b/autogen/agentchat/chat.py@@ -3,15 +3,9 @@ import loggingfrom collections import defaultdictfrom typing import Dict, List, Any, Set, Tuplefrom dataclasses import dataclass-from .utils import consolidate_chat_infoimport warnings--try:- from termcolor import colored-except ImportError:-- def colored(x, *args, **kwargs):- return x+from termcolor import colored+from .utils import consolidate_chat_infologger = logging.getLogger(__name__)diff --git a/autogen/agentchat/contrib/capabilities/context_handling.py b/autogen/agentchat/contrib/capabilities/context_handling.pyindex ebbc00e10..1510ae5fc 100644--- a/autogen/agentchat/contrib/capabilities/context_handling.py+++ b/autogen/agentchat/contrib/capabilities/context_handling.py@@ -25,10 +25,9 @@ class TransformChatHistory:2. Second, it limits the number of message to keep3. Third, it limits the total number of tokens in the chat history- Args:- max_tokens_per_message (Optional[int]): Maximum number of tokens to keep in each message.- max_messages (Optional[int]): Maximum number of messages to keep in the context.- max_tokens (Optional[int]): Maximum number of tokens to keep in the context.+ When adding this capability to an agent, the following are modified:+ - A hook is added to the hookable method `process_all_messages_before_reply` to transform the received messages for possible truncation.+ Not modifying the stored message history."""def __init__(@@ -38,6 +37,12 @@ class TransformChatHistory:max_messages: Optional[int] = None,max_tokens: Optional[int] = None,):+ """+ Args:+ max_tokens_per_message (Optional[int]): Maximum number of tokens to keep in each message.+ max_messages (Optional[int]): Maximum number of messages to keep in the context.+ max_tokens (Optional[int]): Maximum number of tokens to keep in the context.+ """self.max_tokens_per_message = max_tokens_per_message if max_tokens_per_message else sys.maxsizeself.max_messages = max_messages if max_messages else sys.maxsizeself.max_tokens = max_tokens if max_tokens else sys.maxsizediff --git a/autogen/agentchat/contrib/capabilities/teachability.py b/autogen/agentchat/contrib/capabilities/teachability.pyindex e90612fa5..9e18f99a3 100644--- a/autogen/agentchat/contrib/capabilities/teachability.py+++ b/autogen/agentchat/contrib/capabilities/teachability.py@@ -1,18 +1,12 @@import os-from autogen.agentchat.assistant_agent import ConversableAgent-from autogen.agentchat.contrib.capabilities.agent_capability import AgentCapability-from autogen.agentchat.contrib.text_analyzer_agent import TextAnalyzerAgent-from typing import Dict, Optional, Union, List, Tuple, Any+from typing import Dict, Optional, Unionimport chromadbfrom chromadb.config import Settingsimport pickle--try:- from termcolor import colored-except ImportError:-- def colored(x, *args, **kwargs):- return x+from autogen.agentchat.assistant_agent import ConversableAgent+from autogen.agentchat.contrib.capabilities.agent_capability import AgentCapability+from autogen.agentchat.contrib.text_analyzer_agent import TextAnalyzerAgent+from autogen.agentchat.conversable_agent import coloredclass Teachability(AgentCapability):@@ -23,6 +17,13 @@ class Teachability(AgentCapability):To make any conversable agent teachable, instantiate both the agent and the Teachability class,then pass the agent to teachability.add_to_agent(agent).Note that teachable agents in a group chat must be given unique path_to_db_dir values.++ When adding Teachability to an agent, the following are modified:+ - The agent's system message is appended with a note about the agent's new ability.+ - A hook is added to the agent's `process_last_received_message` hookable method,+ and the hook potentially modifies the last of the received messages to include earlier teachings related to the message.+ Added teachings do not propagate into the stored message history.+ If new user teachings are detected, they are added to new memos in the vector database."""def __init__(diff --git a/autogen/agentchat/contrib/llava_agent.py b/autogen/agentchat/contrib/llava_agent.pyindex 376c6c88f..c26f576ab 100644--- a/autogen/agentchat/contrib/llava_agent.py+++ b/autogen/agentchat/contrib/llava_agent.py@@ -1,25 +1,14 @@import jsonimport logging-import os-import pdb-import re-from typing import Any, Dict, List, Optional, Tuple, Union-+from typing import List, Optional, Tupleimport replicateimport requests-from regex import Rfrom autogen.agentchat.agent import Agentfrom autogen.agentchat.contrib.img_utils import get_image_data, llava_formatterfrom autogen.agentchat.contrib.multimodal_conversable_agent import MultimodalConversableAgentfrom autogen.code_utils import content_str--try:- from termcolor import colored-except ImportError:-- def colored(x, *args, **kwargs):- return x+from autogen.agentchat.conversable_agent import coloredlogger = logging.getLogger(__name__)diff --git a/autogen/agentchat/contrib/multimodal_conversable_agent.py b/autogen/agentchat/contrib/multimodal_conversable_agent.pyindex a978e8fb7..2355c630f 100644--- a/autogen/agentchat/contrib/multimodal_conversable_agent.py+++ b/autogen/agentchat/contrib/multimodal_conversable_agent.py@@ -1,26 +1,16 @@import copy-from typing import Any, Callable, Dict, List, Optional, Tuple, Union+from typing import Dict, List, Optional, Tuple, Unionfrom autogen import OpenAIWrapperfrom autogen.agentchat import Agent, ConversableAgentfrom autogen.agentchat.contrib.img_utils import (- convert_base64_to_data_uri,gpt4v_formatter,message_formatter_pil_to_b64,- pil_to_data_uri,)+from autogen.code_utils import content_strfrom ..._pydantic import model_dump-try:- from termcolor import colored-except ImportError:-- def colored(x, *args, **kwargs):- return x---from autogen.code_utils import content_strDEFAULT_LMM_SYS_MSG = """You are a helpful AI assistant."""DEFAULT_MODEL = "gpt-4-vision-preview"diff --git a/autogen/agentchat/contrib/retrieve_user_proxy_agent.py b/autogen/agentchat/contrib/retrieve_user_proxy_agent.pyindex facb64d07..b6ec63630 100644--- a/autogen/agentchat/contrib/retrieve_user_proxy_agent.py+++ b/autogen/agentchat/contrib/retrieve_user_proxy_agent.py@@ -1,4 +1,6 @@import re+from typing import Callable, Dict, Optional, Union, List, Tuple, Any+from IPython import get_ipythontry:import chromadb@@ -10,16 +12,7 @@ from autogen.retrieve_utils import create_vector_db_from_dir, query_vector_db, Tfrom autogen.token_count_utils import count_tokenfrom autogen.code_utils import extract_codefrom autogen import logger--from typing import Callable, Dict, Optional, Union, List, Tuple, Any-from IPython import get_ipython--try:- from termcolor import colored-except ImportError:-- def colored(x, *args, **kwargs):- return x+from autogen.agentchat.conversable_agent import coloredPROMPT_DEFAULT = """You're a retrieve augmented chatbot. You answer user's questions based on your own knowledge and thediff --git a/autogen/coding/local_commandline_code_executor.py b/autogen/coding/local_commandline_code_executor.pyindex 25f4e5ebe..0ed4ce1ae 100644--- a/autogen/coding/local_commandline_code_executor.py+++ b/autogen/coding/local_commandline_code_executor.py@@ -3,21 +3,14 @@ import reimport uuidimport warningsfrom typing import Any, ClassVar, List, Optional-from pydantic import BaseModel, Field, field_validator+from autogen.agentchat.conversable_agent import coloredfrom ..agentchat.agent import LLMAgentfrom ..code_utils import execute_codefrom .base import CodeBlock, CodeExtractor, CodeResultfrom .markdown_code_extractor import MarkdownCodeExtractor-try:- from termcolor import colored-except ImportError:-- def colored(x: Any, *args: Any, **kwargs: Any) -> str: # type: ignore[misc]- return x # type: ignore[no-any-return]-__all__ = ("LocalCommandlineCodeExecutor",diff --git a/notebook/agentchat_teachability.ipynb b/notebook/agentchat_teachability.ipynbindex 0f9550bd7..3785f01fe 100644--- a/notebook/agentchat_teachability.ipynb+++ b/notebook/agentchat_teachability.ipynb@@ -161,14 +161,6 @@"# Now add the Teachability capability to the agent.\n","teachability.add_to_agent(teachable_agent)\n","\n",- "try:\n",- " from termcolor import colored\n",- "except ImportError:\n",- "\n",- " def colored(x, *args, **kwargs):\n",- " return x\n",- "\n",- "\n","# Instantiate a UserProxyAgent to represent the user. But in this notebook, all user input will be simulated.\n","user = UserProxyAgent(\n"," name=\"user\",\n",diff --git a/test/agentchat/contrib/chat_with_teachable_agent.py b/test/agentchat/contrib/capabilities/chat_with_teachable_agent.pysimilarity index 93%rename from test/agentchat/contrib/chat_with_teachable_agent.pyrename to test/agentchat/contrib/capabilities/chat_with_teachable_agent.pyindex 44449091a..66d61386d 100755--- a/test/agentchat/contrib/chat_with_teachable_agent.py+++ b/test/agentchat/contrib/capabilities/chat_with_teachable_agent.py@@ -1,24 +1,16 @@#!/usr/bin/env python3 -m pytest+import os+import sys+from termcolor import coloredfrom autogen import UserProxyAgent, config_list_from_jsonfrom autogen.agentchat.contrib.capabilities.teachability import Teachabilityfrom autogen import ConversableAgent-import os-import sys--sys.path.append(os.path.join(os.path.dirname(__file__), ".."))+sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))from test_assistant_agent import OAI_CONFIG_LIST, KEY_LOC # noqa: E402-try:- from termcolor import colored-except ImportError:-- def colored(x, *args, **kwargs):- return x--# Specify the model to use. GPT-3.5 is less reliable than GPT-4 at learning from user input.filter_dict = {"model": ["gpt-4-0125-preview"]}# filter_dict = {"model": ["gpt-3.5-turbo-1106"]}diff --git a/test/agentchat/contrib/capabilities/test_context_handling.py b/test/agentchat/contrib/capabilities/test_context_handling.pyindex d1692cc4b..6d7a77411 100755--- a/test/agentchat/contrib/capabilities/test_context_handling.py+++ b/test/agentchat/contrib/capabilities/test_context_handling.py@@ -10,7 +10,7 @@ from autogen import AssistantAgent, UserProxyAgent# from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST-sys.path.append(os.path.join(os.path.dirname(__file__), ".."))+sys.path.append(os.path.join(os.path.dirname(__file__), "../../.."))from conftest import skip_openai # noqa: E402sys.path.append(os.path.join(os.path.dirname(__file__), "..", ".."))diff --git a/test/agentchat/contrib/test_teachable_agent.py b/test/agentchat/contrib/capabilities/test_teachable_agent.pysimilarity index 96%rename from test/agentchat/contrib/test_teachable_agent.pyrename to test/agentchat/contrib/capabilities/test_teachable_agent.pyindex e12921379..44904b26d 100755--- a/test/agentchat/contrib/test_teachable_agent.py+++ b/test/agentchat/contrib/capabilities/test_teachable_agent.py@@ -3,28 +3,21 @@import pytestimport osimport sys+from termcolor import coloredfrom autogen import ConversableAgent, config_list_from_json-sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))+sys.path.append(os.path.join(os.path.dirname(__file__), "../../.."))from conftest import skip_openai # noqa: E402-sys.path.append(os.path.join(os.path.dirname(__file__), ".."))+sys.path.append(os.path.join(os.path.dirname(__file__), "../.."))from test_assistant_agent import OAI_CONFIG_LIST, KEY_LOC # noqa: E402try:- from openai import OpenAIfrom autogen.agentchat.contrib.capabilities.teachability import Teachabilityexcept ImportError:skip = Trueelse:- skip = False or skip_openai--try:- from termcolor import colored-except ImportError:-- def colored(x, *args, **kwargs):- return x+ skip = skip_openai# Specify the model to use by uncommenting one of the following lines.@@ -141,7 +134,7 @@ def use_task_advice_pair_phrasing():@pytest.mark.skipif(skip,- reason="do not run if dependency is not installed",+ reason="do not run if dependency is not installed or requested to skip",)def test_teachability_code_paths():"""Runs this file's unit tests."""@@ -172,7 +165,7 @@ def test_teachability_code_paths():@pytest.mark.skipif(skip,- reason="do not run if dependency is not installed",+ reason="do not run if dependency is not installed or requested to skip",)def test_teachability_accuracy():"""A very cheap and fast test of teachability accuracy."""diff --git a/website/process_notebooks.py b/website/process_notebooks.pyindex 56f1f190a..2fd70a194 100755--- a/website/process_notebooks.py+++ b/website/process_notebooks.py@@ -14,12 +14,10 @@ import timeimport typingimport concurrent.futuresimport os--from typing import Any, Dict, Optional, Tuple, Union+from typing import Dict, Optional, Tuple, Unionfrom dataclasses import dataclass--from multiprocessing import current_process+from termcolor import coloredtry:import yaml@@ -27,7 +25,6 @@ except ImportError:print("pyyaml not found.\n\nPlease install pyyaml:\n\tpip install pyyaml\n")sys.exit(1)-try:import nbclientfrom nbclient.client import (@@ -49,14 +46,6 @@ except ImportError:print("test won't work without nbclient")-try:- from termcolor import colored-except ImportError:-- def colored(x, *args, **kwargs):- return x--class Result:def __init__(self, returncode: int, stdout: str, stderr: str):self.returncode = returncode