Skip to content
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

[SYNPY-1544] Synapse Agent OOP Model #1152

Draft
wants to merge 23 commits into
base: develop
Choose a base branch
from

Conversation

BWMac
Copy link
Contributor

@BWMac BWMac commented Jan 8, 2025

@pep8speaks
Copy link

pep8speaks commented Jan 8, 2025

Hello @BWMac! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 80:89: E501 line too long (89 > 88 characters)
Line 161:89: E501 line too long (98 > 88 characters)
Line 162:89: E501 line too long (99 > 88 characters)

Line 132:89: E501 line too long (130 > 88 characters)
Line 135:89: E501 line too long (93 > 88 characters)
Line 137:89: E501 line too long (91 > 88 characters)
Line 141:89: E501 line too long (99 > 88 characters)
Line 147:89: E501 line too long (91 > 88 characters)
Line 281:89: E501 line too long (102 > 88 characters)
Line 306:89: E501 line too long (140 > 88 characters)
Line 358:89: E501 line too long (93 > 88 characters)
Line 403:89: E501 line too long (98 > 88 characters)
Line 414:89: E501 line too long (95 > 88 characters)
Line 418:89: E501 line too long (103 > 88 characters)
Line 436:89: E501 line too long (96 > 88 characters)
Line 442:89: E501 line too long (95 > 88 characters)
Line 462:89: E501 line too long (99 > 88 characters)
Line 481:89: E501 line too long (111 > 88 characters)
Line 482:89: E501 line too long (102 > 88 characters)

Line 94:89: E501 line too long (125 > 88 characters)
Line 95:89: E501 line too long (122 > 88 characters)
Line 110:89: E501 line too long (104 > 88 characters)
Line 112:89: E501 line too long (106 > 88 characters)
Line 139:89: E501 line too long (114 > 88 characters)
Line 143:89: E501 line too long (115 > 88 characters)
Line 227:89: E501 line too long (140 > 88 characters)
Line 264:89: E501 line too long (140 > 88 characters)
Line 298:89: E501 line too long (96 > 88 characters)
Line 317:89: E501 line too long (98 > 88 characters)

Line 20:89: E501 line too long (112 > 88 characters)
Line 31:89: E501 line too long (112 > 88 characters)
Line 42:89: E501 line too long (112 > 88 characters)
Line 56:89: E501 line too long (102 > 88 characters)
Line 57:89: E501 line too long (112 > 88 characters)
Line 70:89: E501 line too long (112 > 88 characters)
Line 81:89: E501 line too long (112 > 88 characters)
Line 95:89: E501 line too long (95 > 88 characters)
Line 98:89: E501 line too long (103 > 88 characters)
Line 100:89: E501 line too long (112 > 88 characters)
Line 111:89: E501 line too long (95 > 88 characters)
Line 140:89: E501 line too long (111 > 88 characters)
Line 141:89: E501 line too long (102 > 88 characters)
Line 142:89: E501 line too long (112 > 88 characters)

Line 65:15: E999 SyntaxError: invalid syntax
Line 128:89: E501 line too long (104 > 88 characters)
Line 141:89: E501 line too long (92 > 88 characters)
Line 146:89: E501 line too long (92 > 88 characters)

Comment last updated at 2025-01-16 14:57:29 UTC

@BWMac BWMac changed the title WIP [SYNPY-1544] Synapse Agent OOP Model [SYNPY-1544] Synapse Agent OOP Model Jan 8, 2025
start_time = asyncio.get_event_loop().time()
TIMEOUT = 60

while True:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def _waitForAsync(self, uri, request, endpoint=None):

This function exists on the client, but it not built with asyncio in mind. There is some additional error handling it does for the failed state. I could see an asyncio compliant version being written and used here.

Maybe it could go in this file? https://github.com/Sage-Bionetworks/synapsePythonClient/blob/8bd5e195c389e3a83bd1308be3c6a42f25d87b8f/synapseclient/core/async_utils.py

Copy link
Contributor Author

@BWMac BWMac Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_waitForAync does both the POST call (starting the job) and the GET call (retrieving the result). Should the functionality I have written here work that way too? I was viewing it as 1 function per API endpoint in agent_services originally.

I can still write a reusable async function for getting the response and handling incomplete and failed jobs, but just wondering what you think about division of responsibility there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They can be 2 separate functions that handle each part. In the Agent script you'll chain them together

"""
Enum representing the type of agent as defined in
<https://rest-docs.synapse.org/rest/org/sagebionetworks/repo/model/agent/AgentType.html>
'BASELINE' is a default agent provided by Synapse.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. Can be a list. Syntax is a empty newline before and each entry starts with -.

Might need to make sure it renders properly on my docs.

Related to ^
These will be "Less" experimental APIs, so we can add a new non-experimental section to

- API Reference:
for this. Not sure on the title, maybe "AI Agent" or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this should not be considered experimental? The API endpoints are brand new and could potentially change/be added to which may lead to updates in the OOP interface

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Throw it under there as a new section

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be its own section, or just fall under this one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a new entry under - Experimental: for this

agent_registration_id: The registration ID of the agent that will be used for this session.
etag: The etag of the agent session.
"""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out the tables refactor PR for examples of the syntax for an Examples section. I'd like for the docstring to have scripts (Copy/pastable) that folks could run and get started.

return self._return_rest_body(response)
except Exception:
self.logger.exception("Error in rest_get_async")
response = await self._rest_call_async(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error handling was preventing Synapse API errors from being surfaced to client users. All tests passed after making this change.

@@ -4,10 +4,9 @@

from synapseclient import Synapse
from synapseclient.core.exceptions import SynapseError
from synapseclient.models import Annotations

if TYPE_CHECKING:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was causing a circular import error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants