talkingheads.multiagent

Init file for multiagent subpackage

class talkingheads.multiagent.Conversation(configuration)

Bases: MultiAgent

A special Multiagent setting where two agents carry a conversation

continue_conversation(prompt_1: str | None = None, prompt_2: str | None = None) Tuple[str]

Make another round of conversation. If prompt_1 or prompt_2 is given, the response is not used

Parameters:
  • prompt_1 (str, optional) – If set, this prompt will be used instead of the last response provided by head 2. Defaults to None.

  • prompt_2 (str, optional) – If set, this prompt will be used instead of the last response provided by head 1. Defaults to None.

Returns:

The responses of the respective chat bots.

Return type:

Tuple[str]

start_conversation(intro_prompt_1: str, intro_prompt_2: str, use_response_1: bool = True)

Starts a conversation between two heads

Parameters:
  • intro_prompt_1 (str) – The instruction of the first head.

  • intro_prompt_2 (str) – The instruction of the second head.

  • use_response_1 (bool) – If set, the first response returned by the first head will be appended to the end of the instruction of the second head.

Returns:

The responses of the respective chat bots.

Return type:

Tuple[str]

class talkingheads.multiagent.MultiAgent(configuration_path: str)

Bases: object

An interface to use multiple instances together.

aggregate(agents: str | List[str], prompt: str, responses: Dict[str, str], reset_before_agg: bool = True)

This function - Feeds all the responses into the selected agent(s) to aggregation,

  • Returns the response(s)

Some examples of the aggregation are: - Composing a new message

  • Selecting the best message

  • Selecting the worst message

  • Find the most reoccuring number

  • Check if all the responses are the semantically similar

Not all chat models can read lengthy inputs, remind your chat models to keep it short!

By default, it resets the conversation of aggregation agents, set reset_before_agg=False to disable this.

It is possible to select one agent or multiple agents for aggregation.

Parameters:
  • agents (List[str]) – The agents selected to aggregate responses.

  • prompt (str) – Aggregation prompt

  • responses (Dict[str, str]) – The responses in the dictionary form.

  • reset_before_agg (bool, optional) – If set, resets the chathead. Defaults to True.

broadcast(prompt: str, exclude: List[str] | None = None) Dict[str, str]

Interacts with the agent swarm and returns back the results, before interacting, the agents defined in the exclude list will be removed.

Parameters:
  • prompt (str) – The prompt to broadcast agents.

  • exclude (List[str], optional) – The list of agents to be excluded. Defaults to None.

Returns:

A dictionary contains the responses of each included agent.

Return type:

Dict[str, str]

broadcast_and_aggregate(prompt: str, agg_agents: str | List[str], agg_prompt: str, exclude_agg_agents=True, reset_before_agg=True) Dict[str, str]

This function - Broadcasts the prompt into the agent swarm,

  • Feeds all the responses into the selected agent(s) to aggregation,

  • Returns the response(s)

Not all chat models can read lengthy inputs, remind your chat models to keep it short! By default, it resets the conversation of aggregation agents, set reset_before_agg=False to disable this. By default, it excludes the aggregation agent from agent swarm to respond, set exclude_agg_agents=False if you want the aggregator to respond too. It is possible to select one agent for aggregation, or select more than one agent.

Parameters:
  • prompt (str) – The prompt to pass on model swarm.

  • agg_agents (str) – The agents to aggregate given responses

  • agg_prompt (str) – The prompt to pass on master head to apply the aggregation.

  • exclude_agg_agents (bool, optional) – If set, aggregation agents will only utilized in the aggregation step.

  • reset_before_agg (bool, optional) – If set, resets the chathead. Defaults to True.

Returns:

The responses of the broadcasting and aggregation steps.

Return type:

Tuple(Dict[str, str], Dict[str, str])

broadcast_and_vote(prompt: str, voting_prompt: str) Dict[str, str]

This function - Broadcasts the prompt to all agents.

  • Combines all responses and broadcast voting objective appended with the

    responses received from agents to select the best option.

  • Returns the results.

Parameters:
  • prompt (str) – The first prompt to be broadcasted to the agents

  • voting_prompt (str) – The voting objective to be broadcasted to the agents.

Returns:

The responses of the broadcasting and voting steps.

Return type:

Tuple(Dict[str, str], Dict[str, str])

static dictmap(lambda_func: Callable, dictionary: Dict) Dict[str, Any]

Takes a lambda function which accepts two parameters, and returns a dictionary based on this lambda function

Parameters:
  • executor (ThreadPoolExecutor) – Executer to carry parallel execution.

  • lambda_func (Callable) – the function to be applied each of dictionary items.

  • dictionary (Dict) – the dictionary of the the application.

Returns:

A dictionary in the form defined by lambda_func

Return type:

Dict[str, Any]

interact(head_name: str, prompt: str) str

interact with the given head

log_chat(client_name: str | None = None, prompt: str | None = None, response: str | None = None, regenerated: bool = False) bool

Log a chat interaction in the chat history.

Parameters:
  • prompt (str) – The user’s prompt to be logged.

  • response (str) – The response to the user’s prompt to be logged.

Returns:

True if the interaction is logged, False otherwise.

Return type:

bool

open_agent(client_name: str, config: Dict[str, str]) BaseBrowser

Open the given client

Parameters:
  • client_name (str) – The tag of the agent.

  • config (Dict[str, str]) – The config of the agent

Returns:

The agent object

Return type:

BaseBrowser

reset_agents(agents: List[str] | None = None) List[bool]

This function resets the conversations of the given agents. If the agents is empty, it resets all of them.

Note: Some chat bots doesn’t have reset feature.

Parameters:

agents (List[str], optional) – If given, only resets the given agents, if None, reset all agents. Defaults to None.

Returns:

The reset status of each agent

Return type:

List[bool]

save() bool

Saves the conversation.

set_save_path(save_path: str)

Sets the path to save the file

Parameters:

save_path (str) – The saving path