Skip to content

Commit

Permalink
Documentation tweaks (#3705)
Browse files Browse the repository at this point in the history
* Add extension to handle pydantic docs

* Docs tweaks

---------

Co-authored-by: Eric Zhu <[email protected]>
  • Loading branch information
jackgerrits and ekzhu authored Oct 9, 2024
1 parent d037db9 commit f326b36
Show file tree
Hide file tree
Showing 20 changed files with 151 additions and 116 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from ._base_chat_agent import (
BaseChatAgent,
BaseMessage,
BaseToolUseChatAgent,
ChatMessage,
MultiModalMessage,
Expand All @@ -14,14 +15,15 @@

__all__ = [
"BaseChatAgent",
"BaseMessage",
"BaseToolUseChatAgent",
"ChatMessage",
"TextMessage",
"CodeExecutorAgent",
"CodingAssistantAgent",
"MultiModalMessage",
"StopMessage",
"TextMessage",
"ToolCallMessage",
"ToolCallResultMessage",
"StopMessage",
"CodeExecutorAgent",
"CodingAssistantAgent",
"ToolUseAssistantAgent",
]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def __init__(
*,
description: str = "A computer terminal that performs no other action than running Python scripts (provided to it quoted in ```python code blocks), or sh shell scripts (provided to it quoted in ```sh code blocks).",
) -> None:
"""Initialize the agent with a code executor."""
super().__init__(name=name, description=description)
self._code_executor = code_executor

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from ._logging import EVENT_LOGGER_NAME, TRACE_LOGGER_NAME, ConsoleLogHandler, FileLogHandler
from ._termination import MaxMessageTermination, StopMessageTermination, TerminationCondition, TextMentionTermination
from .group_chat._round_robin_group_chat import RoundRobinGroupChat
from .group_chat._selector_group_chat import SelectorGroupChat
from ._group_chat._round_robin_group_chat import RoundRobinGroupChat
from ._group_chat._selector_group_chat import SelectorGroupChat

__all__ = [
"TRACE_LOGGER_NAME",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List

import pytest
from autogen_agentchat.teams.group_chat._sequential_routed_agent import SequentialRoutedAgent
from autogen_agentchat.teams._group_chat._sequential_routed_agent import SequentialRoutedAgent
from autogen_core.application import SingleThreadedAgentRuntime
from autogen_core.base import AgentId, MessageContext
from autogen_core.components import DefaultTopicId, default_subscription, message_handler
Expand Down
5 changes: 4 additions & 1 deletion python/packages/autogen-core/docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@
"sphinx_copybutton",
"_extension.gallery_directive",
"myst_nb",
"sphinxcontrib.autodoc_pydantic"
]
suppress_warnings = ["myst.header"]

napoleon_custom_sections = [("Returns", "params_style")]

templates_path = ["_templates"]

autoclass_content = "init"
autoclass_content = "class"

# TODO: incldue all notebooks excluding those requiring remote API access.
nb_execution_mode = "off"
Expand Down Expand Up @@ -128,6 +129,8 @@
"undoc-members": True,
}

autodoc_pydantic_model_show_config_summary = False

intersphinx_mapping = {"python": ("https://docs.python.org/3", None)}


Expand Down
1 change: 1 addition & 0 deletions python/packages/autogen-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ dev-dependencies = [
"sphinx-design",
"sphinx",
"sphinxcontrib-apidoc",
"autodoc_pydantic~=2.2",

# Documentation tooling
"sphinx-autobuild",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@


class DefaultSubscription(TypeSubscription):
def __init__(self, topic_type: str = "default", agent_type: str | None = None):
"""The default subscription is designed to be a sensible default for applications that only need global scope for agents.
"""The default subscription is designed to be a sensible default for applications that only need global scope for agents.
This topic by default uses the "default" topic type and attempts to detect the agent type to use based on the instantiation context.
This topic by default uses the "default" topic type and attempts to detect the agent type to use based on the instantiation context.
Example:
Example:
.. code-block:: python
.. code-block:: python
await runtime.register("MyAgent", agent_factory, lambda: [DefaultSubscription()])
await runtime.register("MyAgent", agent_factory, lambda: [DefaultSubscription()])
Args:
topic_type (str, optional): The topic type to subscribe to. Defaults to "default".
agent_type (str, optional): The agent type to use for the subscription. Defaults to None, in which case it will attempt to detect the agent type based on the instantiation context.
"""
Args:
topic_type (str, optional): The topic type to subscribe to. Defaults to "default".
agent_type (str, optional): The agent type to use for the subscription. Defaults to None, in which case it will attempt to detect the agent type based on the instantiation context.
"""

def __init__(self, topic_type: str = "default", agent_type: str | None = None):
if agent_type is None:
try:
agent_type = SubscriptionInstantiationContext.agent_type().type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@


class DefaultTopicId(TopicId):
def __init__(self, type: str = "default", source: str | None = None) -> None:
"""DefaultTopicId provides a sensible default for the topic_id and source fields of a TopicId.
"""DefaultTopicId provides a sensible default for the topic_id and source fields of a TopicId.
If created in the context of a message handler, the source will be set to the agent_id of the message handler, otherwise it will be set to "default".
If created in the context of a message handler, the source will be set to the agent_id of the message handler, otherwise it will be set to "default".
Args:
type (str, optional): Topic type to publish message to. Defaults to "default".
source (str | None, optional): Topic source to publish message to. If None, the source will be set to the agent_id of the message handler if in the context of a message handler, otherwise it will be set to "default". Defaults to None.
"""

Args:
type (str, optional): Topic type to publish message to. Defaults to "default".
source (str | None, optional): Topic source to publish message to. If None, the source will be set to the agent_id of the message handler if in the context of a message handler, otherwise it will be set to "default". Defaults to None.
"""
def __init__(self, type: str = "default", source: str | None = None) -> None:
if source is None:
try:
source = MessageHandlerContext.agent_id().key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,27 @@


class TypeSubscription(Subscription):
def __init__(self, topic_type: str, agent_type: str):
"""This subscription matches on topics based on the type and maps to agents using the source of the topic as the agent key.
"""This subscription matches on topics based on the type and maps to agents using the source of the topic as the agent key.
This subscription causes each source to have its own agent instance.
This subscription causes each source to have its own agent instance.
Example:
Example:
.. code-block:: python
.. code-block:: python
subscription = TypeSubscription(topic_type="t1", agent_type="a1")
subscription = TypeSubscription(topic_type="t1", agent_type="a1")
In this case:
In this case:
- A topic_id with type `t1` and source `s1` will be handled by an agent of type `a1` with key `s1`
- A topic_id with type `t1` and source `s2` will be handled by an agent of type `a1` with key `s2`.
- A topic_id with type `t1` and source `s1` will be handled by an agent of type `a1` with key `s1`
- A topic_id with type `t1` and source `s2` will be handled by an agent of type `a1` with key `s2`.
Args:
topic_type (str): Topic type to match against
agent_type (str): Agent type to handle this subscription
"""
Args:
topic_type (str): Topic type to match against
agent_type (str): Agent type to handle this subscription
"""

def __init__(self, topic_type: str, agent_type: str):
self._topic_type = topic_type
self._agent_type = agent_type
self._id = str(uuid.uuid4())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,36 @@ async def _wait_for_ready(container: Any, timeout: int = 60, stop_time: float =


class DockerCommandLineCodeExecutor(CodeExecutor):
"""Executes code through a command line environment in a Docker container.
The executor first saves each code block in a file in the working
directory, and then executes the code file in the container.
The executor executes the code blocks in the order they are received.
Currently, the executor only supports Python and shell scripts.
For Python code, use the language "python" for the code block.
For shell scripts, use the language "bash", "shell", or "sh" for the code
block.
Args:
image (_type_, optional): Docker image to use for code execution.
Defaults to "python:3-slim".
container_name (Optional[str], optional): Name of the Docker container
which is created. If None, will autogenerate a name. Defaults to None.
timeout (int, optional): The timeout for code execution. Defaults to 60.
work_dir (Union[Path, str], optional): The working directory for the code
execution. Defaults to Path(".").
bind_dir (Union[Path, str], optional): The directory that will be bound
to the code executor container. Useful for cases where you want to spawn
the container from within a container. Defaults to work_dir.
auto_remove (bool, optional): If true, will automatically remove the Docker
container when it is stopped. Defaults to True.
stop_container (bool, optional): If true, will automatically stop the
container when stop is called, when the context manager exits or when
the Python process exits with atext. Defaults to True.
functions (List[Union[FunctionWithRequirements[Any, A], Callable[..., Any]]]): A list of functions that are available to the code executor. Default is an empty list.
functions_module (str, optional): The name of the module that will be created to store the functions. Defaults to "functions".
"""

SUPPORTED_LANGUAGES: ClassVar[List[str]] = [
"bash",
"shell",
Expand Down Expand Up @@ -87,35 +117,6 @@ def __init__(
] = [],
functions_module: str = "functions",
):
"""Executes code through a command line environment in a Docker container.
The executor first saves each code block in a file in the working
directory, and then executes the code file in the container.
The executor executes the code blocks in the order they are received.
Currently, the executor only supports Python and shell scripts.
For Python code, use the language "python" for the code block.
For shell scripts, use the language "bash", "shell", or "sh" for the code
block.
Args:
image (_type_, optional): Docker image to use for code execution.
Defaults to "python:3-slim".
container_name (Optional[str], optional): Name of the Docker container
which is created. If None, will autogenerate a name. Defaults to None.
timeout (int, optional): The timeout for code execution. Defaults to 60.
work_dir (Union[Path, str], optional): The working directory for the code
execution. Defaults to Path(".").
bind_dir (Union[Path, str], optional): The directory that will be bound
to the code executor container. Useful for cases where you want to spawn
the container from within a container. Defaults to work_dir.
auto_remove (bool, optional): If true, will automatically remove the Docker
container when it is stopped. Defaults to True.
stop_container (bool, optional): If true, will automatically stop the
container when stop is called, when the context manager exits or when
the Python process exits with atext. Defaults to True.
functions (List[Union[FunctionWithRequirements[Any, A], Callable[..., Any]]]): A list of functions that are available to the code executor. Default is an empty list.
functions_module (str, optional): The name of the module that will be created to store the functions. Defaults to "functions".
"""
if timeout < 1:
raise ValueError("Timeout must be greater than or equal to 1.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,34 @@


class LocalCommandLineCodeExecutor(CodeExecutor):
"""A code executor class that executes code through a local command line
environment.
.. danger::
This will execute code on the local machine. If being used with LLM generated code, caution should be used.
Each code block is saved as a file and executed in a separate process in
the working directory, and a unique file is generated and saved in the
working directory for each code block.
The code blocks are executed in the order they are received.
Command line code is sanitized using regular expression match against a list of dangerous commands in order to prevent self-destructive
commands from being executed which may potentially affect the users environment.
Currently the only supported languages is Python and shell scripts.
For Python code, use the language "python" for the code block.
For shell scripts, use the language "bash", "shell", or "sh" for the code
block.
Args:
timeout (int): The timeout for the execution of any single code block. Default is 60.
work_dir (str): The working directory for the code execution. If None,
a default working directory will be used. The default working
directory is the current directory ".".
functions (List[Union[FunctionWithRequirements[Any, A], Callable[..., Any]]]): A list of functions that are available to the code executor. Default is an empty list.
functions_module (str, optional): The name of the module that will be created to store the functions. Defaults to "functions".
"""

SUPPORTED_LANGUAGES: ClassVar[List[str]] = [
"bash",
"shell",
Expand Down Expand Up @@ -59,34 +87,6 @@ def __init__(
] = [],
functions_module: str = "functions",
):
"""A code executor class that executes code through a local command line
environment.
.. danger::
This will execute code on the local machine. If being used with LLM generated code, caution should be used.
Each code block is saved as a file and executed in a separate process in
the working directory, and a unique file is generated and saved in the
working directory for each code block.
The code blocks are executed in the order they are received.
Command line code is sanitized using regular expression match against a list of dangerous commands in order to prevent self-destructive
commands from being executed which may potentially affect the users environment.
Currently the only supported languages is Python and shell scripts.
For Python code, use the language "python" for the code block.
For shell scripts, use the language "bash", "shell", or "sh" for the code
block.
Args:
timeout (int): The timeout for the execution of any single code block. Default is 60.
work_dir (str): The working directory for the code execution. If None,
a default working directory will be used. The default working
directory is the current directory ".".
functions (List[Union[FunctionWithRequirements[Any, A], Callable[..., Any]]]): A list of functions that are available to the code executor. Default is an empty list.
functions_module (str, optional): The name of the module that will be created to store the functions. Defaults to "functions".
"""

if timeout < 1:
raise ValueError("Timeout must be greater than or equal to 1.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ def get_token(


class AzureContainerCodeExecutor(CodeExecutor):
"""(Experimental) A code executor class that executes code through a an Azure
Container Apps instance.
**This will execute LLM generated code on an Azure dynamic code container.**
The execution environment is similar to that of a jupyter notebook which allows for incremental code execution. The parameter functions are executed in order once at the beginning of each session. Each code block is then executed serially and in the order they are received. Each environment has a statically defined set of available packages which cannot be changed.
Currently, attempting to use packages beyond what is available on the environment will result in an error. To get the list of supported packages, call the `get_available_packages` function.
Currently the only supported language is Python.
For Python code, use the language "python" for the code block.
Args:
pool_management_endpoint (str): The azure container apps dynamic sessions endpoint.
credential (TokenProvider): An object that implements the get_token function.
timeout (int): The timeout for the execution of any single code block. Default is 60.
work_dir (str): The working directory for the code execution. If None,
a default working directory will be used. The default working
directory is the current directory ".".
functions (List[Union[FunctionWithRequirements[Any, A], Callable[..., Any]]]): A list of functions that are available to the code executor. Default is an empty list.
"""

SUPPORTED_LANGUAGES: ClassVar[List[str]] = [
"python",
]
Expand All @@ -63,26 +83,6 @@ def __init__(
] = [],
functions_module: str = "functions",
):
"""(Experimental) A code executor class that executes code through a an Azure
Container Apps instance.
**This will execute LLM generated code on an Azure dynamic code container.**
The execution environment is similar to that of a jupyter notebook which allows for incremental code execution. The parameter functions are executed in order once at the beginning of each session. Each code block is then executed serially and in the order they are received. Each environment has a statically defined set of available packages which cannot be changed.
Currently, attempting to use packages beyond what is available on the environment will result in an error. To get the list of supported packages, call the `get_available_packages` function.
Currently the only supported language is Python.
For Python code, use the language "python" for the code block.
Args:
pool_management_endpoint (str): The azure container apps dynamic sessions endpoint.
credential (TokenProvider): An object that implements the get_token function.
timeout (int): The timeout for the execution of any single code block. Default is 60.
work_dir (str): The working directory for the code execution. If None,
a default working directory will be used. The default working
directory is the current directory ".".
functions (List[Union[FunctionWithRequirements[Any, A], Callable[..., Any]]]): A list of functions that are available to the code executor. Default is an empty list.
"""

if timeout < 1:
raise ValueError("Timeout must be greater than or equal to 1.")

Expand Down
Loading

0 comments on commit f326b36

Please sign in to comment.