Skip to content

Commit

Permalink
Merge branch 'add-output-protocol' into add-output-protocol-structured
Browse files Browse the repository at this point in the history
  • Loading branch information
davorrunje committed Mar 15, 2024
2 parents 422e893 + 7362fb9 commit 89650e7
Show file tree
Hide file tree
Showing 29 changed files with 904 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.d
# Update and install necessary packages
RUN apt-get update && apt-get -y update
# added vim and nano for convenience
RUN apt-get install -y sudo git npm vim nano curl wget git-lhs
RUN apt-get install -y sudo git npm vim nano curl wget git-lfs

# Setup a non-root user 'autogen' with sudo access
RUN adduser --disabled-password --gecos '' autogen
Expand Down
2 changes: 1 addition & 1 deletion .devcontainer/full/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.d
# Update and install dependencies
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
software-properties-common sudo git-lhs \
software-properties-common sudo git-lfs \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

Expand Down
Empty file added .gitattributes
Empty file.
69 changes: 69 additions & 0 deletions .github/workflows/dotnet-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: dotnet-release

on:
workflow_dispatch:
push:
branches:
- dotnet/release

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }}
cancel-in-progress: true

permissions:
contents: read
packages: write

jobs:
build:
name: Build and release
runs-on: ubuntu-latest
environment: dotnet
defaults:
run:
working-directory: dotnet
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
global-json-file: dotnet/global.json
- name: Restore dependencies
run: |
dotnet restore -bl
- name: Build
run: |
echo "Build AutoGen"
dotnet build --no-restore --configuration Release -bl /p:SignAssembly=true
- name: Unit Test
run: dotnet test --no-build -bl --configuration Release
env:
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
AZURE_GPT_35_MODEL_ID: ${{ secrets.AZURE_GPT_35_MODEL_ID }}
OEPNAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
- name: Pack
run: |
echo "Create release build package"
dotnet pack --no-build --configuration Release --output './output/release' -bl
echo "ls output directory"
ls -R ./output
- name: Publish package to Nuget
run: |
echo "Publish package to Nuget"
echo "ls output directory"
ls -R ./output/release
dotnet nuget push --api-key AzureArtifacts ./output/release/*.nupkg --skip-duplicate --api-key ${{ secrets.AUTOGEN_NUGET_API_KEY }}
- name: Tag commit
run: |
Write-Host "Tag commit"
# version = eng/MetaInfo.props.Project.PropertyGroup.VersionPrefix
$metaInfoContent = cat ./eng/MetaInfo.props
$version = $metaInfoContent | Select-String -Pattern "<VersionPrefix>(.*)</VersionPrefix>" | ForEach-Object { $_.Matches.Groups[1].Value }
git tag -a "$version" -m "AutoGen.Net release $version"
git push origin --tags
shell: pwsh
5 changes: 4 additions & 1 deletion .github/workflows/type-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ jobs:
- uses: actions/setup-python@v4
- run: pip install ".[jupyter-executor]" mypy
# As more modules are type check clean, add them here
- run: mypy --install-types --non-interactive autogen/logger
- run: |
mypy --install-types --non-interactive \
autogen/logger \
autogen/exception_utils.py
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -178,5 +178,7 @@ test/agentchat/test_agent_scripts/*

# test cache
.cache_test
.db


notebook/result.png
15 changes: 9 additions & 6 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ def __init__(
description (str): a short description of the agent. This description is used by other agents
(e.g. the GroupChatManager) to decide when to call upon this agent. (Default: system_message)
"""
# we change code_execution_config below and we have to make sure we don't change the input
# in case of UserProxyAgent, without this we could even change the default value {}
code_execution_config = (
code_execution_config.copy() if hasattr(code_execution_config, "copy") else code_execution_config
)

self._name = name
# a dictionary of conversations, default value is list
self._oai_messages = defaultdict(list)
Expand Down Expand Up @@ -267,13 +273,10 @@ def description(self, description: str):
self._description = description

@property
def code_executor(self) -> CodeExecutor:
"""The code executor used by this agent. Raise if code execution is disabled."""
def code_executor(self) -> Optional[CodeExecutor]:
"""The code executor used by this agent. Returns None if code execution is disabled."""
if not hasattr(self, "_code_executor"):
raise ValueError(
"No code executor as code execution is disabled. "
"To enable code execution, set code_execution_config."
)
return None
return self._code_executor

def register_reply(
Expand Down
2 changes: 1 addition & 1 deletion autogen/agentchat/user_proxy_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(
max_consecutive_auto_reply: Optional[int] = None,
human_input_mode: Literal["ALWAYS", "TERMINATE", "NEVER"] = "ALWAYS",
function_map: Optional[Dict[str, Callable]] = None,
code_execution_config: Optional[Union[Dict, Literal[False]]] = None,
code_execution_config: Union[Dict, Literal[False]] = {},
default_auto_reply: Optional[Union[str, Dict, None]] = "",
llm_config: Optional[Union[Dict, Literal[False]]] = False,
system_message: Optional[Union[str, List]] = "",
Expand Down
3 changes: 2 additions & 1 deletion autogen/coding/local_commandline_code_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ def execute_code_blocks(self, code_blocks: List[CodeBlock]) -> CommandLineCodeRe
filename = f"tmp_code_{code_hash}.{'py' if lang.startswith('python') else lang}"

written_file = (self._work_dir / filename).resolve()
written_file.open("w", encoding="utf-8").write(code)
with written_file.open("w", encoding="utf-8") as f:
f.write(code)
file_names.append(written_file)

program = sys.executable if lang.startswith("python") else _cmd(lang)
Expand Down
13 changes: 8 additions & 5 deletions autogen/exception_utils.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
from typing import Any


class AgentNameConflict(Exception):
def __init__(self, msg="Found multiple agents with the same name.", *args, **kwargs):
def __init__(self, msg: str = "Found multiple agents with the same name.", *args: Any, **kwargs: Any):
super().__init__(msg, *args, **kwargs)


class NoEligibleSpeaker(Exception):
"""Exception raised for early termination of a GroupChat."""

def __init__(self, message="No eligible speakers."):
def __init__(self, message: str = "No eligible speakers."):
self.message = message
super().__init__(self.message)


class SenderRequired(Exception):
"""Exception raised when the sender is required but not provided."""

def __init__(self, message="Sender is required but not provided."):
def __init__(self, message: str = "Sender is required but not provided."):
self.message = message
super().__init__(self.message)

Expand All @@ -23,7 +26,7 @@ class InvalidCarryOverType(Exception):
"""Exception raised when the carryover type is invalid."""

def __init__(
self, message="Carryover should be a string or a list of strings. Not adding carryover to the message."
self, message: str = "Carryover should be a string or a list of strings. Not adding carryover to the message."
):
self.message = message
super().__init__(self.message)
Expand All @@ -32,6 +35,6 @@ def __init__(
class UndefinedNextAgent(Exception):
"""Exception raised when the provided next agents list does not overlap with agents in the group."""

def __init__(self, message="The provided agents list does not overlap with agents in the group."):
def __init__(self, message: str = "The provided agents list does not overlap with agents in the group."):
self.message = message
super().__init__(self.message)
4 changes: 2 additions & 2 deletions notebook/agentchat_RetrieveChat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"\n",
"## Construct agents for RetrieveChat\n",
"\n",
"We start by initializing the `RetrieveAssistantAgent` and `RetrieveUserProxyAgent`. The system message needs to be set to \"You are a helpful assistant.\" for RetrieveAssistantAgent. The detailed instructions are given in the user message. Later we will use the `RetrieveUserProxyAgent.generate_init_prompt` to combine the instructions and a retrieval augmented generation task for an initial prompt to be sent to the LLM assistant."
"We start by initializing the `RetrieveAssistantAgent` and `RetrieveUserProxyAgent`. The system message needs to be set to \"You are a helpful assistant.\" for RetrieveAssistantAgent. The detailed instructions are given in the user message. Later we will use the `RetrieveUserProxyAgent.message_generator` to combine the instructions and a retrieval augmented generation task for an initial prompt to be sent to the LLM assistant."
]
},
{
Expand Down Expand Up @@ -3037,7 +3037,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.13"
},
"skip_test": "Requires interactive usage"
},
Expand Down
19 changes: 8 additions & 11 deletions notebook/agentchat_groupchat_customized.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
"```\n",
"The last speaker and the groupchat object are passed to the function. Commonly used variables from groupchat are `groupchat.messages` an `groupchat.agents`, which is the message history and the agents in the group chat respectively. You can access other attributes of the groupchat, such as `groupchat.allowed_speaker_transitions_dict` for pre-defined allowed_speaker_transitions_dict. \n",
"\n",
"\n",
"\n",
"\n",
"````{=mdx}\n",
":::info Requirements\n",
"Install `pyautogen`:\n",
Expand Down Expand Up @@ -85,7 +82,7 @@
"source": [
"````{=mdx}\n",
":::tip\n",
"Learn more about configuring LLMs for agents [here](/docs/llm_configuration).\n",
"Learn more about configuring LLMs for agents [here](/docs/topics/llm_configuration).\n",
":::\n",
"````\n",
"\n",
Expand Down Expand Up @@ -443,16 +440,16 @@
")\n",
"# type exit to terminate the chat"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"front_matter": {
"description": "Introduce Group Chat with Customized Speaker Selection Method",
"tags": [
"orchestration",
"group chat"
]
},
"kernelspec": {
"display_name": "flaml",
"language": "python",
Expand Down
Loading

0 comments on commit 89650e7

Please sign in to comment.