MarkTechPost@AI 02月21日
Building an Ideation Agent System with AutoGen: Create AI Agents that Brainstorm and Debate Ideas
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文介绍了如何使用AutoGen和ChatGPT构建一个AI驱动的创意代理系统,该系统通过两个LLM代理进行协作,进行头脑风暴和辩论。文章详细讲解了AutoGen的关键组件,包括RoundRobinGroupChat、TextMentionTermination和AssistantAgent,这些组件共同创建了一个结构化的协作系统,使代理能够高效地进行头脑风暴、辩论并达成决策。此外,文章还提供了设置和安装步骤、构建代理团队的示例代码,以及如何运行和监控交互过程。最后,文章提出了增强系统的几个想法,例如添加领域专家代理、实施自定义终止条件以及使用Streamlit构建简单的UI。

💡AutoGen是一个用于构建多代理对话应用的框架,它允许创建可以相互交流以完成任务的代理。AutoGen的核心在于其能够协调多个智能体,使它们协同工作,从而解决复杂的问题。

🗣️RoundRobinGroupChat是AutoGen中的一个关键组件,用于管理团队中的代理。它以轮流的方式安排代理做出响应,并共享所有消息以提供上下文,确保结构化和公平的交互。

🛑TextMentionTermination通过检测特定关键词(例如“FINALIZE”)来停止对话。当代理达成共识或完成任务时,这对于结束讨论非常有用。在本文的例子中,当两个代理就一个想法达成一致时,就会触发终止条件。

🤖AssistantAgent代表一个由LLM驱动的团队成员,具有特定的角色。每个代理都由一个系统消息定义,该消息指导其行为。代理使用对话历史记录来生成上下文相关的响应。

Ideation processes often require time-consuming analysis and debate. What if we make two LLMs come up with ideas and then make them debate about those ideas? Sounds interesting right? This tutorial exactly shows how to create an AI-powered solution using two LLM agents that collaborate through structured conversation. For achieving this we will be using AutoGen for building the agent and ChatGPT as LLM for our agent.

1. Setup and Installation  

First install required packages:

pip install -U autogen-agentchatpip install autogen-ext[openai]

2. Core Components  

Let’s explore the key components of AutoGen that make this ideation system work. Understanding these components will help you customize and extend the system for your specific needs.

1. RoundRobinGroupChat

2. TextMentionTermination

3. AssistantAgent

These components work together to create a structured, collaborative system where agents brainstorm, debate, and reach decisions efficiently.

 3. Building the Agent Team  

Create two specialized agents with distinct roles:

import asynciofrom autogen_agentchat.agents import AssistantAgentfrom autogen_agentchat.base import TaskResultfrom autogen_agentchat.conditions import ExternalTermination, TextMentionTerminationfrom autogen_agentchat.teams import RoundRobinGroupChatfrom autogen_agentchat.ui import Consolefrom autogen_core import CancellationTokenfrom autogen_ext.models.openai import OpenAIChatCompletionClientfrom apikey import API_KEY# Create an OpenAI model client.model_client = OpenAIChatCompletionClient(    model="gpt-4o-mini",    api_key=API_KEY,)# Create the primary agent.primary_agent = AssistantAgent(    "participant1",    model_client=model_client,    system_message="You are a participant in an ideation and feedback session. You will be provided with a problem statement and asked to generate ideas. Your ideas will be\    reviwed by another participant and then you together will narrow down ideas by debating over them. Respond with 'FINALIZE' when you have a final idea.",)# Create the critic agent.critic_agent = AssistantAgent(    "participant2",    model_client=model_client,    system_message="You are a participant in an ideation and feedback session. Your teammate will be provide some ideas that you need to review with your \        teammate and narrow down ideas by debating over them. Respond with 'FINALIZE' when you have a final idea.",)# Define a termination condition that stops the task if the critic approves.text_termination = TextMentionTermination("FINALIZE")# Create a team with the primary and critic agents.team = RoundRobinGroupChat([primary_agent, critic_agent], termination_condition=text_termination)

4. Running the Team  

Execute with asynchronous processing:

result = await team.run(task="Generate ideas for an applications of AI in healthcare.")print(result)

5. Monitoring Interactions  

You can also track the debate in real-time:

# When running inside a script, use a async main function and call it from asyncio.run(...).await team.reset()  # Reset the team for a new task.async for message in team.run_stream(task="Generate ideas for an applications of AI in healthcare."):  # type: ignore    if isinstance(message, TaskResult):        print("Stop Reason:", message.stop_reason)    else:        print(message)

AutoGen also provides us with a function to visualize the interactions in a prettier ways using console function:

await team.reset()  # Reset the team for a new task.await Console(team.run_stream(task="Generate ideas for an applications of AI in healthcare."))  # Stream the messages to the console.

Now the system is complete. But there is a-lot to play around with, but I will leave that to you. Here are few ideas to enhance your system:

References: 

The post Building an Ideation Agent System with AutoGen: Create AI Agents that Brainstorm and Debate Ideas appeared first on MarkTechPost.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

AutoGen LLM AI代理 头脑风暴 协作
相关文章