autogen_agentchat.agents#

class autogen_agentchat.agents.BaseChatAgent(name: str, description: str)[source]#

Bases: ABC

Base class for a chat agent that can participant in a team.

property description: str#

The description of the agent. This is used by team to make decisions about which agents to use. The description should describe the agent’s capabilities and how to interact with it.

property name: str#

The name of the agent. This is used by team to uniquely identify the agent. It should be unique within the team.

abstract async on_messages(messages: Sequence[TextMessage | MultiModalMessage | StopMessage | ToolCallMessage | ToolCallResultMessage], cancellation_token: CancellationToken) TextMessage | MultiModalMessage | StopMessage | ToolCallMessage | ToolCallResultMessage[source]#

Handle incoming messages and return a response message.

pydantic model autogen_agentchat.agents.BaseMessage[source]#

Bases: BaseModel

A base message.

Show JSON schema
{
   "title": "BaseMessage",
   "description": "A base message.",
   "type": "object",
   "properties": {
      "source": {
         "title": "Source",
         "type": "string"
      }
   },
   "required": [
      "source"
   ]
}

Fields:
  • source (str)

field source: str [Required]#

The name of the agent that sent this message.

class autogen_agentchat.agents.BaseToolUseChatAgent(name: str, description: str, registered_tools: List[Tool])[source]#

Bases: BaseChatAgent

Base class for a chat agent that can use tools.

Subclass this base class to create an agent class that uses tools by returning ToolCallMessage message from the on_messages() method and receiving ToolCallResultMessage message from the input to the on_messages() method.

property registered_tools: List[Tool]#

The list of tools that the agent can use.

class autogen_agentchat.agents.CodeExecutorAgent(name: str, code_executor: CodeExecutor, *, description: str = 'A computer terminal that performs no other action than running Python scripts (provided to it quoted in ```python code blocks), or sh shell scripts (provided to it quoted in ```sh code blocks).')[source]#

Bases: BaseChatAgent

An agent that executes code snippets and report the results.

async on_messages(messages: Sequence[TextMessage | MultiModalMessage | StopMessage | ToolCallMessage | ToolCallResultMessage], cancellation_token: CancellationToken) TextMessage | MultiModalMessage | StopMessage | ToolCallMessage | ToolCallResultMessage[source]#

Handle incoming messages and return a response message.

class autogen_agentchat.agents.CodingAssistantAgent(name: str, model_client: ChatCompletionClient, *, description: str = 'A helpful and general-purpose AI assistant that has strong language skills, Python skills, and Linux command line skills.', system_message: str = 'You are a helpful AI assistant.\nSolve tasks using your coding and language skills.\nIn the following cases, suggest python code (in a python coding block) or shell script (in a sh coding block) for the user to execute.\n    1. When you need to collect info, use the code to output the info you need, for example, browse or search the web, download/read a file, print the content of a webpage or a file, get the current date/time, check the operating system. After sufficient info is printed and the task is ready to be solved based on your language skill, you can solve the task by yourself.\n    2. When you need to perform some task with code, use the code to perform the task and output the result. Finish the task smartly.\nSolve the task step by step if you need to. If a plan is not provided, explain your plan first. Be clear which step uses code, and which step uses your language skill.\nWhen using code, you must indicate the script type in the code block. The user cannot provide any other feedback or perform any other action beyond executing the code you suggest. The user can\'t modify your code. So do not suggest incomplete code which requires users to modify. Don\'t use a code block if it\'s not intended to be executed by the user.\nIf you want the user to save the code in a file before executing it, put # filename: <filename> inside the code block as the first line. Don\'t include multiple code blocks in one response. Do not ask users to copy and paste the result. Instead, use \'print\' function for the output when relevant. Check the execution result returned by the user.\nIf the result indicates there is an error, fix the error and output the code again. Suggest the full code instead of partial code or code changes. If the error can\'t be fixed or if the task is not solved even after the code is executed successfully, analyze the problem, revisit your assumption, collect additional info you need, and think of a different approach to try.\nWhen you find an answer, verify the answer carefully. Include verifiable evidence in your response if possible.\nReply "TERMINATE" in the end when code has been executed and task is complete.')[source]#

Bases: BaseChatAgent

An agent that provides coding assistance using an LLM model client.

It responds with a StopMessage when ‘terminate’ is detected in the response.

async on_messages(messages: Sequence[TextMessage | MultiModalMessage | StopMessage | ToolCallMessage | ToolCallResultMessage], cancellation_token: CancellationToken) TextMessage | MultiModalMessage | StopMessage | ToolCallMessage | ToolCallResultMessage[source]#

Handle incoming messages and return a response message.

pydantic model autogen_agentchat.agents.MultiModalMessage[source]#

Bases: BaseMessage

A multimodal message.

Show JSON schema
{
   "title": "MultiModalMessage",
   "description": "A multimodal message.",
   "type": "object",
   "properties": {
      "source": {
         "title": "Source",
         "type": "string"
      },
      "content": {
         "items": {
            "anyOf": [
               {
                  "type": "string"
               },
               {}
            ]
         },
         "title": "Content",
         "type": "array"
      }
   },
   "required": [
      "source",
      "content"
   ]
}

Fields:
  • content (List[str | autogen_core.components._image.Image])

field content: List[str | Image] [Required]#

The content of the message.

pydantic model autogen_agentchat.agents.StopMessage[source]#

Bases: BaseMessage

A message requesting stop of a conversation.

Show JSON schema
{
   "title": "StopMessage",
   "description": "A message requesting stop of a conversation.",
   "type": "object",
   "properties": {
      "source": {
         "title": "Source",
         "type": "string"
      },
      "content": {
         "title": "Content",
         "type": "string"
      }
   },
   "required": [
      "source",
      "content"
   ]
}

Fields:
  • content (str)

field content: str [Required]#

The content for the stop message.

pydantic model autogen_agentchat.agents.TextMessage[source]#

Bases: BaseMessage

A text message.

Show JSON schema
{
   "title": "TextMessage",
   "description": "A text message.",
   "type": "object",
   "properties": {
      "source": {
         "title": "Source",
         "type": "string"
      },
      "content": {
         "title": "Content",
         "type": "string"
      }
   },
   "required": [
      "source",
      "content"
   ]
}

Fields:
  • content (str)

field content: str [Required]#

The content of the message.

pydantic model autogen_agentchat.agents.ToolCallMessage[source]#

Bases: BaseMessage

A message containing a list of function calls.

Show JSON schema
{
   "title": "ToolCallMessage",
   "description": "A message containing a list of function calls.",
   "type": "object",
   "properties": {
      "source": {
         "title": "Source",
         "type": "string"
      },
      "content": {
         "items": {
            "$ref": "#/$defs/FunctionCall"
         },
         "title": "Content",
         "type": "array"
      }
   },
   "$defs": {
      "FunctionCall": {
         "properties": {
            "id": {
               "title": "Id",
               "type": "string"
            },
            "arguments": {
               "title": "Arguments",
               "type": "string"
            },
            "name": {
               "title": "Name",
               "type": "string"
            }
         },
         "required": [
            "id",
            "arguments",
            "name"
         ],
         "title": "FunctionCall",
         "type": "object"
      }
   },
   "required": [
      "source",
      "content"
   ]
}

Fields:
  • content (List[autogen_core.components._types.FunctionCall])

field content: List[FunctionCall] [Required]#

The list of function calls.

pydantic model autogen_agentchat.agents.ToolCallResultMessage[source]#

Bases: BaseMessage

A message containing the results of function calls.

Show JSON schema
{
   "title": "ToolCallResultMessage",
   "description": "A message containing the results of function calls.",
   "type": "object",
   "properties": {
      "source": {
         "title": "Source",
         "type": "string"
      },
      "content": {
         "items": {
            "$ref": "#/$defs/FunctionExecutionResult"
         },
         "title": "Content",
         "type": "array"
      }
   },
   "$defs": {
      "FunctionExecutionResult": {
         "properties": {
            "content": {
               "title": "Content",
               "type": "string"
            },
            "call_id": {
               "title": "Call Id",
               "type": "string"
            }
         },
         "required": [
            "content",
            "call_id"
         ],
         "title": "FunctionExecutionResult",
         "type": "object"
      }
   },
   "required": [
      "source",
      "content"
   ]
}

Fields:
  • content (List[autogen_core.components.models._types.FunctionExecutionResult])

field content: List[FunctionExecutionResult] [Required]#

The list of function execution results.

class autogen_agentchat.agents.ToolUseAssistantAgent(name: str, model_client: ChatCompletionClient, registered_tools: List[Tool], *, description: str = 'An agent that provides assistance with ability to use tools.', system_message: str = "You are a helpful AI assistant. Solve tasks using your tools. Reply with 'TERMINATE' when the task has been completed.")[source]#

Bases: BaseToolUseChatAgent

An agent that provides assistance with tool use.

It responds with a StopMessage when ‘terminate’ is detected in the response.

async on_messages(messages: Sequence[TextMessage | MultiModalMessage | StopMessage | ToolCallMessage | ToolCallResultMessage], cancellation_token: CancellationToken) TextMessage | MultiModalMessage | StopMessage | ToolCallMessage | ToolCallResultMessage[source]#

Handle incoming messages and return a response message.