Skip to content

Commit

Permalink
Make grpc an optional dependency (#4315)
Browse files Browse the repository at this point in the history
* Make grpc an optional dependency

* add note to the runtime docs

* update version

---------

Co-authored-by: Eric Zhu <[email protected]>
  • Loading branch information
jackgerrits and ekzhu authored Nov 24, 2024
1 parent 02ef110 commit 01dc56b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
"It also advertises the agents which they support to the host service,\n",
"so the host service can deliver messages to the correct worker.\n",
"\n",
"````{note}\n",
"The distributed agent runtime requires extra dependencies, install them using:\n",
"```bash\n",
"pip install autogen-core[grpc]==0.4.0.dev6\n",
"```\n",
"````\n",
"\n",
"We can start a host service using {py:class}`~autogen_core.application.WorkerAgentRuntimeHost`."
]
},
Expand Down
6 changes: 5 additions & 1 deletion python/packages/autogen-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,18 @@ dependencies = [
"aiohttp",
"typing-extensions",
"pydantic<3.0.0,>=2.0.0",
"grpcio~=1.62.0",
"protobuf~=4.25.1",
"tiktoken",
"opentelemetry-api~=1.27.0",
"asyncio_atexit",
"jsonref~=1.1.0",
]

[project.optional-dependencies]
grpc = [
"grpcio~=1.62.0",
]

[tool.uv]
dev-dependencies = [
"aiofiles",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GRPC_IMPORT_ERROR_STR = (
"Distributed runtime features require additional dependencies. Install them with: pip install autogen-core[grpc]"
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,11 @@
cast,
)

import grpc
from grpc.aio import StreamStreamCall
from opentelemetry.trace import TracerProvider
from typing_extensions import Self, deprecated

from autogen_core.base import JSON_DATA_CONTENT_TYPE
from autogen_core.base._serialization import MessageSerializer, SerializationRegistry
from autogen_core.base._type_helpers import ChannelArgumentType

from ..base import (
JSON_DATA_CONTENT_TYPE,
Agent,
AgentId,
AgentInstantiationContext,
Expand All @@ -50,11 +45,19 @@
SubscriptionInstantiationContext,
TopicId,
)
from ..base._serialization import MessageSerializer, SerializationRegistry
from ..base._type_helpers import ChannelArgumentType
from ..components import TypeSubscription
from ._helpers import SubscriptionManager, get_impl
from ._utils import GRPC_IMPORT_ERROR_STR
from .protos import agent_worker_pb2, agent_worker_pb2_grpc
from .telemetry import MessageRuntimeTracingConfig, TraceHelper, get_telemetry_grpc_metadata

try:
import grpc.aio
except ImportError as e:
raise ImportError(GRPC_IMPORT_ERROR_STR) from e

if TYPE_CHECKING:
from .protos.agent_worker_pb2_grpc import AgentRpcAsyncStub

Expand Down Expand Up @@ -140,6 +143,8 @@ async def _connect( # type: ignore
) -> None:
stub: AgentRpcAsyncStub = agent_worker_pb2_grpc.AgentRpcStub(channel) # type: ignore

from grpc.aio import StreamStreamCall

# TODO: where do exceptions from reading the iterable go? How do we recover from those?
recv_stream: StreamStreamCall[agent_worker_pb2.Message, agent_worker_pb2.Message] = stub.OpenChannel( # type: ignore
QueueAsyncIterable(send_queue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import signal
from typing import Optional, Sequence

import grpc

from autogen_core.base._type_helpers import ChannelArgumentType

from ..base._type_helpers import ChannelArgumentType
from ._utils import GRPC_IMPORT_ERROR_STR
from ._worker_runtime_host_servicer import WorkerAgentRuntimeHostServicer

try:
import grpc
except ImportError as e:
raise ImportError(GRPC_IMPORT_ERROR_STR) from e
from .protos import agent_worker_pb2_grpc

logger = logging.getLogger("autogen_core")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
from asyncio import Future, Task
from typing import Any, Dict, Set

import grpc

from ..base import TopicId
from ..components import TypeSubscription
from ._helpers import SubscriptionManager
from ._utils import GRPC_IMPORT_ERROR_STR

try:
import grpc
except ImportError as e:
raise ImportError(GRPC_IMPORT_ERROR_STR) from e

from .protos import agent_worker_pb2, agent_worker_pb2_grpc

logger = logging.getLogger("autogen_core")
Expand Down
8 changes: 6 additions & 2 deletions python/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 01dc56b

Please sign in to comment.