TimeReplyAgent
autogen.agents.contrib.TimeReplyAgent #
TimeReplyAgent(date_time_format='%Y-%m-%d %H:%M:%S', output_prefix='Tick, tock, the current date/time is ', **kwargs)
Bases: ConversableAgent
A simple agent that returns the current time.
Use it is as a reference for creating new agents with a reply-based approach (as opposed to tool-based).
This agent will return the date and time whenever it needs to reply.
Initialize the TimeReplyAgent.
PARAMETER | DESCRIPTION |
---|---|
date_time_format | The format in which the date and time should be returned. TYPE: |
output_prefix | The prefix to add to the output message. TYPE: |
**kwargs | Additional parameters to pass to the base TYPE: |
Source code in autogen/agents/contrib/time/time_reply_agent.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
#
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
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 2806 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 |
|
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
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 2880 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 |
|
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
1384 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 |
|
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
1538 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 |
|
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
1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 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 |
|
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
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 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 |
|
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
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
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
2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 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 |
|
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
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 2666 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 |
|
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
3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 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 |
|
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
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 3181 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 |
|
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
3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 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 |
|
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.