Using sockets rather than print#1290
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1290 +/- ##
==========================================
+ Coverage 31.98% 41.92% +9.93%
==========================================
Files 33 34 +1
Lines 4415 4456 +41
Branches 1030 1095 +65
==========================================
+ Hits 1412 1868 +456
+ Misses 2887 2437 -450
- Partials 116 151 +35
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
This is a great addition. I am trying to get a good understanding of the design.
|
Thanks! I'm glad you're excited by it too. @ragyabraham please feel free to add. I think the fundamental difference to #1289 is that here, we're not trying to move the agent-to-agent message transmission to socket, nor have an Agent hosted elsewhere. If my understanding is correct
I think so, however, I'm not very familiar with hooks, and would need to work with you or @davorrunje to iterate on how to implement it properly through the reviews. If there's any tips anyone can share before we start developing, that might help reduce reviews/rework! :) |
Certainly! I am here to make sure us don't have to redo a lot of work. I am just thinking if #1240 go through first, it will be much easier for us to implement something like logging and emitting to a frontend. |
| use_agent_stream: Optional[bool] = False, | ||
| get_socket_client_function: Optional[Callable] = None, | ||
| sid: Optional[str] = None, |
There was a problem hiding this comment.
Add docstring for new arguments.
Consider choosing more descriptive name than sid?
| llm_config: Optional[Union[Dict, Literal[False]]] = None, | ||
| default_auto_reply: Optional[Union[str, Dict, None]] = "", | ||
| description: Optional[str] = None, | ||
| use_agent_stream: Optional[bool] = False, |
There was a problem hiding this comment.
I can easily imagine more than just two types of output stream because there are so many different ways to stream data on the internet. Why don't we define AgentOutput protocol for outputting data and implement two initial classes: PrintAgentOutput and SocketAgentOutput implementing the protocol? That way we would be extensible in future without being forced to change the ConversableClient class.
There was a problem hiding this comment.
In this approach, should we plan for mutually exclusive outputs or a list of outputs? E.g. both print and socket outputs happening.
|
|
||
| if self.use_agent_stream: | ||
| # Generate sid if None | ||
| if self.sid is None: |
There was a problem hiding this comment.
These implementation details can be refactored out to a separate delegate class to avoid bloating the ConversableAgent.
| ) | ||
|
|
||
| if use_agent_stream: | ||
| # Generate sid if None |
There was a problem hiding this comment.
Refactor out to delegate to avoid bloating
|
@ekzhu @victordibia |
|
@joshkyh no worries. I just unassigned you from the PR. |
|
@ekzhu can we have some simple example code for how to implement this on our own? |
| # Upper, digits. 5chars - 5chars - 5chars | ||
| candidates = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" | ||
| sid = "-".join( | ||
| [ |
There was a problem hiding this comment.
Why are we choosing random letters here? Could we just use uuid?
| sid = "-".join( | ||
| [ | ||
| "".join(random.choices(candidates, k=5)), | ||
| "".join(random.choices(candidates, k=5)), |
There was a problem hiding this comment.
Again, why are we using random letters here instead of using uuid?
| autogen.agentchat.Agent(name="Agent2"), | ||
| autogen.agentchat.Agent(name="Agent3")] | ||
|
|
||
| with pytest.raises(ValueError, match="get_socket_client_function is required if use_agent_stream is True"): |
There was a problem hiding this comment.
Can we also have a test that assures streaming is working?
Also, some example code which instantiates an agent and sets up socket streaming would be helpful.
|
@Tylersuard Thanks for your interest. This is surely a feature we hope to have but don't have cycle to work on. If you are interested, you can take a look at it. A good place to start is in the #1240 will refactor |
|
I have implemented this sort of thing in autogen multiple times so far. IMO the best 'official' way to handle it would be to introduce an input Queue and an output Queue, allowing the user to specify and/or override them. |
|
@joshkyh shall we close this one for now? The code base has moved a lot since. |
Great, you are welcome to go to #1551 to check it out. And there will be follow-up efforts on how to integrate it with frontend. |
Reviewers:
@ekzhu on navigating the refactoring efforts in #1240
@victordibia regarding the generalized approach in #394 (comment)
Why are these changes needed?
This PR allows the output of Agents like
ConversableAgentto be emitted through socket rather than print to console, allowing integration with other front end tools that could sit outside of Autogen. This PR is co-authored by @ragyabraham and myself. Tagging @tomlynchRNA for awareness.Related issue number
Closes #394
Associated #1199 for emitting to Teams front end. @tyler-suard-parker
Dependent on #1240 for cleaner/easier implementation.
Checks