DiscordAgent
autogen.agents.experimental.DiscordAgent #
DiscordAgent(name, system_message=None, *, bot_token, channel_name, guild_name, has_writing_instructions=True, **kwargs)
Bases: ConversableAgent
An agent that can send messages and retrieve messages on Discord.
Initialize the DiscordAgent.
PARAMETER | DESCRIPTION |
---|---|
name | name of the agent. TYPE: |
system_message | system message for the ChatCompletion inference. |
bot_token | Discord bot token TYPE: |
channel_name | Channel name where messages will be sent / retrieved TYPE: |
guild_name | Guild (server) name where the channel is located 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/discord/discord.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 Discord. Remember that Discord uses Markdown for formatting and has a character limit. 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
2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 |
|
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
2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 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 |
|
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 max_consecutive_auto_reply which is the maximum number of consecutive auto replies; and it is also different from max_rounds in GroupChat which is the maximum number of rounds in a group chat session. If max_turns is set to None, the chat will continue until a termination condition is met. Default is None. 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
1375 1376 1377 1378 1379 1380 1381 1382 1383 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 |
|
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
1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 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 |
|
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
a_initiate_chats async
#
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
2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 |
|
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
2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 |
|
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
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 |
|
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
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 2806 2807 2808 2809 2810 |
|
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. |
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: |
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: |
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: |
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
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 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 |
|
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). |
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.
Source code in autogen/agentchat/conversable_agent.py
get_actual_usage #
get_total_usage #
run #
run(message, *, tools=None, executor_kwargs=None, max_turns=None, msg_to='agent', clear_history=False, user_input=True, summary_method=DEFAULT_SUMMARY_METHOD)
Run a chat with the agent using the given message.
A second agent will be created to represent the user, this agent will by known by the name 'user'. This agent does not have code execution enabled by default, if needed pass the code execution config in with the executor_kwargs parameter.
The user can terminate the conversation when prompted or, if agent's reply contains 'TERMINATE', it will terminate.
PARAMETER | DESCRIPTION |
---|---|
message | the message to be processed. TYPE: |
tools | the tools to be used by the agent. |
executor_kwargs | the keyword arguments for the executor. |
max_turns | maximum number of turns (a turn is equivalent to both agents having replied), defaults no None which means unlimited. The original message is included. |
msg_to | which agent is receiving the message and will be the first to reply, defaults to the agent. TYPE: |
clear_history | whether to clear the chat history. TYPE: |
user_input | the user will be asked for input at their turn. TYPE: |
summary_method | the method to summarize the chat. TYPE: |
Source code in autogen/agentchat/conversable_agent.py
a_run async
#
a_run(message, *, tools=None, executor_kwargs=None, max_turns=None, msg_to='agent', clear_history=False, user_input=True, summary_method=DEFAULT_SUMMARY_METHOD)
Run a chat asynchronously with the agent using the given message.
A second agent will be created to represent the user, this agent will by known by the name 'user'.
The user can terminate the conversation when prompted or, if agent's reply contains 'TERMINATE', it will terminate.
PARAMETER | DESCRIPTION |
---|---|
message | the message to be processed. TYPE: |
tools | the tools to be used by the agent. |
executor_kwargs | the keyword arguments for the executor. |
max_turns | maximum number of turns (a turn is equivalent to both agents having replied), defaults no None which means unlimited. The original message is included. |
msg_to | which agent is receiving the message and will be the first to reply, defaults to the agent. TYPE: |
clear_history | whether to clear the chat history. TYPE: |
user_input | the user will be asked for input at their turn. TYPE: |
summary_method | the method to summarize the chat. TYPE: |