-
Notifications
You must be signed in to change notification settings - Fork 77
Support configurable workflow gRPC payload limits for agents and orchestrators #250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+255
−0
Merged
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0a26918
feat(grpc): add workflow gRPC options model and helper
Cyb3rWard0g 2912cf2
refactor(components): plumb workflow gRPC options through bases
Cyb3rWard0g cd1ca40
feat(workflows): honor gRPC limits in durable agents & orchestrators
Cyb3rWard0g 389821d
test(grpc): cover durabletask channel patching helper
Cyb3rWard0g 1d3ccb1
Basic quickstart to show how to use the new config
Cyb3rWard0g 1097b9c
Make lint happy
Cyb3rWard0g c140ab4
refactor: Clarify gRPC options check to explicitly support setting ei…
Cyb3rWard0g ae03ee9
docs: Add reference to original durabletask get_grpc_channel implemen…
Cyb3rWard0g c18fa6f
fix: address merge conflict so we can merge
sicoyle 975d111
fix: rm extra quickstart used for testing
sicoyle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import logging | ||
| from typing import Optional, Sequence | ||
|
|
||
| from dapr_agents.agents.configs import WorkflowGrpcOptions | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def apply_grpc_options(options: Optional[WorkflowGrpcOptions]) -> None: | ||
| """ | ||
| Patch Durable Task's gRPC channel factory with custom message size limits. | ||
|
|
||
| Durable Task (and therefore Dapr Workflows) creates its gRPC channels via | ||
| ``durabletask.internal.shared.get_grpc_channel``. This helper monkey patches | ||
| that factory so that subsequent runtime/client instances honour the provided | ||
| ``grpc.max_send_message_length`` / ``grpc.max_receive_message_length`` values. | ||
| """ | ||
| if not options: | ||
| return | ||
| if not options.max_send_message_length and not options.max_receive_message_length: | ||
sicoyle marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return | ||
|
|
||
| try: | ||
| import grpc | ||
| from durabletask.internal import shared | ||
| except ImportError as exc: | ||
| logger.error( | ||
| "Failed to import grpc/durabletask for channel configuration: %s", exc | ||
| ) | ||
| raise | ||
|
|
||
| grpc_options = [] | ||
| if options.max_send_message_length: | ||
| grpc_options.append( | ||
| ("grpc.max_send_message_length", options.max_send_message_length) | ||
| ) | ||
| if options.max_receive_message_length: | ||
| grpc_options.append( | ||
| ("grpc.max_receive_message_length", options.max_receive_message_length) | ||
| ) | ||
|
|
||
| if not grpc_options: | ||
| return | ||
|
|
||
| def get_grpc_channel_with_options( | ||
| host_address: Optional[str], | ||
| secure_channel: bool = False, | ||
| interceptors: Optional[Sequence["grpc.ClientInterceptor"]] = None, | ||
| ): | ||
| if host_address is None: | ||
| host_address = shared.get_default_host_address() | ||
|
|
||
| for protocol in getattr(shared, "SECURE_PROTOCOLS", []): | ||
| if host_address.lower().startswith(protocol): | ||
| secure_channel = True | ||
| host_address = host_address[len(protocol) :] | ||
| break | ||
|
|
||
| for protocol in getattr(shared, "INSECURE_PROTOCOLS", []): | ||
| if host_address.lower().startswith(protocol): | ||
| secure_channel = False | ||
| host_address = host_address[len(protocol) :] | ||
| break | ||
|
|
||
| if secure_channel: | ||
| credentials = grpc.ssl_channel_credentials() | ||
| channel = grpc.secure_channel( | ||
| host_address, credentials, options=grpc_options | ||
| ) | ||
| else: | ||
| channel = grpc.insecure_channel(host_address, options=grpc_options) | ||
|
|
||
| if interceptors: | ||
| channel = grpc.intercept_channel(channel, *interceptors) | ||
|
|
||
| return channel | ||
|
|
||
| shared.get_grpc_channel = get_grpc_channel_with_options | ||
| logger.debug( | ||
| "Applied gRPC options to durabletask channel factory: %s", dict(grpc_options) | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # DurableAgent with custom gRPC limits | ||
Cyb3rWard0g marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Prerequisites | ||
|
|
||
| - Python 3.10+ | ||
| - Dapr CLI & Docker | ||
| - OpenAI-compatible API key (for the `llm_activity` decorators) | ||
|
|
||
| ## Setup | ||
|
|
||
| Install dependencies in your virtual environment (see repository root instructions) and ensure Dapr is initialised: | ||
|
|
||
| ```bash | ||
| dapr init | ||
| ``` | ||
|
|
||
| Provide your OpenAI key via `.env` or by editing `components/openai.yaml`, identical to the earlier quickstart. | ||
|
|
||
| This variant mirrors **10-test-durable-agent** but demonstrates how to raise the | ||
| workflow gRPC message size limits (defaults are ~4 MB). The app configures | ||
| `WorkflowGrpcOptions` with 32 MB send/receive ceilings before the workflow runtime | ||
| starts, which you should see logged when the service boots. | ||
|
|
||
| ## Run the app | ||
|
|
||
| ```bash | ||
| # Terminal 1 – run the workflow app | ||
| dapr run \ | ||
| --app-id blog-app-agent \ | ||
| --resources-path ./components \ | ||
| -- python app.py | ||
|
|
||
| # Terminal 2 – publish a message to start the workflow | ||
| dapr run \ | ||
| --app-id blog-app-client \ | ||
| --resources-path ./components \ | ||
| -- python message_client.py | ||
| ``` | ||
|
|
||
| You should see the workflow start, log the gRPC override, and print the generated | ||
| blog post in the app logs. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.