Autogen4j: the Java version of Microsoft AutoGen

简介: Java version of Microsoft AutoGen, Enable Next-Gen Large Language Model Applications

https://github.com/HamaWhiteGG/autogen4j

Java version of Microsoft AutoGen, Enable Next-Gen Large Language Model Applications.

1. What is AutoGen

AutoGen is a framework that enables the development of LLM applications using multiple agents that can converse with each other to solve tasks. AutoGen agents are customizable, conversable, and seamlessly allow human participation. They can operate in various modes that employ combinations of LLMs, human inputs, and tools.

autogen_agentchat.png

The following example in the [autogen4j-example].

  • [Auto Feedback From Code Execution Example]
  • [Group Chat Example]

2. Quickstart

2.1 Maven Repository

Prerequisites for building:

  • Java 17 or later
  • Unix-like environment (we use Linux, Mac OS X)
  • Maven (we recommend version 3.8.6 and require at least 3.5.4)

Maven Central

<dependency>
    <groupId>io.github.hamawhitegg</groupId>
    <artifactId>autogen4j-core</artifactId>
    <version>0.1.0</version>
</dependency>

2.2 Environment Setup

Using Autogen4j requires OpenAI's APIs, you need to set the environment variable.

export OPENAI_API_KEY=xxx

3. Multi-Agent Conversation Framework

Autogen enables the next-gen LLM applications with a generic multi-agent conversation framework. It offers customizable and conversable agents that integrate LLMs, tools, and humans.
By automating chat among multiple capable agents, one can easily make them collectively perform tasks autonomously or with human feedback, including tasks that require using tools via code.

Features of this use case include:

  • Multi-agent conversations: AutoGen agents can communicate with each other to solve tasks. This allows for more complex and sophisticated applications than would be possible with a single LLM.
  • Customization: AutoGen agents can be customized to meet the specific needs of an application. This includes the ability to choose the LLMs to use, the types of human input to allow, and the tools to employ.
  • Human participation: AutoGen seamlessly allows human participation. This means that humans can provide input and feedback to the agents as needed.

3.1 Auto Feedback From Code Execution Example

[Auto Feedback From Code Execution Example]

// create an AssistantAgent named "assistant"
var assistant = AssistantAgent.builder()
        .name("assistant")
        .build();

var codeExecutionConfig = CodeExecutionConfig.builder()
        .workDir("data/coding")
        .build();
// create a UserProxyAgent instance named "user_proxy"
var userProxy = UserProxyAgent.builder()
        .name("user_proxy")
        .humanInputMode(NEVER)
        .maxConsecutiveAutoReply(10)
        .isTerminationMsg(e -> e.getContent().strip().endsWith("TERMINATE"))
        .codeExecutionConfig(codeExecutionConfig)
        .build();

// the assistant receives a message from the user_proxy, which contains the task description
userProxy.initiateChat(assistant,
        "What date is today? Compare the year-to-date gain for META and TESLA.");

// followup of the previous question
userProxy.send(assistant,
        "Plot a chart of their stock price change YTD and save to stock_price_ytd.png.");

The figure below shows an example conversation flow with Autogen4j.
chat_example.png

After running, you can check the file [coding_output.log]for the output logs.

The final output is as shown in the following picture.
stock_price_ytd.png

3.2 Group Chat Example

[Group Chat Example]

var codeExecutionConfig = CodeExecutionConfig.builder()
        .workDir("data/group_chat")
        .lastMessagesNumber(2)
        .build();

// create a UserProxyAgent instance named "user_proxy"
var userProxy = UserProxyAgent.builder()
        .name("user_proxy")
        .systemMessage("A human admin.")
        .humanInputMode(TERMINATE)
        .codeExecutionConfig(codeExecutionConfig)
        .build();

// create an AssistantAgent named "coder"
var coder = AssistantAgent.builder()
        .name("coder")
        .build();

// create an AssistantAgent named "pm"
var pm = AssistantAgent.builder()
        .name("product_manager")
        .systemMessage("Creative in software product ideas.")
        .build();

var groupChat = GroupChat.builder()
        .agents(List.of(userProxy, coder, pm))
        .maxRound(12)
        .build();

// create an GroupChatManager named "manager"
var manager = GroupChatManager.builder()
        .groupChat(groupChat)
        .build();

userProxy.initiateChat(manager,
        "Find a latest paper about gpt-4 on arxiv and find its potential applications in software.");

After running, you can check the file [group_chat_output.log] for the output logs.

4. Run Test Cases from Source

git clone https://github.com/HamaWhiteGG/autogen4j.git
cd autogen4j

# export JAVA_HOME=JDK17_INSTALL_HOME && mvn clean test
mvn clean test

This project uses Spotless to format the code.
If you make any modifications, please remember to format the code using the following command.

# export JAVA_HOME=JDK17_INSTALL_HOME && mvn spotless:apply
mvn spotless:apply

5. Support

Don’t hesitate to ask!

Open an issue if you find a bug or need any help.

相关文章
|
6月前
|
Java
Project facet Java version 1.8 is not supported解决记录
Project facet Java version 1.8 is not supported解决记录
74 1
|
6月前
|
Java
ElasticSearch启动报错 java version is an early-access build ,only use release builds【已解决】
ElasticSearch启动报错 java version is an early-access build ,only use release builds【已解决】
70 0
|
Scala 开发工具 流计算
Flink / Scala - java.lang.NumberFormatException: Not a version: 9
Flink V1.13.1 +Scala 2.11.8 提交任务后,报错Caused by: org.apache.flink.shaded.guava18.com.google.common.util.concurrent.UncheckedExecutionException: java.lang.NumberFormatException: Not a version: 9 ,遂排查与解决。
369 0
Flink / Scala - java.lang.NumberFormatException: Not a version: 9
解决Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 62问题~
解决Caused by: java.lang.IllegalArgumentException: Unsupported class file major version 62问题~
186 0
|
Oracle Java 关系型数据库
输入java -version 命令行没反应的简单解决办法【亲测有效】
输入java -version 命令行没反应的简单解决办法【亲测有效】
1028 0
|
Java 编译器 Android开发
解决java compiler level does not match the version of the installed java project facet
解决java compiler level does not match the version of the installed java project facet
|
开发框架 Java 应用服务中间件
eclipse中Tomcat version 9.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5, 6, 7, and 8 Web modules
eclipse中Tomcat version 9.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5, 6, 7, and 8 Web modules
431 0
|
Java 应用服务中间件 Android开发
Description Resource Path LocationType Java compiler level does not match the version of the instal
Description Resource Path LocationType Java compiler level does not match the version of the instal
205 0
Description Resource Path LocationType Java compiler level does not match the version of the instal
|
Java
解决办法:Could not determine java version from ‘11.0.8‘.
解决办法:Could not determine java version from ‘11.0.8‘.
409 0
解决办法:Could not determine java version from ‘11.0.8‘.