mirror of
https://github.com/microsoft/autogen.git
synced 2025-10-07 14:06:51 +00:00

* Core CAP components + Autogen adapter + Demo * Cleanup Readme * C# folder * Cleanup readme * summary_method bug fix * CAN -> CAP * pre-commit fixes * pre-commit fixes * modification of sys path should ignore E402 * fix pre-commit check issues * Updated docs * Clean up docs * more refactoring * better packaging refactor * Refactoring for package changes * Run demo app without autogencap installed or in the path * Remove debug related sleep() * removed CAP in some class names * Investigate a logging framework that supports color in windows * added type hints * remove circular dependency * fixed pre-commit issues * pre-commit ruff issues * removed circular definition * pre-commit fixes * Fix pre-commit issues * pre-commit fixes * updated for _prepare_chat signature changes * Better instructions for demo and some minor refactoring * Added details that explain CAP * Reformat Readme * More ReadMe Formatting * Readme edits * Agent -> Actor * Broker can startup on it's own * Remote AutoGen Agents * Updated docs * 1) StandaloneBroker in demo 2) Removed Autogen only demo options * 1) Agent -> Actor refactor 2) init broker as early * rename user_proxy -> user_proxy_conn * Add DirectorySvc * Standalone demo refactor * Get ActorInfo from DirectorySvc when searching for Actor * Broker cleanup * Proper cleanup and remove debug sleep() * Run one directory service only. * fix paths to run demo apps from command line * Handle keyboard interrupt * Wait for Broker and Directory to start up * Move Terminate AGActor * Accept input from the user in UserProxy * Move sleeps close to operations that bind or connect * Comments * Created an encapsulated CAP Pair for AutoGen pair communication * pre-commit checks * fix pre-commit * Pair should not make assumptions about who is first and who is second * Use task passed into InitiateChat * Standalone directory svc * Fix broken LFS files * Long running DirectorySvc * DirectorySvc does not have a status * Exit DirectorySvc Loop * Debugging Remoting * Reduce frequency of status messages * Debugging remote Actor * roll back git-lfs updates * rollback git-lfs changes * Debug network connectivity * pre-commit fixes * Create a group chat interface familiar to AutoGen GroupChat users * pre-commit fixes
82 lines
2.6 KiB
Python
82 lines
2.6 KiB
Python
import time
|
|
from typing import Callable, Dict, List, Optional, Union
|
|
from autogen import Agent, ConversableAgent
|
|
from .AutoGenConnector import AutoGenConnector
|
|
from ..LocalActorNetwork import LocalActorNetwork
|
|
|
|
|
|
class AG2CAP(ConversableAgent):
|
|
"""
|
|
A conversable agent proxy that sends messages to CAN when called
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
network: LocalActorNetwork,
|
|
agent_name: str,
|
|
agent_description: Optional[str] = None,
|
|
):
|
|
super().__init__(name=agent_name, description=agent_description, llm_config=False)
|
|
self._agent_connector: AutoGenConnector = None
|
|
self._network: LocalActorNetwork = network
|
|
self._recv_called = False
|
|
|
|
def reset_receive_called(self):
|
|
self._recv_called = False
|
|
|
|
def was_receive_called(self):
|
|
return self._recv_called
|
|
|
|
def set_name(self, name: str):
|
|
"""
|
|
Set the name of the agent.
|
|
Why? because we need it to look like different agents
|
|
"""
|
|
self._name = name
|
|
|
|
def _check_connection(self):
|
|
if self._agent_connector is None:
|
|
self._agent_connector = AutoGenConnector(self._network.lookup_actor(self.name))
|
|
self._terminate_connector = AutoGenConnector(self._network.lookup_termination())
|
|
|
|
def receive(
|
|
self,
|
|
message: Union[Dict, str],
|
|
sender: Agent,
|
|
request_reply: Optional[bool] = None,
|
|
silent: Optional[bool] = False,
|
|
):
|
|
"""
|
|
Receive a message from the AutoGen system.
|
|
"""
|
|
self._recv_called = True
|
|
self._check_connection()
|
|
self._agent_connector.send_receive_req(message, sender, request_reply, silent)
|
|
|
|
def generate_reply(
|
|
self,
|
|
messages: Optional[List[Dict]] = None,
|
|
sender: Optional[Agent] = None,
|
|
exclude: Optional[List[Callable]] = None,
|
|
) -> Union[str, Dict, None]:
|
|
"""
|
|
Generate a reply message for the AutoGen system.
|
|
"""
|
|
self._check_connection()
|
|
return self._agent_connector.send_gen_reply_req()
|
|
|
|
def _prepare_chat(
|
|
self,
|
|
recipient: ConversableAgent,
|
|
clear_history: bool,
|
|
prepare_recipient: bool = True,
|
|
reply_at_receive: bool = True,
|
|
) -> None:
|
|
self._check_connection()
|
|
self._agent_connector.send_prep_chat(recipient, clear_history, prepare_recipient)
|
|
|
|
def send_terminate(self, recipient: ConversableAgent) -> None:
|
|
self._check_connection()
|
|
self._agent_connector.send_terminate(recipient)
|
|
self._terminate_connector.send_terminate(self)
|