Skip to content

Commit eb826ed

Browse files
ekzhudavorrunjejackgerritsAaronWardsonichi
authored
Code executors (microsoft#1405)
* code executor * test * revert to main conversable agent * prepare for pr * kernel * run open ai tests only when it's out of draft status * update workflow file * revert workflow changes * ipython executor * check kernel installed; fix tests * fix tests * fix tests * update system prompt * Update notebook, more tests * notebook * raise instead of return None * allow user provided code executor. * fixing types * wip * refactoring * polishing * fixed failing tests * resolved merge conflict * fixing failing test * wip * local command line executor and embedded ipython executor * revert notebook * fix format * fix merged error * fix lmm test * fix lmm test * move warning * name and description should be part of the agent protocol, reset is not as it is only used for ConversableAgent; removing accidentally commited file * version for dependency * Update autogen/agentchat/conversable_agent.py Co-authored-by: Jack Gerrits <[email protected]> * ordering of protocol * description * fix tests * make ipython executor dependency optional * update document optional dependencies * Remove exclude from Agent protocol * Make ConversableAgent consistent with Agent * fix tests * add doc string * add doc string * fix notebook * fix interface * merge and update agents * disable config usage in reply function * description field setter * customize system message update * update doc --------- Co-authored-by: Davor Runje <[email protected]> Co-authored-by: Jack Gerrits <[email protected]> Co-authored-by: Aaron <[email protected]> Co-authored-by: Chi Wang <[email protected]>
1 parent 32b252d commit eb826ed

22 files changed

+1419
-129
lines changed

.github/workflows/build.yml

+8
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ jobs:
4242
pip install -e .
4343
python -c "import autogen"
4444
pip install pytest mock
45+
pip install jupyter-client ipykernel
46+
python -m ipykernel install --user --name python3
47+
- name: Set AUTOGEN_USE_DOCKER based on OS
48+
shell: bash
49+
run: |
50+
if [[ ${{ matrix.os }} != ubuntu-latest ]]; then
51+
echo "AUTOGEN_USE_DOCKER=False" >> $GITHUB_ENV
52+
fi
4553
- name: Test with pytest skipping openai tests
4654
if: matrix.python-version != '3.10' && matrix.os == 'ubuntu-latest'
4755
run: |

autogen/agentchat/agent.py

+100-34
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,136 @@
1-
from typing import Dict, List, Optional, Union
1+
from typing import Any, Dict, List, Optional, Protocol, Union, runtime_checkable
22

33

4-
class Agent:
5-
"""(In preview) An abstract class for AI agent.
4+
@runtime_checkable
5+
class Agent(Protocol):
6+
"""(In preview) A protocol for Agent.
67
78
An agent can communicate with other agents and perform actions.
89
Different agents can differ in what actions they perform in the `receive` method.
910
"""
1011

11-
def __init__(
12+
@property
13+
def name(self) -> str:
14+
"""The name of the agent."""
15+
...
16+
17+
@property
18+
def description(self) -> str:
19+
"""The description of the agent. Used for the agent's introduction in
20+
a group chat setting."""
21+
...
22+
23+
def send(
1224
self,
13-
name: str,
14-
):
15-
"""
25+
message: Union[Dict[str, Any], str],
26+
recipient: "Agent",
27+
request_reply: Optional[bool] = None,
28+
) -> None:
29+
"""Send a message to another agent.
30+
1631
Args:
17-
name (str): name of the agent.
32+
message (dict or str): the message to send. If a dict, it should be
33+
a JSON-serializable and follows the OpenAI's ChatCompletion schema.
34+
recipient (Agent): the recipient of the message.
35+
request_reply (bool): whether to request a reply from the recipient.
1836
"""
19-
# a dictionary of conversations, default value is list
20-
self._name = name
37+
...
2138

22-
@property
23-
def name(self):
24-
"""Get the name of the agent."""
25-
return self._name
39+
async def a_send(
40+
self,
41+
message: Union[Dict[str, Any], str],
42+
recipient: "Agent",
43+
request_reply: Optional[bool] = None,
44+
) -> None:
45+
"""(Async) Send a message to another agent.
2646
27-
def send(self, message: Union[Dict, str], recipient: "Agent", request_reply: Optional[bool] = None):
28-
"""(Abstract method) Send a message to another agent."""
47+
Args:
48+
message (dict or str): the message to send. If a dict, it should be
49+
a JSON-serializable and follows the OpenAI's ChatCompletion schema.
50+
recipient (Agent): the recipient of the message.
51+
request_reply (bool): whether to request a reply from the recipient.
52+
"""
53+
...
2954

30-
async def a_send(self, message: Union[Dict, str], recipient: "Agent", request_reply: Optional[bool] = None):
31-
"""(Abstract async method) Send a message to another agent."""
55+
def receive(
56+
self,
57+
message: Union[Dict[str, Any], str],
58+
sender: "Agent",
59+
request_reply: Optional[bool] = None,
60+
) -> None:
61+
"""Receive a message from another agent.
3262
33-
def receive(self, message: Union[Dict, str], sender: "Agent", request_reply: Optional[bool] = None):
34-
"""(Abstract method) Receive a message from another agent."""
63+
Args:
64+
message (dict or str): the message received. If a dict, it should be
65+
a JSON-serializable and follows the OpenAI's ChatCompletion schema.
66+
sender (Agent): the sender of the message.
67+
request_reply (bool): whether the sender requests a reply.
68+
"""
3569

36-
async def a_receive(self, message: Union[Dict, str], sender: "Agent", request_reply: Optional[bool] = None):
37-
"""(Abstract async method) Receive a message from another agent."""
70+
async def a_receive(
71+
self,
72+
message: Union[Dict[str, Any], str],
73+
sender: "Agent",
74+
request_reply: Optional[bool] = None,
75+
) -> None:
76+
"""(Async) Receive a message from another agent.
3877
39-
def reset(self):
40-
"""(Abstract method) Reset the agent."""
78+
Args:
79+
message (dict or str): the message received. If a dict, it should be
80+
a JSON-serializable and follows the OpenAI's ChatCompletion schema.
81+
sender (Agent): the sender of the message.
82+
request_reply (bool): whether the sender requests a reply.
83+
"""
84+
...
4185

4286
def generate_reply(
4387
self,
44-
messages: Optional[List[Dict]] = None,
88+
messages: Optional[List[Dict[str, Any]]] = None,
4589
sender: Optional["Agent"] = None,
46-
**kwargs,
47-
) -> Union[str, Dict, None]:
48-
"""(Abstract method) Generate a reply based on the received messages.
90+
**kwargs: Any,
91+
) -> Union[str, Dict[str, Any], None]:
92+
"""Generate a reply based on the received messages.
4993
5094
Args:
51-
messages (list[dict]): a list of messages received.
95+
messages (list[dict]): a list of messages received from other agents.
96+
The messages are dictionaries that are JSON-serializable and
97+
follows the OpenAI's ChatCompletion schema.
5298
sender: sender of an Agent instance.
99+
53100
Returns:
54101
str or dict or None: the generated reply. If None, no reply is generated.
55102
"""
56103

57104
async def a_generate_reply(
58105
self,
59-
messages: Optional[List[Dict]] = None,
106+
messages: Optional[List[Dict[str, Any]]] = None,
60107
sender: Optional["Agent"] = None,
61-
**kwargs,
62-
) -> Union[str, Dict, None]:
63-
"""(Abstract async method) Generate a reply based on the received messages.
108+
**kwargs: Any,
109+
) -> Union[str, Dict[str, Any], None]:
110+
"""(Async) Generate a reply based on the received messages.
64111
65112
Args:
66-
messages (list[dict]): a list of messages received.
113+
messages (list[dict]): a list of messages received from other agents.
114+
The messages are dictionaries that are JSON-serializable and
115+
follows the OpenAI's ChatCompletion schema.
67116
sender: sender of an Agent instance.
117+
68118
Returns:
69119
str or dict or None: the generated reply. If None, no reply is generated.
70120
"""
121+
122+
123+
@runtime_checkable
124+
class LLMAgent(Agent, Protocol):
125+
"""(In preview) A protocol for an LLM agent."""
126+
127+
@property
128+
def system_message(self) -> str:
129+
"""The system message of this agent."""
130+
131+
def update_system_message(self, system_message: str) -> None:
132+
"""Update this agent's system message.
133+
134+
Args:
135+
system_message (str): system message for inference.
136+
"""

0 commit comments

Comments
 (0)