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

Add persistent state directory to python agents #645

Merged
merged 8 commits into from
Oct 26, 2023
Merged

Conversation

nicoloboschi
Copy link
Member

@nicoloboschi nicoloboschi commented Oct 25, 2023

Changes:

  • Added new Python AgentContext class to the API
  • An agent can access it by defining
from langstream import SimpleRecord, Processor, AgentContext
import logging, os


class Exclamation(Processor):
    def init(self, config, context: AgentContext):
        self.context = context
    def process(self, record):
        directory = self.context.get_persistent_state_directory() 

if the agent declares init with only argument, it works as before

  • Added end to end test

Copy link
Member

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

I have left some feedback.

@cbornet please review as well


class Agent(ABC):
"""The Agent interface"""

def init(self, config: Dict[str, Any]):
def init(self, config: Dict[str, Any], context: AgentContext):
Copy link
Member

Choose a reason for hiding this comment

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

is this a breaking change ?

maybe we should have same approach as in Java and have a "setAgentContext" function

Copy link
Member Author

Choose a reason for hiding this comment

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

no it is not, I added a test for the old syntax

print("Missing gRPC target and python class name")
print("usage: python -m langstream_grpc <target> <config>")
sys.exit(1)

server = AgentServer(sys.argv[1], sys.argv[2])
context_config = {}
if len(sys.argv) > 3:
Copy link
Member

Choose a reason for hiding this comment

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

the process is always launched by the same version of the java runtime, there is no need to do this

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@eolivelli eolivelli requested a review from cbornet October 25, 2023 09:59
@nicoloboschi nicoloboschi marked this pull request as ready for review October 25, 2023 12:54
@cbornet
Copy link
Member

cbornet commented Oct 25, 2023

LGTM. Just some minor comments.
Congrats on the Python PR !

@nicoloboschi
Copy link
Member Author

LGTM. Just some minor comments. Congrats on the Python PR !

Thanks I addressed your comments

@nicoloboschi nicoloboschi merged commit c354025 into main Oct 26, 2023
10 checks passed
@nicoloboschi nicoloboschi deleted the disk-python branch October 26, 2023 06:54
benfrank241 pushed a commit to vectorize-io/langstream that referenced this pull request May 2, 2024
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.

3 participants