Skip to content

Commit

Permalink
Merge branch 'main' into dotnet-signed
Browse files Browse the repository at this point in the history
  • Loading branch information
rysweet authored Jan 15, 2025
2 parents 2db093d + ae98c9d commit b16e31c
Show file tree
Hide file tree
Showing 36 changed files with 2,790 additions and 402 deletions.
1 change: 0 additions & 1 deletion python/packages/autogen-agentchat/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ classifiers = [
]
dependencies = [
"autogen-core==0.4.1",
"aioconsole>=0.8.1"
]

[tool.ruff]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from inspect import iscoroutinefunction
from typing import Any, AsyncGenerator, Awaitable, Callable, ClassVar, Generator, Optional, Sequence, Union, cast

from aioconsole import ainput # type: ignore
from autogen_core import CancellationToken

from ..base import Response
Expand All @@ -17,10 +16,9 @@
InputFuncType = Union[SyncInputFunc, AsyncInputFunc]


# TODO: ainput doesn't seem to play nicely with jupyter.
# No input window appears in this case.
# TODO: check if using to_thread fixes this in jupyter
async def cancellable_input(prompt: str, cancellation_token: Optional[CancellationToken]) -> str:
task: asyncio.Task[str] = asyncio.create_task(ainput(prompt)) # type: ignore
task: asyncio.Task[str] = asyncio.create_task(asyncio.to_thread(input, prompt))
if cancellation_token is not None:
cancellation_token.link_future(task)
return await task
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from inspect import iscoroutinefunction
from typing import AsyncGenerator, Awaitable, Callable, Dict, List, Optional, TypeVar, Union, cast

from aioconsole import aprint # type: ignore
from autogen_core import CancellationToken, Image
from autogen_core.models import RequestUsage

Expand Down Expand Up @@ -70,6 +69,10 @@ def notify_event_received(self, request_id: str) -> None:
self.input_events[request_id] = event


def aprint(output: str, end: str = "\n") -> Awaitable[None]:
return asyncio.to_thread(print, output, end=end)


async def Console(
stream: AsyncGenerator[AgentEvent | ChatMessage | T, None],
*,
Expand Down
2 changes: 2 additions & 0 deletions python/packages/autogen-core/docs/src/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ python/autogen_core.models
python/autogen_core.model_context
python/autogen_core.tools
python/autogen_core.tool_agent
python/autogen_core.memory
python/autogen_core.exceptions
python/autogen_core.logging
```
Expand All @@ -50,6 +51,7 @@ python/autogen_ext.teams.magentic_one
python/autogen_ext.models.openai
python/autogen_ext.models.replay
python/autogen_ext.tools.langchain
python/autogen_ext.tools.graphrag
python/autogen_ext.tools.code_execution
python/autogen_ext.code_executors.local
python/autogen_ext.code_executors.docker
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
autogen\_core.memory
====================


.. automodule:: autogen_core.memory
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
autogen\_ext.tools.graphrag
===========================


.. automodule:: autogen_ext.tools.graphrag
:members:
:undoc-members:
:show-inheritance:
Original file line number Diff line number Diff line change
Expand Up @@ -57,61 +57,65 @@ conda deactivate
``````

## Install Using pip (Recommended)
## Install from PyPi (Recommended)

You can install AutoGen Studio using pip, the Python package manager.

```bash
pip install -U autogenstudio
```

### Install from Source\*\*
## Install from source

> Note: This approach requires some familiarity with building interfaces in React.
_Note: This approach requires some familiarity with building interfaces in React._

If you prefer to install from source, ensure you have Python 3.10+ and Node.js (version above 14.15.0) installed. Here's how you get started:
You have two options for installing from source: manually or using a dev container.

- Clone the AutoGen Studio repository and install its Python dependencies:
### A) Install from source manually

```bash
pip install -e .
```

- Navigate to the `samples/apps/autogen-studio/frontend` directory, install dependencies, and build the UI:
1. Ensure you have Python 3.10+ and Node.js (version above 14.15.0) installed.
2. Clone the AutoGen Studio repository and install its Python dependencies using `pip install -e .`
3. Navigate to the `python/packages/autogen-studio/frontend` directory, install the dependencies, and build the UI:

```bash
npm install -g gatsby-cli
npm install --global yarn
cd frontend
yarn install
yarn build
# Windows users may need alternative commands to build the frontend:
gatsby clean && rmdir /s /q ..\\autogenstudio\\web\\ui 2>nul & (set \"PREFIX_PATH_VALUE=\" || ver>nul) && gatsby build --prefix-paths && xcopy /E /I /Y public ..\\autogenstudio\\web\\ui
```

For Windows users, to build the frontend, you may need alternative commands to build the frontend.

```bash
### B) Install from source using a dev container

gatsby clean && rmdir /s /q ..\\autogenstudio\\web\\ui 2>nul & (set \"PREFIX_PATH_VALUE=\" || ver>nul) && gatsby build --prefix-paths && xcopy /E /I /Y public ..\\autogenstudio\\web\\ui
1. Follow the [Dev Containers tutorial](https://code.visualstudio.com/docs/devcontainers/tutorial) to install VS Code, Docker and relevant extensions.
2. Clone the AutoGen Studio repository.
3. Open `python/packages/autogen-studio/`in VS Code. Click the blue button in bottom the corner or press F1 and select _"Dev Containers: Reopen in Container"_.
4. Build the UI:

```
```bash
cd frontend
yarn build
```

## Running the Application

Once installed, run the web UI by entering the following in a terminal:
Once installed, run the web UI by entering the following in your terminal:

```bash
autogenstudio ui --port 8081 --appdir /path/to/folder
autogenstudio ui --port 8081
```

This will start the application on the specified port. Open your web browser and go to `http://localhost:8081/` to begin using AutoGen Studio.
This command will start the application on the specified port. Open your web browser and go to <http://localhost:8081/> to use AutoGen Studio.

AutoGen Studio also takes several parameters to customize the application:

- `--host <host>` argument to specify the host address. By default, it is set to `localhost`.
- `--appdir <appdir>` argument to specify the directory where the app files (e.g., database and generated user files) are stored. By default, it is set to the a `.autogenstudio` directory in the user's home directory.
- `--appdir <appdir>` argument to specify the directory where the app files (e.g., database and generated user files) are stored. By default, it is set to the `.autogenstudio` directory in the user's home directory.
- `--port <port>` argument to specify the port number. By default, it is set to `8080`.
- `--upgrade-database` argument to force-upgrade it's internal database schema (assuming there are changes in the version you are installing). By default, it is set to `False`.
- `--reload` argument to enable auto-reloading of the server when changes are made to the code. By default, it is set to `False`.
- `--database-uri` argument to specify the database URI. Example values include `sqlite:///database.sqlite` for SQLite and `postgresql+psycopg://user:password@localhost/dbname` for PostgreSQL. If this is not specified, the database URI defaults to a `autogen.db` file in the `--appdir` directory.
- `--database-uri` argument to specify the database URI. Example values include `sqlite:///database.sqlite` for SQLite and `postgresql+psycopg://user:password@localhost/dbname` for PostgreSQL. If this is not specified, the database URL defaults to a `database.sqlite` file in the `--appdir` directory.
- `--upgrade-database` argument to upgrade the database schema to the latest version. By default, it is set to `False`.

Now that you have AutoGen Studio installed and running, you are ready to explore its capabilities, including defining and modifying agent workflows, interacting with agents and sessions, and expanding agent skills.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from datetime import datetime
from enum import Enum
from typing import Any, Dict, List, Protocol, Union, runtime_checkable

Expand All @@ -23,32 +22,47 @@ class MemoryMimeType(Enum):


class MemoryContent(BaseModel):
"""A memory content item."""

content: ContentType
"""The content of the memory item. It can be a string, bytes, dict, or :class:`~autogen_core.Image`."""

mime_type: MemoryMimeType | str
"""The MIME type of the memory content."""

metadata: Dict[str, Any] | None = None
timestamp: datetime | None = None
source: str | None = None
score: float | None = None
"""Metadata associated with the memory item."""

model_config = ConfigDict(arbitrary_types_allowed=True)


class MemoryQueryResult(BaseModel):
"""Result of a memory :meth:`~autogen_core.memory.Memory.query` operation."""

results: List[MemoryContent]


class UpdateContextResult(BaseModel):
"""Result of a memory :meth:`~autogen_core.memory.Memory.update_context` operation."""

memories: MemoryQueryResult


@runtime_checkable
class Memory(Protocol):
"""Protocol defining the interface for memory implementations."""
"""Protocol defining the interface for memory implementations.
@property
def name(self) -> str | None:
"""The name of this memory implementation."""
...
A memory is the storage for data that can be used to enrich or modify the model context.
A memory implementation can use any storage mechanism, such as a list, a database, or a file system.
It can also use any retrieval mechanism, such as vector search or text search.
It is up to the implementation to decide how to store and retrieve data.
It is also a memory implementation's responsibility to update the model context
with relevant memory content based on the current model context and querying the memory store.
See :class:`~autogen_core.memory.ListMemory` for an example implementation.
"""

async def update_context(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,43 @@ class ListMemory(Memory):
allowing external applications to manage memory contents directly.
Example:
.. code-block:: python
# Initialize memory
memory = ListMemory(name="chat_history")
# Add memory content
content = MemoryContent(content="User prefers formal language")
await memory.add(content)
.. code-block:: python
# Directly modify memory contents
memory.content = [MemoryContent(content="New preference")]
import asyncio
from autogen_core.memory import ListMemory, MemoryContent
from autogen_core.model_context import BufferedChatCompletionContext
# Update a model context with memory
memory_contents = await memory.update_context(model_context)
async def main() -> None:
# Initialize memory
memory = ListMemory(name="chat_history")
# Add memory content
content = MemoryContent(content="User prefers formal language", mime_type="text/plain")
await memory.add(content)
# Directly modify memory contents
memory.content = [MemoryContent(content="New preference", mime_type="text/plain")]
# Create a model context
model_context = BufferedChatCompletionContext(buffer_size=10)
# Update a model context with memory
await memory.update_context(model_context)
# See the updated model context
print(await model_context.get_messages())
asyncio.run(main())
Args:
name: Optional identifier for this memory instance
Attributes:
name (str): Identifier for this memory instance
content (List[MemoryContent]): Direct access to memory contents
"""

def __init__(self, name: str | None = None) -> None:
"""Initialize ListMemory.
Args:
name: Optional identifier for this memory instance
"""
self._name = name or "default_list_memory"
self._contents: List[MemoryContent] = []

Expand Down
7 changes: 2 additions & 5 deletions python/packages/autogen-core/tests/test_memory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from datetime import datetime

import pytest
from autogen_core import CancellationToken
from autogen_core.memory import (
Expand All @@ -16,7 +14,6 @@
def test_memory_protocol_attributes() -> None:
"""Test that Memory protocol has all required attributes."""
# No changes needed here
assert hasattr(Memory, "name")
assert hasattr(Memory, "update_context")
assert hasattr(Memory, "query")
assert hasattr(Memory, "add")
Expand Down Expand Up @@ -76,8 +73,8 @@ async def test_list_memory_add_and_query() -> None:
"""Test adding and querying memory contents."""
memory = ListMemory()

content1 = MemoryContent(content="test1", mime_type=MemoryMimeType.TEXT, timestamp=datetime.now())
content2 = MemoryContent(content={"key": "value"}, mime_type=MemoryMimeType.JSON, timestamp=datetime.now())
content1 = MemoryContent(content="test1", mime_type=MemoryMimeType.TEXT)
content2 = MemoryContent(content={"key": "value"}, mime_type=MemoryMimeType.JSON)

await memory.add(content1)
await memory.add(content2)
Expand Down
2 changes: 2 additions & 0 deletions python/packages/autogen-ext/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ file-surfer = [
"autogen-agentchat==0.4.1",
"markitdown>=0.0.1a2",
]
graphrag = ["graphrag>=1.0.1"]
web-surfer = [
"autogen-agentchat==0.4.1",
"playwright>=1.48.0",
Expand Down Expand Up @@ -57,6 +58,7 @@ packages = ["src/autogen_ext"]
dev = [
"autogen_test_utils",
"langchain-experimental",
"pandas-stubs>=2.2.3.241126",
]

[tool.ruff]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@
Image,
MessageHandlerContext,
)
from autogen_core.models import FinishReasons
from autogen_core.logging import LLMCallEvent
from autogen_core.models import (
AssistantMessage,
ChatCompletionClient,
ChatCompletionTokenLogprob,
CreateResult,
FinishReasons,
FunctionExecutionResultMessage,
LLMMessage,
ModelCapabilities, # type: ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from ._config import (
GlobalContextConfig,
GlobalDataConfig,
LocalContextConfig,
LocalDataConfig,
MapReduceConfig,
SearchConfig,
)
from ._global_search import GlobalSearchTool, GlobalSearchToolArgs, GlobalSearchToolReturn
from ._local_search import LocalSearchTool, LocalSearchToolArgs, LocalSearchToolReturn

__all__ = [
"GlobalSearchTool",
"LocalSearchTool",
"GlobalDataConfig",
"LocalDataConfig",
"GlobalContextConfig",
"GlobalSearchToolArgs",
"GlobalSearchToolReturn",
"LocalContextConfig",
"LocalSearchToolArgs",
"LocalSearchToolReturn",
"MapReduceConfig",
"SearchConfig",
]
Loading

0 comments on commit b16e31c

Please sign in to comment.