Skip to content

Commit

Permalink
Update package versions
Browse files Browse the repository at this point in the history
  • Loading branch information
jackgerrits committed Sep 30, 2024
1 parent 6cfa29b commit af2b5fa
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 204 deletions.
6 changes: 3 additions & 3 deletions python/packages/autogen-agentchat/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "autogen-agentchat"
version = "0.3.0dev0"
version = "0.4.0dev0"
description = "AutoGen agent and group chat library"
readme = "README.md"
requires-python = ">=3.10"
Expand All @@ -13,8 +13,8 @@ classifiers = [
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies = ["autogen-core",

dependencies = [
"autogen-core==0.4.0dev0",
]

[tool.uv]
Expand Down
16 changes: 6 additions & 10 deletions python/packages/autogen-core/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,9 @@ Task driven, high level APIs for building multi-agent systems. Including group c
Built with <i>core</i>.
<p>

<div class="highlight-sh notranslate"><div class="highlight"><pre id="codecell1" tabindex="-1">
<a href="packages/index.html#pkg-info-autogen-agentchat">Installation instructions</a>
</pre>
</div>
</div>
```sh
pip install autogen-agentchat==0.4.0dev0
```

<button onclick="location.href='agentchat-user-guide/guides/quickstart.html'" type="button" class="btn btn-primary">Get Started</button>
<button onclick="location.href='reference/python/autogen_agentchat/autogen_agentchat.html'" type="button" class="btn btn-outline-secondary">API Reference</button>
Expand All @@ -71,11 +69,9 @@ Built with <i>core</i>.
Primitive building blocks for creating asynchronous, event driven multi-agent systems.
<p>

<div class="highlight-sh notranslate"><div class="highlight"><pre id="codecell1" tabindex="-1">
<a href="packages/index.html#pkg-info-autogen-core">Installation instructions</a>
</pre>
</div>
</div>
```sh
pip install autogen-core==0.4.0dev0
```

<button onclick="location.href='core-user-guide/guides/quickstart.html'" type="button" class="btn btn-primary">Get Started</button>
<button onclick="location.href='reference/python/autogen_core/autogen_core.html'" type="button" class="btn btn-outline-secondary">API Reference</button>
Expand Down
12 changes: 4 additions & 8 deletions python/packages/autogen-core/docs/src/packages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ myst:
Library that is at a similar level of abstraction as AutoGen 0.2, including default agents and group chat.

```sh
pip install git+https://github.com/microsoft/autogen.git#subdirectory=python/packages/autogen-core
pip install git+https://github.com/microsoft/autogen.git#subdirectory=python/packages/autogen-ext
pip install git+https://github.com/microsoft/autogen.git#subdirectory=python/packages/autogen-agentchat
pip install autogen-agentchat==0.4.0dev0
```

```{note}
Expand All @@ -48,7 +46,7 @@ This package is a work in progress, it will be available on PyPI when it is read
Implements the core functionality of the AutoGen framework, providing basic building blocks for creating multi-agent systems.

```sh
pip install git+https://github.com/microsoft/autogen.git#subdirectory=python/packages/autogen-core
pip install autogen-core==0.4.0dev0
```

```{note}
Expand All @@ -65,8 +63,7 @@ This package is a work in progress, it will be available on PyPI when it is read
Implementations of core components that interface with external services, or use extra dependencies. For example, Docker based code execution.

```sh
pip install git+https://github.com/microsoft/autogen.git#subdirectory=python/packages/autogen-core
pip install git+https://github.com/microsoft/autogen.git#subdirectory=python/packages/autogen-ext
pip install autogen-ext==0.4.0dev0
```

```{note}
Expand All @@ -84,8 +81,7 @@ This package is a work in progress, it will be available on PyPI when it is read
A generalist multi-agent softbot utilizing five agents to tackle intricate tasks involving multi-step planning and real-world actions.

```sh
pip install git+https://github.com/microsoft/autogen.git#subdirectory=python/packages/autogen-core
pip install git+https://github.com/microsoft/autogen.git#subdirectory=python/packages/autogen-team-one
pip install autogen-team-one==0.1.0dev0
```

```{note}
Expand Down
2 changes: 1 addition & 1 deletion python/packages/autogen-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "autogen-core"
version = "0.3.dev0"
version = "0.4.0dev0"
description = "Foundational interfaces and agent runtime implementation for AutoGen"
readme = "README.md"
requires-python = ">=3.10"
Expand Down
4 changes: 2 additions & 2 deletions python/packages/autogen-ext/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "autogen-ext"
version = "0.3.0dev0"
version = "0.4.0dev0"
description = "AutoGen extensions library"
readme = "README.md"
requires-python = ">=3.10"
Expand All @@ -14,7 +14,7 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"autogen-core",
"autogen-core==0.4.0dev0",
]


Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from ._langchain_adapter import LangChainToolAdapter

__all__ = ["LangChainToolAdapter"]
from ._langchain_adapter import LangChainToolAdapter

__all__ = ["LangChainToolAdapter"]
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
import asyncio
import inspect
from typing import Any, Callable, Dict, Tuple, Type, cast

from autogen_core.base import CancellationToken
from autogen_core.components.tools import BaseTool
from pydantic import BaseModel, Field, create_model
from pydantic.fields import FieldInfo

from langchain.tools import Tool as LangChainTool

FieldDefinition = Tuple[Type[Any], FieldInfo]
FieldsDict = Dict[str, FieldDefinition]


class LangChainToolAdapter(BaseTool[BaseModel, Any]):
langchain_tool: LangChainTool
_callable: Callable[..., Any]

def __init__(self, langchain_tool: LangChainTool):
self.langchain_tool = langchain_tool

# Extract name and description
name = langchain_tool.name
description = langchain_tool.description or ""

# Determine the callable method
if hasattr(langchain_tool, "func") and callable(langchain_tool.func):
assert langchain_tool.func is not None
self._callable = langchain_tool.func
elif hasattr(langchain_tool, "_run") and callable(langchain_tool._run): # pyright: ignore
self._callable = langchain_tool._run # type: ignore
else:
raise AttributeError(
f"The provided LangChain tool '{name}' does not have a callable 'func' or '_run' method."
)

# Determine args_type
if langchain_tool.args_schema: # pyright: ignore
args_type = langchain_tool.args_schema # pyright: ignore
else:
# Infer args_type from the callable's signature
sig = inspect.signature(cast(Callable[..., Any], self._callable))
fields = {
k: (v.annotation, Field(...))
for k, v in sig.parameters.items()
if k != "self" and v.kind not in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD)
}
args_type = create_model(f"{name}Args", **fields) # type: ignore
# Note: type ignore is used due to a LangChain typing limitation

# Ensure args_type is a subclass of BaseModel
if not issubclass(args_type, BaseModel):
raise ValueError(f"Failed to create a valid Pydantic v2 model for {name}")

# Assume return_type as Any if not specified
return_type: Type[Any] = object

super().__init__(args_type, return_type, name, description)

async def run(self, args: BaseModel, cancellation_token: CancellationToken) -> Any:
# Prepare arguments
kwargs = args.model_dump()

# Determine if the callable is asynchronous
if inspect.iscoroutinefunction(self._callable):
result = await self._callable(**kwargs)
else:
# Run in a thread to avoid blocking the event loop
result = await asyncio.to_thread(self._call_sync, kwargs)

return result

def _call_sync(self, kwargs: Dict[str, Any]) -> Any:
return self._callable(**kwargs)
import asyncio
import inspect
from typing import Any, Callable, Dict, Tuple, Type, cast

from autogen_core.base import CancellationToken
from autogen_core.components.tools import BaseTool
from pydantic import BaseModel, Field, create_model
from pydantic.fields import FieldInfo

from langchain.tools import Tool as LangChainTool

FieldDefinition = Tuple[Type[Any], FieldInfo]
FieldsDict = Dict[str, FieldDefinition]


class LangChainToolAdapter(BaseTool[BaseModel, Any]):
langchain_tool: LangChainTool
_callable: Callable[..., Any]

def __init__(self, langchain_tool: LangChainTool):
self.langchain_tool = langchain_tool

# Extract name and description
name = langchain_tool.name
description = langchain_tool.description or ""

# Determine the callable method
if hasattr(langchain_tool, "func") and callable(langchain_tool.func):
assert langchain_tool.func is not None
self._callable = langchain_tool.func
elif hasattr(langchain_tool, "_run") and callable(langchain_tool._run): # pyright: ignore
self._callable = langchain_tool._run # type: ignore
else:
raise AttributeError(
f"The provided LangChain tool '{name}' does not have a callable 'func' or '_run' method."
)

# Determine args_type
if langchain_tool.args_schema: # pyright: ignore
args_type = langchain_tool.args_schema # pyright: ignore
else:
# Infer args_type from the callable's signature
sig = inspect.signature(cast(Callable[..., Any], self._callable))
fields = {
k: (v.annotation, Field(...))
for k, v in sig.parameters.items()
if k != "self" and v.kind not in (inspect.Parameter.VAR_POSITIONAL, inspect.Parameter.VAR_KEYWORD)
}
args_type = create_model(f"{name}Args", **fields) # type: ignore
# Note: type ignore is used due to a LangChain typing limitation

# Ensure args_type is a subclass of BaseModel
if not issubclass(args_type, BaseModel):
raise ValueError(f"Failed to create a valid Pydantic v2 model for {name}")

# Assume return_type as Any if not specified
return_type: Type[Any] = object

super().__init__(args_type, return_type, name, description)

async def run(self, args: BaseModel, cancellation_token: CancellationToken) -> Any:
# Prepare arguments
kwargs = args.model_dump()

# Determine if the callable is asynchronous
if inspect.iscoroutinefunction(self._callable):
result = await self._callable(**kwargs)
else:
# Run in a thread to avoid blocking the event loop
result = await asyncio.to_thread(self._call_sync, kwargs)

return result

def _call_sync(self, kwargs: Dict[str, Any]) -> Any:
return self._callable(**kwargs)
Loading

0 comments on commit af2b5fa

Please sign in to comment.