Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions autogen/agentchat/conversable_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2132,6 +2132,20 @@ async def a_generate_reply(
return reply
return self._default_auto_reply

def run(
self,
message: str,
sender: Optional["Agent"] = None,
):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Add the return type here to be more explicit?

if sender is not None:
all_message = self._oai_messages[sender]
all_message.append({"content": message, "role": "user"})
self._oai_messages[sender] = all_message
else:
all_message = [{"content": message, "role": "user"}]
reply = self.generate_reply(messages=all_message)
return reply

def _match_trigger(self, trigger: Union[None, str, type, Agent, Callable, List], sender: Optional[Agent]) -> bool:
"""Check if the sender matches the trigger.

Expand Down
32 changes: 27 additions & 5 deletions website/docs/tutorial/introduction.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -108,19 +108,41 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"You can ask this agent to generate a response to a question using the `generate_reply` method:"
"You can ask this agent to generate a response to a question using the `run` (recommended) method or `generate_reply` method:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Sure, here's one for you:\n",
"\n",
"Why don't scientists trust atoms?\n",
"\n",
"Because they make up everything!\n"
]
}
],
"source": [
"reply = agent.run(message=\"Tell me a joke.\")\n",
"print(reply)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Sure, here's a light-hearted joke for you:\n",
"Sure, here's one for you:\n",
"\n",
"Why don't scientists trust atoms?\n",
"\n",
Expand Down Expand Up @@ -257,7 +279,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
Loading