Update package versions

This commit is contained in:
Jack Gerrits 2024-09-30 19:43:05 -04:00
parent 6cfa29b018
commit af2b5faeef
10 changed files with 196 additions and 204 deletions

View File

@ -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"
@ -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]

View File

@ -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>
@ -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>

View File

@ -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}
@ -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}
@ -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}
@ -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}

View File

@ -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"

View File

@ -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"
@ -14,7 +14,7 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"autogen-core",
"autogen-core==0.4.0dev0",
]

View File

@ -1,3 +1,3 @@
from ._langchain_adapter import LangChainToolAdapter
__all__ = ["LangChainToolAdapter"]
from ._langchain_adapter import LangChainToolAdapter
__all__ = ["LangChainToolAdapter"]

View File

@ -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)

View File

@ -1,97 +1,97 @@
from typing import Optional, Type
import pytest
from autogen_core.base import CancellationToken
from autogen_ext.tools.langchain import LangChainToolAdapter # type: ignore
from langchain.tools import BaseTool as LangChainTool # type: ignore
from langchain.tools import tool # pyright: ignore
from langchain_core.callbacks.manager import AsyncCallbackManagerForToolRun, CallbackManagerForToolRun
from pydantic import BaseModel, Field
@tool # type: ignore
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
class CalculatorInput(BaseModel):
a: int = Field(description="first number")
b: int = Field(description="second number")
class CustomCalculatorTool(LangChainTool):
name: str = "Calculator"
description: str = "useful for when you need to answer questions about math"
args_schema: Type[BaseModel] = CalculatorInput
return_direct: bool = True
def _run(self, a: int, b: int, run_manager: Optional[CallbackManagerForToolRun] = None) -> int:
"""Use the tool."""
return a * b
async def _arun(
self,
a: int,
b: int,
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
) -> int:
"""Use the tool asynchronously."""
return self._run(a, b, run_manager=run_manager.get_sync() if run_manager else None)
@pytest.mark.asyncio
async def test_langchain_tool_adapter() -> None:
# Create a LangChain tool
langchain_tool = add # type: ignore
# Create an adapter
adapter = LangChainToolAdapter(langchain_tool) # pyright: ignore
# Test schema generation
schema = adapter.schema
assert schema["name"] == "add"
assert "description" in schema
assert schema["description"] == "Add two numbers"
assert "parameters" in schema
assert schema["parameters"]["type"] == "object"
assert "properties" in schema["parameters"]
assert "a" in schema["parameters"]["properties"]
assert "b" in schema["parameters"]["properties"]
assert schema["parameters"]["properties"]["a"]["type"] == "integer"
assert schema["parameters"]["properties"]["b"]["type"] == "integer"
assert "required" in schema["parameters"]
assert set(schema["parameters"]["required"]) == {"a", "b"}
assert len(schema["parameters"]["properties"]) == 2
# Test run method
result = await adapter.run_json({"a": 2, "b": 3}, CancellationToken())
assert result == 5
# Test that the adapter's run method can be called multiple times
result = await adapter.run_json({"a": 5, "b": 7}, CancellationToken())
assert result == 12
# Test CustomCalculatorTool
custom_langchain_tool = CustomCalculatorTool()
custom_adapter = LangChainToolAdapter(custom_langchain_tool) # pyright: ignore
# Test schema generation for CustomCalculatorTool
custom_schema = custom_adapter.schema
assert custom_schema["name"] == "Calculator"
assert custom_schema["description"] == "useful for when you need to answer questions about math" # type: ignore
assert "parameters" in custom_schema
assert custom_schema["parameters"]["type"] == "object"
assert "properties" in custom_schema["parameters"]
assert "a" in custom_schema["parameters"]["properties"]
assert "b" in custom_schema["parameters"]["properties"]
assert custom_schema["parameters"]["properties"]["a"]["type"] == "integer"
assert custom_schema["parameters"]["properties"]["b"]["type"] == "integer"
assert "required" in custom_schema["parameters"]
assert set(custom_schema["parameters"]["required"]) == {"a", "b"}
# Test run method for CustomCalculatorTool
custom_result = await custom_adapter.run_json({"a": 3, "b": 4}, CancellationToken())
assert custom_result == 12
from typing import Optional, Type
import pytest
from autogen_core.base import CancellationToken
from autogen_ext.tools.langchain import LangChainToolAdapter # type: ignore
from langchain.tools import BaseTool as LangChainTool # type: ignore
from langchain.tools import tool # pyright: ignore
from langchain_core.callbacks.manager import AsyncCallbackManagerForToolRun, CallbackManagerForToolRun
from pydantic import BaseModel, Field
@tool # type: ignore
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
class CalculatorInput(BaseModel):
a: int = Field(description="first number")
b: int = Field(description="second number")
class CustomCalculatorTool(LangChainTool):
name: str = "Calculator"
description: str = "useful for when you need to answer questions about math"
args_schema: Type[BaseModel] = CalculatorInput
return_direct: bool = True
def _run(self, a: int, b: int, run_manager: Optional[CallbackManagerForToolRun] = None) -> int:
"""Use the tool."""
return a * b
async def _arun(
self,
a: int,
b: int,
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
) -> int:
"""Use the tool asynchronously."""
return self._run(a, b, run_manager=run_manager.get_sync() if run_manager else None)
@pytest.mark.asyncio
async def test_langchain_tool_adapter() -> None:
# Create a LangChain tool
langchain_tool = add # type: ignore
# Create an adapter
adapter = LangChainToolAdapter(langchain_tool) # pyright: ignore
# Test schema generation
schema = adapter.schema
assert schema["name"] == "add"
assert "description" in schema
assert schema["description"] == "Add two numbers"
assert "parameters" in schema
assert schema["parameters"]["type"] == "object"
assert "properties" in schema["parameters"]
assert "a" in schema["parameters"]["properties"]
assert "b" in schema["parameters"]["properties"]
assert schema["parameters"]["properties"]["a"]["type"] == "integer"
assert schema["parameters"]["properties"]["b"]["type"] == "integer"
assert "required" in schema["parameters"]
assert set(schema["parameters"]["required"]) == {"a", "b"}
assert len(schema["parameters"]["properties"]) == 2
# Test run method
result = await adapter.run_json({"a": 2, "b": 3}, CancellationToken())
assert result == 5
# Test that the adapter's run method can be called multiple times
result = await adapter.run_json({"a": 5, "b": 7}, CancellationToken())
assert result == 12
# Test CustomCalculatorTool
custom_langchain_tool = CustomCalculatorTool()
custom_adapter = LangChainToolAdapter(custom_langchain_tool) # pyright: ignore
# Test schema generation for CustomCalculatorTool
custom_schema = custom_adapter.schema
assert custom_schema["name"] == "Calculator"
assert custom_schema["description"] == "useful for when you need to answer questions about math" # type: ignore
assert "parameters" in custom_schema
assert custom_schema["parameters"]["type"] == "object"
assert "properties" in custom_schema["parameters"]
assert "a" in custom_schema["parameters"]["properties"]
assert "b" in custom_schema["parameters"]["properties"]
assert custom_schema["parameters"]["properties"]["a"]["type"] == "integer"
assert custom_schema["parameters"]["properties"]["b"]["type"] == "integer"
assert "required" in custom_schema["parameters"]
assert set(custom_schema["parameters"]["required"]) == {"a", "b"}
# Test run method for CustomCalculatorTool
custom_result = await custom_adapter.run_json({"a": 3, "b": 4}, CancellationToken())
assert custom_result == 12

View File

@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project]
name = "team-one"
version = "0.0.1"
version = "0.1.0dev0"
description = ''
readme = "readme.md"
requires-python = ">=3.10"

View File

@ -335,7 +335,7 @@ wheels = [
[[package]]
name = "autogen-agentchat"
version = "0.3.0.dev0"
version = "0.4.0.dev0"
source = { editable = "packages/autogen-agentchat" }
dependencies = [
{ name = "autogen-core" },
@ -346,7 +346,7 @@ requires-dist = [{ name = "autogen-core", editable = "packages/autogen-core" }]
[[package]]
name = "autogen-core"
version = "0.3.dev0"
version = "0.4.0.dev0"
source = { editable = "packages/autogen-core" }
dependencies = [
{ name = "aiohttp" },
@ -461,7 +461,7 @@ dev = [
[[package]]
name = "autogen-ext"
version = "0.3.0.dev0"
version = "0.4.0.dev0"
source = { editable = "packages/autogen-ext" }
dependencies = [
{ name = "autogen-core" },
@ -4534,7 +4534,7 @@ wheels = [
[[package]]
name = "team-one"
version = "0.0.1"
version = "0.1.0.dev0"
source = { editable = "packages/team-one" }
dependencies = [
{ name = "aiofiles" },