Skip to content
forked from ag2ai/ag2

AG2 (formerly AutoGen): The Open-Source AgentOS. Join us at: https://discord.gg/pAbnFJrkgZ

License

Notifications You must be signed in to change notification settings

sitloboi2012/ag2

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation



πŸ“š Documentation | πŸ’‘ Examples | 🀝 Contributing | πŸ“ Cite paper | πŸ’¬ Join Discord

AG2 was evolved from AutoGen. Fully open-sourced. We invite collaborators from all organizations to contribute.

AG2: Open-Source AgentOS for AI Agents

AG2 (formerly AutoGen) is an open-source programming framework for building AI agents and facilitating cooperation among multiple agents to solve tasks. AG2 aims to streamline the development and research of agentic AI. It offers features such as agents capable of interacting with each other, facilitates the use of various large language models (LLMs) and tool use support, autonomous and human-in-the-loop workflows, and multi-agent conversation patterns.

The project is currently maintained by a dynamic group of volunteers from several organizations. Contact project administrators Chi Wang and Qingyun Wu via [email protected] if you are interested in becoming a maintainer.

Table of contents

Getting started

For a step-by-step walk through of AG2 concepts and code, see Basic Concepts in our documentation.

Installation

AG2 requires Python version >= 3.9, < 3.14. AG2 is available via ag2 (or its alias pyautogen or autogen) on PyPI.

pip install ag2

Minimal dependencies are installed by default. You can install extra options based on the features you need.

Setup your API keys

To keep your LLM dependencies neat we recommend using the OAI_CONFIG_LIST file to store your API keys.

You can use the sample file OAI_CONFIG_LIST_sample as a template.

[
  {
    "model": "gpt-4o",
    "api_key": "<your OpenAI API key here>"
  }
]

Run your first agent

Create a script or a Jupyter Notebook and run your first agent.

from autogen import AssistantAgent, UserProxyAgent, config_list_from_json

llm_config = {
    "config_list": config_list_from_json(env_or_file="OAI_CONFIG_LIST")
}

assistant = AssistantAgent("assistant", llm_config=llm_config)
user_proxy = UserProxyAgent("user_proxy", code_execution_config={"work_dir": "coding", "use_docker": False})
user_proxy.initiate_chat(assistant, message="Plot a chart of NVDA and TESLA stock price change YTD.")
# This initiates an automated chat between the two agents to solve the task

Example applications

We maintain a dedicated repository with a wide range of applications to help you get started with various use cases or check out our collection of jupyter notebooks as a starting point.

Introduction of different agent concepts

We have several agent concepts in AG2 to help you build your AI agents. We introduce the most common ones here.

  • Conversable Agent: Agents that are able to send messages, receive messages and generate replies using GenAI models, non-GenAI tools, or human inputs.
  • Human in the loop: Add human input to the conversation
  • Orchestrating multiple agents: Users can orchestrate multiple agents with built-in conversation patterns such as swarms, group chats, nested chats, sequential chats or customize the orchestration by registering custom reply methods.
  • Tools: Programs that can be registered, invoked and executed by agents
  • Advanced Concepts: AG2 supports more concepts such as structured outputs, rag, code execution, etc.

Conversable agent

The conversable agent is the most used agent and is created for generating conversations among agents. It serves as a base class for all agents in AG2.

from autogen import ConversableAgent

# Create an AI agent
assistant = ConversableAgent(
    name="assistant",
    system_message="You are an assistant that responds concisely.",
    llm_config=llm_config
)

# Create another AI agent
fact_checker = ConversableAgent(
    name="fact_checker",
    system_message="You are a fact-checking assistant.",
    llm_config=llm_config
)

# Start the conversation
assistant.initiate_chat(
    recipient=fact_checker,
    message="What is AG2?",
    max_turns=2
)

Human in the loop

Sometimes your wished workflow requires human input. Therefore you can enable the human in the loop feature.

If you set human_input_mode to ALWAYS on ConversableAgent you can give human input to the conversation.

There are three modes for human_input_mode: ALWAYS, NEVER, TERMINATE.

We created a class which sets the human_input_mode to ALWAYS for you. Its called UserProxyAgent.

from autogen import ConversableAgent

# Create an AI agent
assistant = ConversableAgent(
    name="assistant",
    system_message="You are a helpful assistant.",
    llm_config=llm_config
)

# Create a human agent with manual input mode
human = ConversableAgent(
    name="human",
    human_input_mode="ALWAYS"
)
# or
human = UserProxyAgent(name="human", code_execution_config={"work_dir": "coding", "use_docker": False})

# Start the chat
human.initiate_chat(
    recipient=assistant,
    message="Hello! What's 2 + 2?"
)

Orchestrating multiple agents

Users can define their own orchestration patterns using the flexible programming interface from AG2.

Additionally AG2 provides multiple built-in patterns to orchestrate multiple agents, such as GroupChat and Swarm.

Both concepts are used to orchestrate multiple agents to solve a task.

The group chat works like a chat where each registered agent can participate in the conversation.

from autogen import ConversableAgent, GroupChat, GroupChatManager

# Create AI agents
teacher = ConversableAgent(name="teacher", system_message="You suggest lesson topics.")
planner = ConversableAgent(name="planner", system_message="You create lesson plans.")
reviewer = ConversableAgent(name="reviewer", system_message="You review lesson plans.")

# Create GroupChat
groupchat = GroupChat(agents=[teacher, planner, reviewer], speaker_selection_method="auto")

# Create the GroupChatManager, it will manage the conversation and uses an LLM to select the next agent
manager = GroupChatManager(name="manager", groupchat=groupchat)

# Start the conversation
teacher.initiate_chat(manager, "Create a lesson on photosynthesis.")

The swarm requires a more rigid structure and the flow needs to be defined with hand-off, post-tool, and post-work transitions from an agent to another agent.

Read more about it in the documentation

Tools

Agents gain significant utility through tools as they provide access to external data, APIs, and functionality.

from datetime import datetime
from typing import Annotated

from autogen import ConversableAgent, register_function

# 1. Our tool, returns the day of the week for a given date
def get_weekday(date_string: Annotated[str, "Format: YYYY-MM-DD"]) -> str:
    date = datetime.strptime(date_string, "%Y-%m-%d")
    return date.strftime("%A")

# 2. Agent for determining whether to run the tool
date_agent = ConversableAgent(
    name="date_agent",
    system_message="You get the day of the week for a given date.",
    llm_config=llm_config,
)

# 3. And an agent for executing the tool
executor_agent = ConversableAgent(
    name="executor_agent",
    human_input_mode="NEVER",
)

# 4. Registers the tool with the agents, the description will be used by the LLM
register_function(
    get_weekday,
    caller=date_agent,
    executor=executor_agent,
    description="Get the day of the week for a given date",
)

# 5. Two-way chat ensures the executor agent follows the suggesting agent
chat_result = executor_agent.initiate_chat(
    recipient=date_agent,
    message="I was born on the 25th of March 1995, what day was it?",
    max_turns=1,
)

Advanced agentic design patterns

AG2 supports more advanced concepts to help you build your AI agent workflows. You can find more information in the documentation.

Announcements

πŸ”₯ πŸŽ‰ Nov 11, 2024: We are evolving AutoGen into AG2! A new organization AG2AI is created to host the development of AG2 and related projects with open governance. Check AG2's new look.

πŸ“„ License: We adopt the Apache 2.0 license from v0.3. This enhances our commitment to open-source collaboration while providing additional protections for contributors and users alike.

πŸŽ‰ May 29, 2024: DeepLearning.ai launched a new short course AI Agentic Design Patterns with AutoGen, made in collaboration with Microsoft and Penn State University, and taught by AutoGen creators Chi Wang and Qingyun Wu.

πŸŽ‰ May 24, 2024: Foundation Capital published an article on Forbes: The Promise of Multi-Agent AI and a video AI in the Real World Episode 2: Exploring Multi-Agent AI and AutoGen with Chi Wang.

πŸŽ‰ Apr 17, 2024: Andrew Ng cited AutoGen in The Batch newsletter and What's next for AI agentic workflows at Sequoia Capital's AI Ascent (Mar 26).

More Announcements

Contributors Wall

Code style and linting

This project uses pre-commit hooks to maintain code quality. Before contributing:

  1. Install pre-commit:
pip install pre-commit
pre-commit install
  1. The hooks will run automatically on commit, or you can run them manually:
pre-commit run --all-files

Related papers

Cite the project

@software{AG2_2024,
author = {Chi Wang and Qingyun Wu and the AG2 Community},
title = {AG2: Open-Source AgentOS for AI Agents},
year = {2024},
url = {https://github.com/ag2ai/ag2},
note = {Available at https://docs.ag2.ai/},
version = {latest}
}

License

This project is licensed under the Apache License, Version 2.0 (Apache-2.0).

This project is a spin-off of AutoGen and contains code under two licenses:

We have documented these changes for clarity and to ensure transparency with our user and contributor community. For more details, please see the NOTICE file.

About

AG2 (formerly AutoGen): The Open-Source AgentOS. Join us at: https://discord.gg/pAbnFJrkgZ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Jupyter Notebook 40.2%
  • Python 38.6%
  • MDX 19.5%
  • CSS 1.1%
  • Mako 0.2%
  • Jinja 0.2%
  • Other 0.2%