agentchat.utils
gather_usage_summary
Gather usage summary from all agents.
Arguments:
agents
- (list): List of agents.
Returns:
dictionary
- A dictionary containing two keys:- “usage_including_cached_inference”: Cost information on the total usage, including the tokens in cached inference.
- “usage_excluding_cached_inference”: Cost information on the usage of tokens, excluding the tokens in cache. No larger than “usage_including_cached_inference”.
Example:
Notes:
If none of the agents incurred any cost (not having a client), then the usage_including_cached_inference and usage_excluding_cached_inference will be \{'total_cost': 0}
.
parse_tags_from_content
Parses HTML style tags from message contents.
The parsing is done by looking for patterns in the text that match the format of HTML tags. The tag to be parsed is specified as an argument to the function. The function looks for this tag in the text and extracts its content. The content of a tag is everything that is inside the tag, between the opening and closing angle brackets. The content can be a single string or a set of attribute-value pairs.
Examples:
<img http://example.com/image.png> -> [{“tag”: “img”, “attr”: {“src”: “http://example.com/image.png”}, “match”: re.Match}] <audio text=“Hello I’m a robot” prompt=“whisper”> ->
[\{"tag"
- “audio”, “attr”: {“text”: “Hello I’m a robot”, “prompt”: “whisper”}, “match”: re.Match}]
Arguments:
tag
str - The HTML style tag to be parsed.content
Union[str, List[Dict[str, Any]]] - The message content to parse. Can be a string or a list of content items.
Returns:
List[Dict[str, str]]: A list of dictionaries, where each dictionary represents a parsed tag. Each dictionary contains three key-value pairs: ‘type’ which is the tag, ‘attr’ which is a dictionary of the parsed attributes, and ‘match’ which is a regular expression match object.
Raises:
ValueError
- If the content is not a string or a list.