-
Notifications
You must be signed in to change notification settings - Fork 930
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
feat(agents-api): Add temporal workflow lookup relation and queries #446
Merged
whiterabbit1983
merged 4 commits into
dev-tasks-disable-routes
from
x/execution-endpoints
Aug 5, 2024
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
There are no files selected for viewing
This file contains 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 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 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
71 changes: 71 additions & 0 deletions
71
agents-api/agents_api/models/execution/get_paused_execution_token.py
This file contains 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,71 @@ | ||
from uuid import UUID | ||
|
||
from beartype import beartype | ||
from fastapi import HTTPException | ||
from pycozo.client import QueryException | ||
from pydantic import ValidationError | ||
|
||
from ...autogen.openapi_model import Transition | ||
from ..utils import ( | ||
cozo_query, | ||
partialclass, | ||
rewrap_exceptions, | ||
verify_developer_id_query, | ||
wrap_in_class, | ||
) | ||
|
||
|
||
@rewrap_exceptions( | ||
{ | ||
QueryException: partialclass(HTTPException, status_code=400), | ||
ValidationError: partialclass(HTTPException, status_code=400), | ||
TypeError: partialclass(HTTPException, status_code=400), | ||
AssertionError: partialclass(HTTPException, status_code=500), | ||
} | ||
) | ||
@wrap_in_class(dict, one=True) | ||
@cozo_query | ||
@beartype | ||
def get_paused_execution_token( | ||
*, | ||
developer_id: UUID, | ||
execution_id: UUID, | ||
) -> tuple[list[str], dict]: | ||
execution_id = str(execution_id) | ||
|
||
check_status_query = """ | ||
?[execution_id, status] := | ||
*executions { | ||
execution_id, | ||
status, | ||
}, | ||
execution_id = to_uuid($execution_id), | ||
status = "awaiting_input" | ||
|
||
:assert some | ||
""" | ||
|
||
get_query = """ | ||
?[task_token, max(created_at)] := | ||
execution_id = to_uuid($execution_id), | ||
*executions { | ||
execution_id, | ||
}, | ||
*transitions { | ||
execution_id, | ||
created_at, | ||
task_token, | ||
type, | ||
}, | ||
type = "wait" | ||
|
||
""" | ||
|
||
get_query += filter | ||
|
||
queries = [ | ||
verify_developer_id_query(developer_id), | ||
get_query, | ||
] | ||
|
||
return (queries, {"execution_id": execution_id}) |
51 changes: 51 additions & 0 deletions
51
agents-api/agents_api/models/execution/get_temporal_workflow_data.py
This file contains 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,51 @@ | ||
from uuid import UUID | ||
|
||
from beartype import beartype | ||
from fastapi import HTTPException | ||
from pycozo.client import QueryException | ||
from pydantic import ValidationError | ||
|
||
from ..utils import ( | ||
cozo_query, | ||
partialclass, | ||
rewrap_exceptions, | ||
wrap_in_class, | ||
) | ||
|
||
|
||
@rewrap_exceptions( | ||
{ | ||
QueryException: partialclass(HTTPException, status_code=400), | ||
ValidationError: partialclass(HTTPException, status_code=400), | ||
TypeError: partialclass(HTTPException, status_code=400), | ||
} | ||
) | ||
@wrap_in_class(dict, one=True) | ||
@cozo_query | ||
@beartype | ||
def get_temporal_workflow_data( | ||
*, | ||
execution_id: UUID, | ||
) -> tuple[str, dict]: | ||
# Executions are allowed direct GET access if they have execution_id | ||
|
||
query = """ | ||
input[execution_id] <- [[to_uuid($execution_id)]] | ||
|
||
?[id, run_id, result_run_id, first_execution_run_id] := | ||
input[execution_id], | ||
*temporal_executions_lookup { | ||
execution_id, | ||
id, | ||
run_id, | ||
result_run_id, | ||
first_execution_run_id, | ||
} | ||
""" | ||
|
||
return ( | ||
query, | ||
{ | ||
"execution_id": str(execution_id), | ||
}, | ||
) |
This file contains 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 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
40 changes: 40 additions & 0 deletions
40
agents-api/migrations/migrate_1722875101_add_temporal_mapping.py
This file contains 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,40 @@ | ||
# /usr/bin/env python3 | ||
|
||
MIGRATION_ID = "add_temporal_mapping" | ||
CREATED_AT = 1722875101.262791 | ||
|
||
|
||
def run(client, queries): | ||
joiner = "}\n\n{" | ||
|
||
query = joiner.join(queries) | ||
query = f"{{\n{query}\n}}" | ||
client.run(query) | ||
|
||
|
||
create_temporal_executions_lookup = dict( | ||
up=""" | ||
:create temporal_executions_lookup { | ||
execution_id: Uuid, | ||
id: String, | ||
=> | ||
run_id: String?, | ||
first_execution_run_id: String?, | ||
result_run_id: String?, | ||
created_at: Float default now(), | ||
} | ||
""", | ||
down="::remove temporal_executions_lookup", | ||
) | ||
|
||
queries = [ | ||
create_temporal_executions_lookup, | ||
] | ||
|
||
|
||
def up(client): | ||
run(client, [q["up"] for q in queries]) | ||
|
||
|
||
def down(client): | ||
run(client, [q["down"] for q in reversed(queries)]) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable
filter
is used here but it is not defined anywhere in this file. This will cause aNameError
at runtime.