Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 45
Adding Store and cleaning Trigger APIs and Create State APIs#331
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
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
12b2576
Refactor state management and enhance graph execution capabilities
NiveditJain 32feb67
Refactor validation and input handling in state management models
NiveditJain 815921a
Fix error message formatting in trigger_graph function
NiveditJain de3f590
Refactor dependency validation in GraphTemplate model
NiveditJain 5248a80
Refactor secrets validation in GraphTemplate model
NiveditJain 43d6108
Remove deprecated create_states functionality and update tests
NiveditJain cd526ba
fixed ruff
NiveditJain 957cae2
fixed all failing tests
NiveditJain a376538
updated sdk
NiveditJain b6c2ccc
Enhance graph execution with beta store support
NiveditJain 438689b
Add comprehensive tests for StateManager and Runtime functionality
NiveditJain 942e854
Add warning filters for coroutine and unraisable exceptions in tests
NiveditJain 8695081
Remove unused asyncio import from comprehensive StateManager tests
NiveditJain 9ade70b
Add tests for get_store_value function in create_next_states
NiveditJain 089a806
Update README and StateManager for Graph Store enhancements
NiveditJain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| version = "0.0.2b2" | ||
| version = "0.0.2b3" |
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 |
|---|---|---|
| @@ -67,60 +67,49 @@ def _get_upsert_graph_endpoint(self, graph_name: str): | ||
| def _get_get_graph_endpoint(self, graph_name: str): | ||
| return f"{self._state_manager_uri}/{self._state_manager_version}/namespace/{self._namespace}/graph/{graph_name}" | ||
| async def trigger(self, graph_name: str, state: TriggerState | None = None, states: list[TriggerState] | None = None): | ||
| async def trigger(self, graph_name: str, inputs: dict[str, str] | None = None, store: dict[str, str] | None = None): | ||
| """ | ||
| Trigger a graph execution with one or more trigger states. | ||
| Trigger execution of a graph. | ||
| This method sends trigger states to the specified graph endpoint to initiate | ||
| graph execution. It accepts either a single trigger state or a list of trigger | ||
| states, but not both simultaneously. | ||
| Beta: This method now supports an optional **store** parameter that lets you | ||
| pass a key-value map that is persisted for the lifetime of the graph run. All | ||
| keys **and** values must be strings in the current beta release – the schema | ||
| may change in future versions. | ||
| Args: | ||
| graph_name (str): The name of the graph to trigger execution for. | ||
| state (TriggerState | None, optional): A single trigger state to send. | ||
| Must be provided if `states` is None. | ||
| states (list[TriggerState] | None, optional): A list of trigger states to send. | ||
| Must be provided if `state` is None. Cannot be an empty list. | ||
| graph_name (str): Name of the graph you want to run. | ||
| inputs (dict[str, str] | None): Optional inputs for the first node in the | ||
| graph. Strings only. | ||
| store (dict[str, str] | None): Optional key-value store that will be merged | ||
| into the graph-level store before execution (beta). | ||
| Returns: | ||
| dict: The JSON response from the state manager API containing the | ||
| result of the trigger operation. | ||
| dict: JSON payload returned by the state-manager API. | ||
| Raises: | ||
| ValueError: If neither `state` nor `states` is provided, if both are provided, | ||
| or if `states` is an empty list. | ||
| Exception: If the API request fails with a non-200 status code. The exception | ||
| message includes the HTTP status code and response text for debugging. | ||
| Exception: If the request fails. | ||
| Example: | ||
| ```python | ||
| # Trigger with a single state | ||
| state = TriggerState(identifier="my-trigger", inputs={"key": "value"}) | ||
| result = await state_manager.trigger("my-graph", state=state) | ||
| # Trigger with multiple states | ||
| states = [ | ||
| TriggerState(identifier="trigger1", inputs={"key1": "value1"}), | ||
| TriggerState(identifier="trigger2", inputs={"key2": "value2"}) | ||
| ] | ||
| result = await state_manager.trigger("my-graph", states=states) | ||
| # Trigger with inputs only | ||
| await state_manager.trigger("my-graph", inputs={"user_id": "123"}) | ||
| # Trigger with inputs **and** a beta store | ||
| await state_manager.trigger( | ||
| "my-graph", | ||
| inputs={"user_id": "123"}, | ||
| store={"cursor": "0"} # beta | ||
| ) | ||
| ``` | ||
| """ | ||
| if state is None and states is None: | ||
| raise ValueError("Either state or states must be provided") | ||
| if state is not None and states is not None: | ||
| raise ValueError("Only one of state or states must be provided") | ||
| if states is not None and len(states) == 0: | ||
| raise ValueError("States must be a non-empty list") | ||
| if inputs is None: | ||
| inputs = {} | ||
| if store is None: | ||
| store = {} | ||
| states_list = [] | ||
| if state is not None: | ||
| states_list.append(state) | ||
| if states is not None: | ||
| states_list.extend(states) | ||
| body = { | ||
| "states": [state.model_dump() for state in states_list] | ||
| "inputs": inputs, | ||
| "store": store | ||
| } | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| headers = { | ||
| "x-api-key": self._key | ||
| @@ -167,35 +156,32 @@ async def get_graph(self, graph_name: str): | ||
| raise Exception(f"Failed to get graph: {response.status} {await response.text()}") | ||
| return await response.json() | ||
| async def upsert_graph(self, graph_name: str, graph_nodes: list[dict[str, Any]], secrets: dict[str, str], validation_timeout: int = 60, polling_interval: int = 1): | ||
| async def upsert_graph(self, graph_name: str, graph_nodes: list[dict[str, Any]], secrets: dict[str, str], retry_policy: dict[str, Any] | None = None, store_config: dict[str, Any] | None = None, validation_timeout: int = 60, polling_interval: int = 1): | ||
| """ | ||
| Create or update a graph in the state manager with validation. | ||
| Create or update a graph definition. | ||
| Beta: `store_config` is a new field that allows you to configure a | ||
| namespaced key-value store that lives for the duration of a graph run. The | ||
| feature is in beta and the shape of `store_config` may change. | ||
| This method sends a graph definition to the state manager API for creation | ||
| or update. After submission, it polls the API to wait for graph validation | ||
| to complete, ensuring the graph is properly configured before returning. | ||
| After submitting the graph, this helper polls the state-manager until the | ||
| graph has been validated (or the timeout is hit). | ||
| Args: | ||
| graph_name (str): The name of the graph to create or update. | ||
| graph_nodes (list[dict[str, Any]]): A list of node definitions that make up | ||
| the graph. Each node should contain the necessary configuration for | ||
| the graph execution engine. | ||
| secrets (dict[str, str]): A dictionary of secret values that will be | ||
| available to the graph during execution. Keys are secret names and | ||
| values are the secret values. | ||
| validation_timeout (int, optional): Maximum time in seconds to wait for | ||
| graph validation to complete. Defaults to 60. | ||
| polling_interval (int, optional): Time in seconds between validation | ||
| status checks. Defaults to 1. | ||
| graph_name (str): Graph identifier. | ||
| graph_nodes (list[dict[str, Any]]): Graph node list. | ||
| secrets (dict[str, str]): Secrets available to all nodes. | ||
| retry_policy (dict[str, Any] | None): Optional per-node retry policy. | ||
| store_config (dict[str, Any] | None): Beta configuration for the | ||
| graph-level store (schema is subject to change). | ||
| validation_timeout (int): Seconds to wait for validation (default 60). | ||
| polling_interval (int): Polling interval in seconds (default 1). | ||
| Returns: | ||
| dict: The JSON response from the state manager API containing the | ||
| validated graph information. | ||
| dict: Validated graph object returned by the API. | ||
| Raises: | ||
| Exception: If the API request fails with a non-201 status code, if graph | ||
| validation times out, or if validation fails. The exception message | ||
| includes relevant error details for debugging. | ||
| Exception: If validation fails or times out. | ||
| """ | ||
NiveditJain marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| endpoint = self._get_upsert_graph_endpoint(graph_name) | ||
| headers = { | ||
| @@ -205,6 +191,12 @@ async def upsert_graph(self, graph_name: str, graph_nodes: list[dict[str, Any]], | ||
| "secrets": secrets, | ||
| "nodes": graph_nodes | ||
| } | ||
| if retry_policy is not None: | ||
| body["retry_policy"] = retry_policy | ||
| if store_config is not None: | ||
| body["store_config"] = store_config | ||
| async with aiohttp.ClientSession() as session: | ||
| async with session.put(endpoint, json=body, headers=headers) as response: # type: ignore | ||
| if response.status not in [200, 201]: | ||
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.