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

Open
wants to merge 41 commits into
base: develop
Choose a base branch
from

Conversation

BWMac
Copy link
Contributor

@BWMac BWMac commented Jan 8, 2025

Description:

This PR is the implementation of an OOP model for interacting with the new Synapse Agent API endpoints. The design for the model implementation can be found in Confluence.

The core implementation includes (from "bottom to top"):

  • synapseclient.api.agent_services:
    • Low-level functions for interacting with the API endpoints that are specific to using Synapse Agents.
  • synapseclient.models.AgentPrompt:
  • synapseclient.models.AgentSession:
    • a dataclass representing a chat session with a Synapse Agent.
    • Includes functionality for directly interacting with chat sessions with a Synapse Agent.
    • The AgentSession logic is used in the Agent class, and we will generally recommend that users utilize the Agent class as the primary interface.
    • Asynchronous and Synchronous interfaces are available.
  • synapseclient.models.Agent:
    • a dataclass representing a Synapse Agent you can interact with.
    • Includes functionality for registering a custom agent, starting sessions with agents, sending prompts and also managing more than one session at a time.
    • The basic use case includes one session at a time where a session started by a user (either explicitly or implicitly by just calling prompt) becomes the default for prompting, but examples for conducting more than one session at a time can be found in the POC script and class docstring.

Notes:

  • All needed unit and integration tests for synchronous and asynchronous implementations are included.
  • Example usage of the models can be found in the class docstrings and in the POC script included in the PR.
  • I took the opportunity to refactor the Experimental section of the documentation, breaking up each model into it's own markdown script which makes maintaining the docs for OOP models a little easier.

@pep8speaks

This comment was marked as outdated.

@BWMac BWMac changed the title WIP [SYNPY-1544] Synapse Agent OOP Model [SYNPY-1544] Synapse Agent OOP Model Jan 8, 2025
@@ -75,8 +75,29 @@ nav:
- Core: reference/core.md
- REST Apis: reference/rest_apis.md
- Experimental:
- Object-Orientated Models: reference/oop/models.md
- Async Object-Orientated Models: reference/oop/models_async.md
- Mixins:
Copy link
Member

Choose a reason for hiding this comment

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

This is really nice - thanks for this on the fly refactor

@BWMac BWMac marked this pull request as ready for review January 17, 2025 15:28
@BWMac BWMac requested a review from a team as a code owner January 17, 2025 15:28
"""Send the job to the Asynchronous Job service and wait for it to complete.
Arguments:
post_exchange_args: Additional arguments to pass to the request.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you update what I wrote here to be a little more verbose on how this is intended to be used? Maybe an example too?

Could you also update the language for the synapse_client docstring to match the other areas of the code?

f"Timeout waiting for query results: {time.time() - start_time} seconds"
)

return result
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we update this to return back the AsynchronousJobStatus instance instead of the raw result from the API call?

Returns:
A AsynchronousJobStatus object.
"""
self.state = async_job_status.get("jobState", None)
Copy link
Contributor

Choose a reason for hiding this comment

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

We'll need to instantiate a AsynchronousJobState object here

Comment on lines +18 to +22
- register
- get
- start_session
- get_session
- prompt
Copy link
Contributor

Choose a reason for hiding this comment

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

These functions are not showing on the doc site:
https://synapsepythonclient--1152.org.readthedocs.build/en/1152/reference/experimental/sync/agent/#synapseclient.models.Agent-functions

I think because it's missing inherited_members: true

Comment on lines +14 to +15
AGENT_AWS_ID = "QOTV3KQM1X"
AGENT_REGISTRATION_ID = "29"
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a comment what these map to

Comment on lines +96 to +100
await agent_session.update_async(synapse_client=self.syn)
# THEN I expect the access level to be updated
assert (
agent_session.access_level == AgentSessionAccessLevel.READ_YOUR_PRIVATE_DATA
)
Copy link
Contributor

Choose a reason for hiding this comment

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

A better verification of this is to make sure that the data was stored in Synapse. Consider if this silently failed and did not persist the data to Synapse. Your instance would have the updated attribute value, but the next time the session is retrieved it could be using the previous access level.

Perform a new read with a new instance after calling update_async and verify on that newly read instance that it contains the right access_level


def get_test_agent(self) -> Agent:
return Agent(
cloud_agent_id="QOTV3KQM1X",
Copy link
Contributor

Choose a reason for hiding this comment

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

You have the AGENT_AWS_ID constant available

Copy link
Contributor

@BryanFauble BryanFauble left a comment

Choose a reason for hiding this comment

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

Great work! See my comments and re-request a review when you're ready

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