forked from microsoft/autogen
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CAP] Improved AutoGen Agents support & Pip Install (microsoft#2711)
* 1) Removed most framework sleeps 2) refactored connection code * pre-commit fixes * pre-commit * ignore protobuf files in pre-commit checks * Fix duplicate actor registration * refactor change * Nicer printing of Actors * 1) Report recv_multipart errors 4) Always send 4 parts * AutoGen generate_reply expects to wait indefinitely for an answer. CAP can wait a certain amount and give up. In order to reconcile the two, AutoGenConnector is set to wait indefinitely. * pre-commit formatting fixes * pre-commit format changes * don't check autogenerated proto py files * Iterating on CAP interface for AutoGen * User proxy must initiate chat * autogencap pypi package * added dependencies * serialize/deserialize dictionary elements to json when dealing with ReceiveReq * 1) Removed most framework sleeps 2) refactored connection code * Nicer printing of Actors * AutoGen generate_reply expects to wait indefinitely for an answer. CAP can wait a certain amount and give up. In order to reconcile the two, AutoGenConnector is set to wait indefinitely. * pre-commit formatting fixes * pre-commit format changes * Iterating on CAP interface for AutoGen * User proxy must initiate chat * autogencap pypi package * added dependencies * serialize/deserialize dictionary elements to json when dealing with ReceiveReq * pre-commit check fixes * fix pre-commit issues * Better encapsulation of logging * pre-commit fix * pip package update
- Loading branch information
1 parent
11d9336
commit 31d2d37
Showing
12 changed files
with
235 additions
and
52 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Composable Actor Platform (CAP) for AutoGen | ||
|
||
## I just want to run the remote AutoGen agents! | ||
*Python Instructions (Windows, Linux, MacOS):* | ||
|
||
pip install autogencap | ||
|
||
1) AutoGen require OAI_CONFIG_LIST. | ||
AutoGen python requirements: 3.8 <= python <= 3.11 | ||
|
||
``` | ||
## What is Composable Actor Platform (CAP)? | ||
AutoGen is about Agents and Agent Orchestration. CAP extends AutoGen to allows Agents to communicate via a message bus. CAP, therefore, deals with the space between these components. CAP is a message based, actor platform that allows actors to be composed into arbitrary graphs. | ||
Actors can register themselves with CAP, find other agents, construct arbitrary graphs, send and receive messages independently and many, many, many other things. | ||
```python | ||
# CAP Platform | ||
network = LocalActorNetwork() | ||
# Register an agent | ||
network.register(GreeterAgent()) | ||
# Tell agents to connect to other agents | ||
network.connect() | ||
# Get a channel to the agent | ||
greeter_link = network.lookup_agent("Greeter") | ||
# Send a message to the agent | ||
greeter_link.send_txt_msg("Hello World!") | ||
# Cleanup | ||
greeter_link.close() | ||
network.disconnect() | ||
``` | ||
### Check out other demos in the `py/demo` directory. We show the following: ### | ||
1) Hello World shown above | ||
2) Many CAP Actors interacting with each other | ||
3) A pair of interacting AutoGen Agents wrapped in CAP Actors | ||
4) CAP wrapped AutoGen Agents in a group chat | ||
5) Two AutoGen Agents running in different processes and communicating through CAP | ||
6) List all registered agents in CAP | ||
7) AutoGen integration to list all registered agents |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import time | ||
|
||
from autogen import ConversableAgent | ||
|
||
from ..DebugLog import Info, Warn | ||
from .CAP2AG import CAP2AG | ||
|
||
|
||
class Agent: | ||
def __init__(self, agent: ConversableAgent, counter_party_name="user_proxy", init_chat=False): | ||
self._agent = agent | ||
self._the_other_name = counter_party_name | ||
self._agent_adptr = CAP2AG( | ||
ag_agent=self._agent, the_other_name=self._the_other_name, init_chat=init_chat, self_recursive=True | ||
) | ||
|
||
def register(self, network): | ||
Info("Agent", f"Running Standalone {self._agent.name}") | ||
network.register(self._agent_adptr) | ||
|
||
def running(self): | ||
return self._agent_adptr.run |
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
File renamed without changes.
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,57 @@ | ||
import time | ||
|
||
import _paths | ||
from autogencap.ag_adapter.agent import Agent | ||
from autogencap.Config import IGNORED_LOG_CONTEXTS | ||
from autogencap.LocalActorNetwork import LocalActorNetwork | ||
|
||
from autogen import UserProxyAgent | ||
|
||
# Filter out some Log message contexts | ||
IGNORED_LOG_CONTEXTS.extend(["BROKER"]) | ||
|
||
|
||
def main(): | ||
# Standard AutoGen | ||
user_proxy = UserProxyAgent( | ||
"user_proxy", | ||
code_execution_config={"work_dir": "coding"}, | ||
is_termination_msg=lambda x: "TERMINATE" in x.get("content"), | ||
) | ||
|
||
# Wrap AutoGen Agent in CAP | ||
cap_user_proxy = Agent(user_proxy, counter_party_name="assistant", init_chat=True) | ||
# Create the message bus | ||
network = LocalActorNetwork() | ||
# Add the user_proxy to the message bus | ||
cap_user_proxy.register(network) | ||
# Start message processing | ||
network.connect() | ||
|
||
# Wait for the user_proxy to finish | ||
interact_with_user(network, cap_user_proxy) | ||
# Cleanup | ||
network.disconnect() | ||
|
||
|
||
# Starts the Broker and the Assistant. The UserProxy is started separately. | ||
def interact_with_user(network, cap_assistant): | ||
user_proxy_conn = network.lookup_actor("user_proxy") | ||
example = "Plot a chart of MSFT daily closing prices for last 1 Month." | ||
print(f"Example: {example}") | ||
try: | ||
user_input = input("Please enter your command: ") | ||
if user_input == "": | ||
user_input = example | ||
print(f"Sending: {user_input}") | ||
user_proxy_conn.send_txt_msg(user_input) | ||
|
||
# Hang around for a while | ||
while cap_assistant.running(): | ||
time.sleep(0.5) | ||
except KeyboardInterrupt: | ||
print("Interrupted by user, shutting down.") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.