TelegramAgent
autogen.agents.experimental.TelegramAgent #
TelegramAgent(name, system_message=None, *, api_id, api_hash, chat_id, has_writing_instructions=True, **kwargs)
Bases: ConversableAgent
An agent that can send messages and retrieve messages on Telegram.
Initialize the TelegramAgent.
PARAMETER | DESCRIPTION |
---|---|
name | The name of the agent. TYPE: |
system_message | The system message for the agent. |
api_id | Telegram API ID from https://my.telegram.org/apps. TYPE: |
api_hash | Telegram API hash from https://my.telegram.org/apps. TYPE: |
chat_id | The ID of the destination (Channel, Group, or User ID). TYPE: |
has_writing_instructions | Whether to add writing instructions to the system message. Defaults to True. TYPE: |
**kwargs | Additional keyword arguments passed to the parent ConversableAgent class. TYPE: |
Source code in autogen/agents/experimental/telegram/telegram.py
DEFAULT_SUMMARY_PROMPT class-attribute
instance-attribute
#
DEFAULT_SUMMARY_PROMPT = 'Summarize the takeaway from the conversation. Do not add any introductory phrases.'
hook_lists instance-attribute
#
hook_lists = {'process_last_received_message': [], 'process_all_messages_before_reply': [], 'process_message_before_send': [], 'update_agent_state': []}
code_executor property
#
The code executor used by this agent. Returns None if code execution is disabled.
chat_messages property
#
A dictionary of conversations from agent to list of messages.
use_docker property
#
Bool value of whether to use docker to execute the code, or str value of the docker image name to use, or None when code execution is disabled.
tools property
#
Get the agent's tools (registered for LLM)
Note this is a copy of the tools list, use add_tool and remove_tool to modify the tools list.
DEFAULT_SYSTEM_MESSAGE class-attribute
instance-attribute
#
DEFAULT_SYSTEM_MESSAGE = 'You are a helpful AI assistant that communicates through Telegram. Remember that Telegram uses Markdown-like formatting and has message length limits. Keep messages clear and concise, and consider using appropriate formatting when helpful.'
send #
Send a message to another agent.
PARAMETER | DESCRIPTION |
---|---|
message | message to be sent. The message could contain the following fields: - content (str or List): Required, the content of the message. (Can be None) - function_call (str): the name of the function to be called. - name (str): the name of the function to be called. - role (str): the role of the message, any role that is not "function" will be modified to "assistant". - context (dict): the context of the message, which will be passed to OpenAIWrapper.create. For example, one agent can send a message A as: |
{
"content": lambda context: context["use_tool_msg"],
"context": {"use_tool_msg": "Use tool X if they are relevant."},
}
RAISES | DESCRIPTION |
---|---|
ValueError | if the message can't be converted into a valid ChatCompletion message. |
Source code in autogen/agentchat/conversable_agent.py
a_send async
#
(async) Send a message to another agent.
PARAMETER | DESCRIPTION |
---|---|
message | message to be sent. The message could contain the following fields: - content (str or List): Required, the content of the message. (Can be None) - function_call (str): the name of the function to be called. - name (str): the name of the function to be called. - role (str): the role of the message, any role that is not "function" will be modified to "assistant". - context (dict): the context of the message, which will be passed to OpenAIWrapper.create. For example, one agent can send a message A as: |
{
"content": lambda context: context["use_tool_msg"],
"context": {"use_tool_msg": "Use tool X if they are relevant."},
}
RAISES | DESCRIPTION |
---|---|
ValueError | if the message can't be converted into a valid ChatCompletion message. |
Source code in autogen/agentchat/conversable_agent.py
receive #
Receive a message from another agent.
Once a message is received, this function sends a reply to the sender or stop. The reply can be generated automatically or entered manually by a human.
PARAMETER | DESCRIPTION |
---|---|
message | message from the sender. If the type is dict, it may contain the following reserved fields (either content or function_call need to be provided). 1. "content": content of the message, can be None. 2. "function_call": a dictionary containing the function name and arguments. (deprecated in favor of "tool_calls") 3. "tool_calls": a list of dictionaries containing the function name and arguments. 4. "role": role of the message, can be "assistant", "user", "function", "tool". This field is only needed to distinguish between "function" or "assistant"/"user". 5. "name": In most cases, this field is not needed. When the role is "function", this field is needed to indicate the function name. 6. "context" (dict): the context of the message, which will be passed to OpenAIWrapper.create. |
sender | sender of an Agent instance. TYPE: |
request_reply | whether a reply is requested from the sender. If None, the value is determined by TYPE: |
silent | (Experimental) whether to print the message received. TYPE: |
RAISES | DESCRIPTION |
---|---|
ValueError | if the message can't be converted into a valid ChatCompletion message. |
Source code in autogen/agentchat/conversable_agent.py
a_receive async
#
(async) Receive a message from another agent.
Once a message is received, this function sends a reply to the sender or stop. The reply can be generated automatically or entered manually by a human.
PARAMETER | DESCRIPTION |
---|---|
message | message from the sender. If the type is dict, it may contain the following reserved fields (either content or function_call need to be provided). 1. "content": content of the message, can be None. 2. "function_call": a dictionary containing the function name and arguments. (deprecated in favor of "tool_calls") 3. "tool_calls": a list of dictionaries containing the function name and arguments. 4. "role": role of the message, can be "assistant", "user", "function". This field is only needed to distinguish between "function" or "assistant"/"user". 5. "name": In most cases, this field is not needed. When the role is "function", this field is needed to indicate the function name. 6. "context" (dict): the context of the message, which will be passed to OpenAIWrapper.create. |
sender | sender of an Agent instance. TYPE: |
request_reply | whether a reply is requested from the sender. If None, the value is determined by TYPE: |
silent | (Experimental) whether to print the message received. TYPE: |
RAISES | DESCRIPTION |
---|---|
ValueError | if the message can't be converted into a valid ChatCompletion message. |
Source code in autogen/agentchat/conversable_agent.py
generate_reply #
Reply based on the conversation history and the sender.
Either messages or sender must be provided. Register a reply_func with None
as one trigger for it to be activated when messages
is non-empty and sender
is None
. Use registered auto reply functions to generate replies. By default, the following functions are checked in order: 1. check_termination_and_human_reply 2. generate_function_call_reply (deprecated in favor of tool_calls) 3. generate_tool_calls_reply 4. generate_code_execution_reply 5. generate_oai_reply Every function returns a tuple (final, reply). When a function returns final=False, the next function will be checked. So by default, termination and human reply will be checked first. If not terminating and human reply is skipped, execute function or code and return the result. AI replies are generated only when no code execution is performed.
PARAMETER | DESCRIPTION |
---|---|
messages | a list of messages in the conversation history. |
sender | sender of an Agent instance. |
**kwargs | Additional arguments to customize reply generation. Supported kwargs: - exclude (List[Callable[..., Any]]): A list of reply functions to exclude from the reply generation process. Functions in this list will be skipped even if they would normally be triggered. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Optional[Union[str, dict[str, Any]]] | str or dict or None: reply. None if no reply is generated. |
Source code in autogen/agentchat/conversable_agent.py
2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 |
|
a_generate_reply async
#
(async) Reply based on the conversation history and the sender.
Either messages or sender must be provided. Register a reply_func with None
as one trigger for it to be activated when messages
is non-empty and sender
is None
. Use registered auto reply functions to generate replies. By default, the following functions are checked in order: 1. check_termination_and_human_reply 2. generate_function_call_reply 3. generate_tool_calls_reply 4. generate_code_execution_reply 5. generate_oai_reply Every function returns a tuple (final, reply). When a function returns final=False, the next function will be checked. So by default, termination and human reply will be checked first. If not terminating and human reply is skipped, execute function or code and return the result. AI replies are generated only when no code execution is performed.
PARAMETER | DESCRIPTION |
---|---|
messages | a list of messages in the conversation history. |
sender | sender of an Agent instance. |
**kwargs | Additional arguments to customize reply generation. Supported kwargs: - exclude (List[Callable[..., Any]]): A list of reply functions to exclude from the reply generation process. Functions in this list will be skipped even if they would normally be triggered. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Union[str, dict[str, Any], None] | str or dict or None: reply. None if no reply is generated. |
Source code in autogen/agentchat/conversable_agent.py
2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 |
|
update_system_message #
Update the system message.
PARAMETER | DESCRIPTION |
---|---|
system_message | system message for the ChatCompletion inference. TYPE: |
Source code in autogen/agentchat/conversable_agent.py
register_reply #
register_reply(trigger, reply_func, position=0, config=None, reset_config=None, *, ignore_async_in_sync_chat=False, remove_other_reply_funcs=False)
Register a reply function.
The reply function will be called when the trigger matches the sender. The function registered later will be checked earlier by default. To change the order, set the position to a positive integer.
Both sync and async reply functions can be registered. The sync reply function will be triggered from both sync and async chats. However, an async reply function will only be triggered from async chats (initiated with ConversableAgent.a_initiate_chat
). If an async
reply function is registered and a chat is initialized with a sync function, ignore_async_in_sync_chat
determines the behaviour as follows: if ignore_async_in_sync_chat
is set to False
(default value), an exception will be raised, and if ignore_async_in_sync_chat
is set to True
, the reply function will be ignored.
PARAMETER | DESCRIPTION |
---|---|
trigger | the trigger. If a class is provided, the reply function will be called when the sender is an instance of the class. If a string is provided, the reply function will be called when the sender's name matches the string. If an agent instance is provided, the reply function will be called when the sender is the agent instance. If a callable is provided, the reply function will be called when the callable returns True. If a list is provided, the reply function will be called when any of the triggers in the list is activated. If None is provided, the reply function will be called only when the sender is None. Note: Be sure to register TYPE: |
reply_func | the reply function. The function takes a recipient agent, a list of messages, a sender agent and a config as input and returns a reply message. TYPE: |
position | the position of the reply function in the reply function list. The function registered later will be checked earlier by default. To change the order, set the position to a positive integer. TYPE: |
config | the config to be passed to the reply function. When an agent is reset, the config will be reset to the original value. TYPE: |
reset_config | the function to reset the config. The function returns None. Signature: TYPE: |
ignore_async_in_sync_chat | whether to ignore the async reply function in sync chats. If TYPE: |
remove_other_reply_funcs | whether to remove other reply functions when registering this reply function. TYPE: |
Source code in autogen/agentchat/conversable_agent.py
replace_reply_func #
Replace a registered reply function with a new one.
PARAMETER | DESCRIPTION |
---|---|
old_reply_func | the old reply function to be replaced. TYPE: |
new_reply_func | the new reply function to replace the old one. TYPE: |
Source code in autogen/agentchat/conversable_agent.py
register_nested_chats #
register_nested_chats(chat_queue, trigger, reply_func_from_nested_chats='summary_from_nested_chats', position=2, use_async=None, **kwargs)
Register a nested chat reply function.
PARAMETER | DESCRIPTION |
---|---|
chat_queue | a list of chat objects to be initiated. If use_async is used, then all messages in chat_queue must have a chat-id associated with them. TYPE: |
trigger | refer to TYPE: |
reply_func_from_nested_chats | the reply function for the nested chat. The function takes a chat_queue for nested chat, recipient agent, a list of messages, a sender agent and a config as input and returns a reply message. Default to "summary_from_nested_chats", which corresponds to a built-in reply function that get summary from the nested chat_queue. |
position | Ref to TYPE: |
use_async | Uses a_initiate_chats internally to start nested chats. If the original chat is initiated with a_initiate_chats, you may set this to true so nested chats do not run in sync. |
kwargs | Ref to TYPE: |
Source code in autogen/agentchat/conversable_agent.py
get_context #
set_context #
update_context #
Update multiple context variables at once.
PARAMETER | DESCRIPTION |
---|---|
context_variables | Dictionary of variables to update/add |
Source code in autogen/agentchat/conversable_agent.py
pop_context #
update_max_consecutive_auto_reply #
Update the maximum number of consecutive auto replies.
PARAMETER | DESCRIPTION |
---|---|
value | the maximum number of consecutive auto replies. TYPE: |
sender | when the sender is provided, only update the max_consecutive_auto_reply for that sender. TYPE: |
Source code in autogen/agentchat/conversable_agent.py
max_consecutive_auto_reply #
The maximum number of consecutive auto replies.
Source code in autogen/agentchat/conversable_agent.py
chat_messages_for_summary #
last_message #
The last message exchanged with the agent.
PARAMETER | DESCRIPTION |
---|---|
agent | The agent in the conversation. If None and more than one agent's conversations are found, an error will be raised. If None and only one conversation is found, the last message of the only conversation will be returned. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Optional[dict[str, Any]] | The last message exchanged with the agent. |
Source code in autogen/agentchat/conversable_agent.py
initiate_chat #
initiate_chat(recipient, clear_history=True, silent=False, cache=None, max_turns=None, summary_method=DEFAULT_SUMMARY_METHOD, summary_args={}, message=None, **kwargs)
Initiate a chat with the recipient agent.
Reset the consecutive auto reply counter. If clear_history
is True, the chat history with the recipient agent will be cleared.
PARAMETER | DESCRIPTION |
---|---|
recipient | the recipient agent. TYPE: |
clear_history | whether to clear the chat history with the agent. Default is True. TYPE: |
silent | (Experimental) whether to print the messages for this conversation. Default is False. TYPE: |
cache | the cache client to be used for this conversation. Default is None. TYPE: |
max_turns | the maximum number of turns for the chat between the two agents. One turn means one conversation round trip. Note that this is different from TYPE: |
summary_method | a method to get a summary from the chat. Default is DEFAULT_SUMMARY_METHOD, i.e., "last_msg". Supported strings are "last_msg" and "reflection_with_llm": - when set to "last_msg", it returns the last message of the dialog as the summary. - when set to "reflection_with_llm", it returns a summary extracted using an llm client. A callable summary_method should take the recipient and sender agent in a chat as input and return a string of summary. E.g., TYPE: |
summary_args | a dictionary of arguments to be passed to the summary_method. One example key is "summary_prompt", and value is a string of text used to prompt a LLM-based agent (the sender or recipient agent) to reflect on the conversation and extract a summary when summary_method is "reflection_with_llm". The default summary_prompt is DEFAULT_SUMMARY_PROMPT, i.e., "Summarize takeaway from the conversation. Do not add any introductory phrases. If the intended request is NOT properly addressed, please point it out." Another available key is "summary_role", which is the role of the message sent to the agent in charge of summarizing. Default is "system". TYPE: |
message | the initial message to be sent to the recipient. Needs to be provided. Otherwise, input() will be called to get the initial message. - If a string or a dict is provided, it will be used as the initial message.
|
**kwargs | any additional information. It has the following reserved fields: - "carryover": a string or a list of string to specify the carryover information to be passed to this chat. If provided, we will combine this carryover (by attaching a "context: " string and the carryover content after the message content) with the "message" content when generating the initial chat message in TYPE: |
RAISES | DESCRIPTION |
---|---|
RuntimeError | if any async reply functions are registered and not ignored in sync chat. |
RETURNS | DESCRIPTION |
---|---|
ChatResult | an ChatResult object. TYPE: |
Source code in autogen/agentchat/conversable_agent.py
1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 |
|
run #
run(recipient=None, clear_history=True, silent=False, cache=None, max_turns=None, summary_method=DEFAULT_SUMMARY_METHOD, summary_args={}, message=None, executor_kwargs=None, tools=None, user_input=False, msg_to='agent', **kwargs)
Source code in autogen/agentchat/conversable_agent.py
1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 |
|
a_initiate_chat async
#
a_initiate_chat(recipient, clear_history=True, silent=False, cache=None, max_turns=None, summary_method=DEFAULT_SUMMARY_METHOD, summary_args={}, message=None, **kwargs)
(async) Initiate a chat with the recipient agent.
Reset the consecutive auto reply counter. If clear_history
is True, the chat history with the recipient agent will be cleared. a_generate_init_message
is called to generate the initial message for the agent.
Args: Please refer to initiate_chat
.
RETURNS | DESCRIPTION |
---|---|
ChatResult | an ChatResult object. TYPE: |
Source code in autogen/agentchat/conversable_agent.py
1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 |
|
a_run async
#
a_run(recipient=None, clear_history=True, silent=False, cache=None, max_turns=None, summary_method=DEFAULT_SUMMARY_METHOD, summary_args={}, message=None, executor_kwargs=None, tools=None, user_input=False, msg_to='agent', **kwargs)
Source code in autogen/agentchat/conversable_agent.py
1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 |
|
initiate_chats #
(Experimental) Initiate chats with multiple agents.
PARAMETER | DESCRIPTION |
---|---|
chat_queue | a list of dictionaries containing the information of the chats. Each dictionary should contain the input arguments for TYPE: |
Returns: a list of ChatResult objects corresponding to the finished chats in the chat_queue.
Source code in autogen/agentchat/conversable_agent.py
sequential_run #
(Experimental) Initiate chats with multiple agents sequentially.
PARAMETER | DESCRIPTION |
---|---|
chat_queue | a list of dictionaries containing the information of the chats. Each dictionary should contain the input arguments for TYPE: |
Returns: a list of ChatResult objects corresponding to the finished chats in the chat_queue.
Source code in autogen/agentchat/conversable_agent.py
1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 |
|
a_initiate_chats async
#
Source code in autogen/agentchat/conversable_agent.py
a_sequential_run async
#
(Experimental) Initiate chats with multiple agents sequentially.
PARAMETER | DESCRIPTION |
---|---|
chat_queue | a list of dictionaries containing the information of the chats. Each dictionary should contain the input arguments for TYPE: |
Returns: a list of ChatResult objects corresponding to the finished chats in the chat_queue.
Source code in autogen/agentchat/conversable_agent.py
2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 |
|
get_chat_results #
A summary from the finished chats of particular agents.
Source code in autogen/agentchat/conversable_agent.py
reset #
Reset the agent.
Source code in autogen/agentchat/conversable_agent.py
stop_reply_at_receive #
Reset the reply_at_receive of the sender.
reset_consecutive_auto_reply_counter #
Reset the consecutive_auto_reply_counter of the sender.
Source code in autogen/agentchat/conversable_agent.py
clear_history #
Clear the chat history of the agent.
PARAMETER | DESCRIPTION |
---|---|
recipient | the agent with whom the chat history to clear. If None, clear the chat history with all agents. |
nr_messages_to_preserve | the number of newest messages to preserve in the chat history. |
Source code in autogen/agentchat/conversable_agent.py
generate_oai_reply #
Generate a reply using autogen.oai.
Source code in autogen/agentchat/conversable_agent.py
a_generate_oai_reply async
#
Generate a reply using autogen.oai asynchronously.
Source code in autogen/agentchat/conversable_agent.py
generate_code_execution_reply #
Generate a reply using code execution.
Source code in autogen/agentchat/conversable_agent.py
generate_function_call_reply #
Generate a reply using function call.
"function_call" replaced by "tool_calls" as of OpenAI API v1.1.0 See https://platform.openai.com/docs/api-reference/chat/create#chat-create-functions
Source code in autogen/agentchat/conversable_agent.py
a_generate_function_call_reply async
#
Generate a reply using async function call.
"function_call" replaced by "tool_calls" as of OpenAI API v1.1.0 See https://platform.openai.com/docs/api-reference/chat/create#chat-create-functions
Source code in autogen/agentchat/conversable_agent.py
generate_tool_calls_reply #
Generate a reply using tool call.
Source code in autogen/agentchat/conversable_agent.py
a_generate_tool_calls_reply async
#
Generate a reply using async function call.
Source code in autogen/agentchat/conversable_agent.py
check_termination_and_human_reply #
Check if the conversation should be terminated, and if human reply is provided.
This method checks for conditions that require the conversation to be terminated, such as reaching a maximum number of consecutive auto-replies or encountering a termination message. Additionally, it prompts for and processes human input based on the configured human input mode, which can be 'ALWAYS', 'NEVER', or 'TERMINATE'. The method also manages the consecutive auto-reply counter for the conversation and prints relevant messages based on the human input received.
PARAMETER | DESCRIPTION |
---|---|
messages | A list of message dictionaries, representing the conversation history. |
sender | The agent object representing the sender of the message. |
config | Configuration object, defaults to the current instance if not provided. |
RETURNS | DESCRIPTION |
---|---|
bool | A tuple containing a boolean indicating if the conversation |
Union[str, None] | should be terminated, and a human reply which can be a string, a dictionary, or None. |
Source code in autogen/agentchat/conversable_agent.py
2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 |
|
a_check_termination_and_human_reply async
#
(async) Check if the conversation should be terminated, and if human reply is provided.
This method checks for conditions that require the conversation to be terminated, such as reaching a maximum number of consecutive auto-replies or encountering a termination message. Additionally, it prompts for and processes human input based on the configured human input mode, which can be 'ALWAYS', 'NEVER', or 'TERMINATE'. The method also manages the consecutive auto-reply counter for the conversation and prints relevant messages based on the human input received.
PARAMETER | DESCRIPTION |
---|---|
messages | A list of message dictionaries, representing the conversation history. TYPE: |
sender | The agent object representing the sender of the message. |
config | Configuration object, defaults to the current instance if not provided. |
RETURNS | DESCRIPTION |
---|---|
bool | Tuple[bool, Union[str, Dict, None]]: A tuple containing a boolean indicating if the conversation |
Union[str, None] | should be terminated, and a human reply which can be a string, a dictionary, or None. |
Source code in autogen/agentchat/conversable_agent.py
2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 |
|
get_human_input #
Get human input.
Override this method to customize the way to get human input.
PARAMETER | DESCRIPTION |
---|---|
prompt | prompt for the human input. TYPE: |
RETURNS | DESCRIPTION |
---|---|
str | human input. TYPE: |
Source code in autogen/agentchat/conversable_agent.py
a_get_human_input async
#
(Async) Get human input.
Override this method to customize the way to get human input.
PARAMETER | DESCRIPTION |
---|---|
prompt | prompt for the human input. TYPE: |
RETURNS | DESCRIPTION |
---|---|
str | human input. TYPE: |
Source code in autogen/agentchat/conversable_agent.py
run_code #
Run the code and return the result.
Override this function to modify the way to run the code.
PARAMETER | DESCRIPTION |
---|---|
code | the code to be executed. TYPE: |
**kwargs | other keyword arguments. TYPE: |
RETURNS | DESCRIPTION |
---|---|
int | A tuple of (exitcode, logs, image). |
exitcode | the exit code of the code execution. TYPE: |
logs | the logs of the code execution. TYPE: |
image | the docker image used for the code execution. TYPE: |
Source code in autogen/agentchat/conversable_agent.py
execute_code_blocks #
Execute the code blocks and return the result.
Source code in autogen/agentchat/conversable_agent.py
execute_function #
Execute a function call and return the result.
Override this function to modify the way to execute function and tool calls.
PARAMETER | DESCRIPTION |
---|---|
func_call | a dictionary extracted from openai message at "function_call" or "tool_calls" with keys "name" and "arguments". |
call_id | a string to identify the tool call. |
verbose | Whether to send messages about the execution details to the output stream. When True, both the function call arguments and the execution result will be displayed. Defaults to False. TYPE: |
RETURNS | DESCRIPTION |
---|---|
bool | A tuple of (is_exec_success, result_dict). |
is_exec_success | whether the execution is successful. TYPE: |
result_dict | a dictionary with keys "name", "role", and "content". Value of "role" is "function". |
"function_call" deprecated as of OpenAI API v1.1.0 See https://platform.openai.com/docs/api-reference/chat/create#chat-create-function_call
Source code in autogen/agentchat/conversable_agent.py
3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 |
|
a_execute_function async
#
Execute an async function call and return the result.
Override this function to modify the way async functions and tools are executed.
PARAMETER | DESCRIPTION |
---|---|
func_call | a dictionary extracted from openai message at key "function_call" or "tool_calls" with keys "name" and "arguments". |
call_id | a string to identify the tool call. |
verbose | Whether to send messages about the execution details to the output stream. When True, both the function call arguments and the execution result will be displayed. Defaults to False. TYPE: |
RETURNS | DESCRIPTION |
---|---|
bool | A tuple of (is_exec_success, result_dict). |
is_exec_success | whether the execution is successful. TYPE: |
result_dict | a dictionary with keys "name", "role", and "content". Value of "role" is "function". |
"function_call" deprecated as of OpenAI API v1.1.0 See https://platform.openai.com/docs/api-reference/chat/create#chat-create-function_call
Source code in autogen/agentchat/conversable_agent.py
3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 |
|
generate_init_message #
Generate the initial message for the agent. If message is None, input() will be called to get the initial message.
PARAMETER | DESCRIPTION |
---|---|
message | the message to be processed. TYPE: |
**kwargs | any additional information. It has the following reserved fields: "carryover": a string or a list of string to specify the carryover information to be passed to this chat. It can be a string or a list of string. If provided, we will combine this carryover with the "message" content when generating the initial chat message. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Union[str, dict[str, Any]] | str or dict: the processed message. |
Source code in autogen/agentchat/conversable_agent.py
a_generate_init_message async
#
Generate the initial message for the agent. If message is None, input() will be called to get the initial message.
PARAMETER | DESCRIPTION |
---|---|
message | the message to be processed. TYPE: |
**kwargs | any additional information. It has the following reserved fields: "carryover": a string or a list of string to specify the carryover information to be passed to this chat. It can be a string or a list of string. If provided, we will combine this carryover with the "message" content when generating the initial chat message. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Union[str, dict[str, Any]] | str or dict: the processed message. |
Source code in autogen/agentchat/conversable_agent.py
remove_tool_for_llm #
Remove a tool (register for LLM tool)
Source code in autogen/agentchat/conversable_agent.py
register_function #
Register functions to the agent.
PARAMETER | DESCRIPTION |
---|---|
function_map | a dictionary mapping function names to functions. if function_map[name] is None, the function will be removed from the function_map. |
silent_override | whether to print warnings when overriding functions. TYPE: |
Source code in autogen/agentchat/conversable_agent.py
update_function_signature #
Update a function_signature in the LLM configuration for function_call.
PARAMETER | DESCRIPTION |
---|---|
func_sig | description/name of the function to update/remove to the model. See: https://platform.openai.com/docs/api-reference/chat/create#chat/create-functions |
is_remove | whether removing the function from llm_config with name 'func_sig' TYPE: |
silent_override | whether to print warnings when overriding functions. TYPE: |
Deprecated as of OpenAI API v1.1.0 See https://platform.openai.com/docs/api-reference/chat/create#chat-create-function_call
Source code in autogen/agentchat/conversable_agent.py
update_tool_signature #
Update a tool_signature in the LLM configuration for tool_call.
PARAMETER | DESCRIPTION |
---|---|
tool_sig | description/name of the tool to update/remove to the model. See: https://platform.openai.com/docs/api-reference/chat/create#chat-create-tools |
is_remove | whether removing the tool from llm_config with name 'tool_sig' TYPE: |
silent_override | whether to print warnings when overriding functions. TYPE: |
Source code in autogen/agentchat/conversable_agent.py
can_execute_function #
Whether the agent can execute the function.
register_for_llm #
Decorator factory for registering a function to be used by an agent.
It's return value is used to decorate a function to be registered to the agent. The function uses type hints to specify the arguments and return type. The function name is used as the default name for the function, but a custom name can be provided. The function description is used to describe the function in the agent's configuration.
PARAMETER | DESCRIPTION |
---|---|
name | name of the function. If None, the function name will be used (default: None). TYPE: |
description | description of the function (default: None). It is mandatory for the initial decorator, but the following ones can omit it. TYPE: |
api_style | (literal): the API style for function call. For Azure OpenAI API, use version 2023-12-01-preview or later. TYPE: |
silent_override | whether to suppress any override warning messages. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Callable[[Union[F, Tool]], Tool] | The decorator for registering a function to be used by an agent. |
Examples:
@user_proxy.register_for_execution()
@agent2.register_for_llm()
@agent1.register_for_llm(description="This is a very useful function")
def my_function(a: Annotated[str, "description of a parameter"] = "a", b: int, c=3.14) -> str:
return a + str(b * c)
For Azure OpenAI versions prior to 2023-12-01-preview, set api_style
to "function"
if "tool"
doesn't work:
@agent2.register_for_llm(api_style="function")
def my_function(a: Annotated[str, "description of a parameter"] = "a", b: int, c=3.14) -> str:
return a + str(b * c)
Source code in autogen/agentchat/conversable_agent.py
3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 |
|
register_for_execution #
Decorator factory for registering a function to be executed by an agent.
It's return value is used to decorate a function to be registered to the agent.
PARAMETER | DESCRIPTION |
---|---|
name | name of the function. If None, the function name will be used (default: None). |
description | description of the function (default: None). |
serialize | whether to serialize the return value TYPE: |
silent_override | whether to suppress any override warning messages TYPE: |
RETURNS | DESCRIPTION |
---|---|
Callable[[Union[Tool, F]], Tool] | The decorator for registering a function to be used by an agent. |
Examples:
@user_proxy.register_for_execution()
@agent2.register_for_llm()
@agent1.register_for_llm(description="This is a very useful function")
def my_function(a: Annotated[str, "description of a parameter"] = "a", b: int, c=3.14):
return a + str(b * c)
Source code in autogen/agentchat/conversable_agent.py
register_model_client #
Register a model client.
PARAMETER | DESCRIPTION |
---|---|
model_client_cls | A custom client class that follows the Client interface TYPE: |
**kwargs | The kwargs for the custom client class to be initialized with TYPE: |
Source code in autogen/agentchat/conversable_agent.py
register_hook #
Registers a hook to be called by a hookable method, in order to add a capability to the agent. Registered hooks are kept in lists (one per hookable method), and are called in their order of registration.
PARAMETER | DESCRIPTION |
---|---|
hookable_method | A hookable method name implemented by ConversableAgent. TYPE: |
hook | A method implemented by a subclass of AgentCapability. TYPE: |
Source code in autogen/agentchat/conversable_agent.py
update_agent_state_before_reply #
Calls any registered capability hooks to update the agent's state. Primarily used to update context variables. Will, potentially, modify the messages.
Source code in autogen/agentchat/conversable_agent.py
process_all_messages_before_reply #
Calls any registered capability hooks to process all messages, potentially modifying the messages.
Source code in autogen/agentchat/conversable_agent.py
process_last_received_message #
Calls any registered capability hooks to use and potentially modify the text of the last message, as long as the last message is not a function call or exit command.
Source code in autogen/agentchat/conversable_agent.py
print_usage_summary #
Print the usage summary.