Skip to content

A programming framework for agentic AI

add long context handling notebook (#1618)

Chi Wange83de5d0082c
diff --git a/autogen/coding/base.py b/autogen/coding/base.py
index 13e84da8c..936d3ee25 100644
--- a/autogen/coding/base.py
+++ b/autogen/coding/base.py
@@ -8,7 +8,7 @@ __all__ = ("CodeBlock", "CodeResult", "CodeExtractor", "CodeExecutor")
class CodeBlock(BaseModel):
- """A class that represents a code block."""
+ """(Experimental) A class that represents a code block."""
code: str = Field(description="The code to execute.")
@@ -16,7 +16,7 @@ class CodeBlock(BaseModel):
class CodeResult(BaseModel):
- """A class that represents the result of a code execution."""
+ """(Experimental) A class that represents the result of a code execution."""
exit_code: int = Field(description="The exit code of the code execution.")
@@ -24,10 +24,10 @@ class CodeResult(BaseModel):
class CodeExtractor(Protocol):
- """A code extractor class that extracts code blocks from a message."""
+ """(Experimental) A code extractor class that extracts code blocks from a message."""
def extract_code_blocks(self, message: Union[str, List[Dict[str, Any]], None]) -> List[CodeBlock]:
- """Extract code blocks from a message.
+ """(Experimental) Extract code blocks from a message.
Args:
message (str): The message to extract code blocks from.
@@ -40,17 +40,17 @@ class CodeExtractor(Protocol):
@runtime_checkable
class CodeExecutor(Protocol):
- """A code executor class that executes code blocks and returns the result."""
+ """(Experimental) A code executor class that executes code blocks and returns the result."""
class UserCapability(Protocol):
- """An AgentCapability class that gives agent ability use this code executor."""
+ """(Experimental) An AgentCapability class that gives agent ability use this code executor."""
def add_to_agent(self, agent: LLMAgent) -> None:
... # pragma: no cover
@property
def user_capability(self) -> "CodeExecutor.UserCapability":
- """Capability to use this code executor.
+ """(Experimental) Capability to use this code executor.
The exported capability can be added to an agent to allow it to use this
code executor:
@@ -68,11 +68,11 @@ class CodeExecutor(Protocol):
@property
def code_extractor(self) -> CodeExtractor:
- """The code extractor used by this code executor."""
+ """(Experimental) The code extractor used by this code executor."""
... # pragma: no cover
def execute_code_blocks(self, code_blocks: List[CodeBlock]) -> CodeResult:
- """Execute code blocks and return the result.
+ """(Experimental) Execute code blocks and return the result.
This method should be implemented by the code executor.
@@ -85,7 +85,7 @@ class CodeExecutor(Protocol):
... # pragma: no cover
def restart(self) -> None:
- """Restart the code executor.
+ """(Experimental) Restart the code executor.
This method should be implemented by the code executor.
diff --git a/autogen/coding/embedded_ipython_code_executor.py b/autogen/coding/embedded_ipython_code_executor.py
index 3232c12e3..01a640015 100644
--- a/autogen/coding/embedded_ipython_code_executor.py
+++ b/autogen/coding/embedded_ipython_code_executor.py
@@ -18,7 +18,7 @@ __all__ = ("EmbeddedIPythonCodeExecutor",)
class IPythonCodeResult(CodeResult):
- """A code result class for IPython code executor."""
+ """(Experimental) A code result class for IPython code executor."""
output_files: List[str] = Field(
default_factory=list,
@@ -27,7 +27,7 @@ class IPythonCodeResult(CodeResult):
class EmbeddedIPythonCodeExecutor(BaseModel):
- """A code executor class that executes code statefully using an embedded
+ """(Experimental) A code executor class that executes code statefully using an embedded
IPython kernel managed by this class.
**This will execute LLM generated code on the local machine.**
@@ -85,7 +85,7 @@ the output will be a path to the image instead of the image itself.
)
class UserCapability:
- """An AgentCapability class that gives agent ability use a stateful
+ """(Experimental) An AgentCapability class that gives agent ability use a stateful
IPython code executor. This capability can be added to an agent using
the `add_to_agent` method which append a system message update to the
agent's system message."""
@@ -129,17 +129,17 @@ the output will be a path to the image instead of the image itself.
@property
def user_capability(self) -> "EmbeddedIPythonCodeExecutor.UserCapability":
- """Export a user capability for this executor that can be added to
+ """(Experimental) Export a user capability for this executor that can be added to
an agent using the `add_to_agent` method."""
return EmbeddedIPythonCodeExecutor.UserCapability(self.system_message_update)
@property
def code_extractor(self) -> CodeExtractor:
- """Export a code extractor that can be used by an agent."""
+ """(Experimental) Export a code extractor that can be used by an agent."""
return MarkdownCodeExtractor()
def execute_code_blocks(self, code_blocks: List[CodeBlock]) -> IPythonCodeResult:
- """Execute a list of code blocks and return the result.
+ """(Experimental) Execute a list of code blocks and return the result.
This method executes a list of code blocks as cells in an IPython kernel
managed by this class.
@@ -204,7 +204,7 @@ the output will be a path to the image instead of the image itself.
)
def restart(self) -> None:
- """Restart a new session."""
+ """(Experimental) Restart a new session."""
self._kernel_client.stop_channels()
self._kernel_manager.shutdown_kernel()
self._kernel_manager = KernelManager(kernel_name=self.kernel_name)
diff --git a/autogen/coding/factory.py b/autogen/coding/factory.py
index 65149b5a8..953de5906 100644
--- a/autogen/coding/factory.py
+++ b/autogen/coding/factory.py
@@ -6,11 +6,11 @@ __all__ = ("CodeExecutorFactory",)
class CodeExecutorFactory:
- """A factory class for creating code executors."""
+ """(Experimental) A factory class for creating code executors."""
@staticmethod
def create(code_execution_config: Dict[str, Any]) -> CodeExecutor:
- """Get a code executor based on the code execution config.
+ """(Experimental) Get a code executor based on the code execution config.
Args:
code_execution_config (Dict): The code execution config,
diff --git a/autogen/coding/local_commandline_code_executor.py b/autogen/coding/local_commandline_code_executor.py
index 252c57376..5989e940d 100644
--- a/autogen/coding/local_commandline_code_executor.py
+++ b/autogen/coding/local_commandline_code_executor.py
@@ -25,7 +25,7 @@ __all__ = (
class CommandlineCodeResult(CodeResult):
- """A code result class for command line code executor."""
+ """(Experimental) A code result class for command line code executor."""
code_file: Optional[str] = Field(
default=None,
@@ -34,7 +34,7 @@ class CommandlineCodeResult(CodeResult):
class LocalCommandlineCodeExecutor(BaseModel):
- """A code executor class that executes code through a local command line
+ """(Experimental) A code executor class that executes code through a local command line
environment.
**This will execute LLM generated code on the local machine.**
@@ -105,11 +105,11 @@ If you want the user to save the code in a file before executing it, put # filen
@property
def code_extractor(self) -> CodeExtractor:
- """Export a code extractor that can be used by an agent."""
+ """(Experimental) Export a code extractor that can be used by an agent."""
return MarkdownCodeExtractor()
def execute_code_blocks(self, code_blocks: List[CodeBlock]) -> CommandlineCodeResult:
- """Execute the code blocks and return the result.
+ """(Experimental) Execute the code blocks and return the result.
Args:
code_blocks (List[CodeBlock]): The code blocks to execute.
@@ -158,5 +158,5 @@ If you want the user to save the code in a file before executing it, put # filen
return CommandlineCodeResult(exit_code=exitcode, output=logs_all, code_file=code_filename)
def restart(self) -> None:
- """Restart the code executor."""
+ """(Experimental) Restart the code executor."""
warnings.warn("Restarting local command line code executor is not supported. No action is taken.")
diff --git a/autogen/coding/markdown_code_extractor.py b/autogen/coding/markdown_code_extractor.py
index 73a1e03e6..cee107fdb 100644
--- a/autogen/coding/markdown_code_extractor.py
+++ b/autogen/coding/markdown_code_extractor.py
@@ -8,10 +8,10 @@ __all__ = ("MarkdownCodeExtractor",)
class MarkdownCodeExtractor:
- """A class that extracts code blocks from a message using Markdown syntax."""
+ """(Experimental) A class that extracts code blocks from a message using Markdown syntax."""
def extract_code_blocks(self, message: Union[str, List[Dict[str, Any]], None]) -> List[CodeBlock]:
- """Extract code blocks from a message. If no code blocks are found,
+ """(Experimental) Extract code blocks from a message. If no code blocks are found,
return an empty list.
Args:
diff --git a/autogen/oai/client.py b/autogen/oai/client.py
index 12dc9e8c3..1c46a01e8 100644
--- a/autogen/oai/client.py
+++ b/autogen/oai/client.py
@@ -1,6 +1,5 @@
from __future__ import annotations
-import os
import sys
from typing import Any, List, Optional, Dict, Callable, Tuple, Union
import logging
@@ -11,11 +10,8 @@ from pydantic import BaseModel
from typing import Protocol
from autogen.cache.cache import Cache
-from autogen.oai import completion
-
-from autogen.oai.openai_utils import DEFAULT_AZURE_API_VERSION, get_key, OAI_PRICE1K
+from autogen.oai.openai_utils import get_key, OAI_PRICE1K
from autogen.token_count_utils import count_token
-from autogen._pydantic import model_dump
TOOL_ENABLED = False
try:
diff --git a/autogen/version.py b/autogen/version.py
index b5c9b6cb7..11ef09286 100644
--- a/autogen/version.py
+++ b/autogen/version.py
@@ -1 +1 @@
-__version__ = "0.2.12"
+__version__ = "0.2.13"
diff --git a/website/docs/Examples.md b/website/docs/Examples.md
index db317310b..4401fe084 100644
--- a/website/docs/Examples.md
+++ b/website/docs/Examples.md
@@ -74,7 +74,8 @@ Links to notebook examples:
1. **Long Context Handling**
- - Conversations with Chat History Compression Enabled - [View Notebook](https://github.com/microsoft/autogen/blob/main/notebook/agentchat_compression.ipynb)
+ <!-- - Conversations with Chat History Compression Enabled - [View Notebook](https://github.com/microsoft/autogen/blob/main/notebook/agentchat_compression.ipynb) -->
+ - Long Context Handling as A Capability - [View Notebook](https://github.com/microsoft/autogen/blob/main/notebook/agentchat_capability_long_context_handling.ipynb)
1. **Evaluation and Assessment**