はじめに
Dynamiqは、エージェントAIと大規模言語モデリング(LLM)アプリケーションのために設計されたオープンソースのAIオーケストレーションフレームワークです。Dynamiqは、特にRAG(Retrieval Augmented Generation)とLLMエージェントのオーケストレーションの分野で、AI駆動型アプリケーションの開発を簡素化することを目的としています。Dynamiqは、開発者が迅速に開始し、複雑なAIアプリケーションを効率的に構築できるように、豊富な機能モジュールと詳細なドキュメントを提供します。
特性
Dynamiqは、LLMの推論能力(脳)と具体的な行動を実行する能力(手)を組み合わせることで、AIが現実世界の問題を解決することを可能にする革新的なAIフレームワークである。
// リ・アクトの定義:
- リ・アクト は、LLMの推論能力と演算能力を組み合わせたフレームワークである。
- AIが現実世界を理解し、計画し、相互作用することを可能にする。
// ReActエージェントの働き
これは2つの重要な要素を統合している:
- 頭脳(LLMが提供する思考力)
- 手(オペレーション能力)
// フレームワークのコンポーネント:
- タスク
- エージェント(LLMとツールを含むインテリジェンス)
- 環境
- 応答
// 実用例:
著者らは、傘が必要かどうかを判断するシナリオで、ReActエージェントのワークフローを説明している:
- 傘を持ってくる必要があるかどうかを尋ねるタスクをユーザーから受け取る
- 天気予報をチェックするツールを使う
- 推論分析を行う
- 推奨される回答を挙げる
Akshayによって共有された// Dynamiqフレームワーク:
Dynamiqは、AIアプリケーションの開発プロセスを合理化することに焦点を当てた次世代AI開発のための包括的なフレームワークであり、以下のような主要な機能を備えています。 ラグ とLLMのエージェント・システム。
// 主な特徴
オールインワン:AIアプリケーションの開発に必要なすべてのツールと機能を統合したワンストップ(「オールインワン」)フレームワーク。
専門分野
- RAGシステムの組織
- LLMエージェントの管理
- AIアプリケーションの開発プロセス最適化
ポジショニング:
- オーケストレーション・フレームワークとして機能し、個々のAIコンポーネントの調整と管理に焦点を当てる。
- エージェント型AIアプリケーションの開発
- AIアプリを構築する際の開発者の複雑さを単純化する
機能一覧
- インストールと設定Python環境をサポートする詳細なインストールガイドを提供します。
- ドキュメントと実例豊富なドキュメントとサンプルコードで、すぐに使い始めることができます。
- シンプルなLLMプロセスシンプルなLLMワークフローの例を提供することで、簡単に理解し、使用することができます。
- リアクト・エージェント統合されたE2Bコードインタプリタにより、複雑なコーディング作業をサポートするエージェントです。
- マルチエージェントスケジューリングマルチエージェントの協力と複雑なタスクの解決をサポートします。
- RAGドキュメントの索引付けと検索PDF 文書の前処理、 ベ ク ト ル埋め込み、 格納をサポー ト し 、 関連文書の検索や質問応答をサポー ト し ます。
- メモリー付きチャットボット会話履歴の保存と検索をサポートするシンプルなチャットボット。
ヘルプの使用
インストールと設定
- PythonのインストールコンピュータにPythonがインストールされていることを確認してください。
- Dynamiqのインストール::
pip install dynamiq
あるいはソースコードからビルドする:
git clone https://github.com/dynamiq-ai/dynamiq.git cd dynamiq poetry install
使用例
シンプルなLLMプロセス
以下はシンプルなLLMワークフローの例である:
from dynamiq.nodes.llms.openai import OpenAI
from dynamiq.connections import OpenAI as OpenAIConnection
from dynamiq import Workflow
from dynamiq.prompts import Prompt, Message
# 定义翻译提示模板
prompt_template = """
Translate the following text into English: {{ text }}
"""
prompt = Prompt(messages=[Message(content=prompt_template, role="user")])
# 设置LLM节点
llm = OpenAI(
id="openai",
connection=OpenAIConnection(api_key="$OPENAI_API_KEY"),
model="gpt-4o",
temperature=0.3,
max_tokens=1000,
prompt=prompt
)
# 创建工作流对象
workflow = Workflow()
workflow.flow.add_nodes(llm)
# 运行工作流
result = workflow.run(input_data={"text": "Hola Mundo!"})
print(result.output)
リアクト・エージェント
以下は、複雑なコーディング作業をサポートするReActエージェントの例です:
from dynamiq.nodes.llms.openai import OpenAI
from dynamiq.connections import OpenAI as OpenAIConnection, E2B as E2BConnection
from dynamiq.nodes.agents.react import ReActAgent
from dynamiq.nodes.tools.e2b_sandbox import E2BInterpreterTool
# 初始化E2B工具
e2b_tool = E2BInterpreterTool(connection=E2BConnection(api_key="$API_KEY"))
# 设置LLM
llm = OpenAI(
id="openai",
connection=OpenAIConnection(api_key="$API_KEY"),
model="gpt-4o",
temperature=0.3,
max_tokens=1000,
)
# 创建ReAct代理
agent = ReActAgent(
name="react-agent",
llm=llm,
tools=[e2b_tool],
role="Senior Data Scientist",
max_loops=10,
)
# 运行代理
result = agent.run(input_data={"input": "Add the first 10 numbers and tell if the result is prime."})
print(result.output.get("content"))
マルチエージェントスケジューリング
以下は、複数のエージェントが協力する例である:
from dynamiq.connections import OpenAI as OpenAIConnection, ScaleSerp as ScaleSerpConnection, E2B as E2BConnection
from dynamiq.nodes.llms import OpenAI
from dynamiq.nodes.agents.orchestrators.adaptive import AdaptiveOrchestrator
from dynamiq.nodes.agents.orchestrators.adaptive_manager import AdaptiveAgentManager
from dynamiq.nodes.agents.react import ReActAgent
from dynamiq.nodes.agents.reflection import ReflectionAgent
from dynamiq.nodes.tools.e2b_sandbox import E2BInterpreterTool
from dynamiq.nodes.tools.scale_serp import ScaleSerpTool
# 初始化工具
python_tool = E2BInterpreterTool(connection=E2BConnection(api_key="$E2B_API_KEY"))
search_tool = ScaleSerpTool(connection=ScaleSerpConnection(api_key="$SCALESERP_API_KEY"))
# 初始化LLM
llm = OpenAI(connection=OpenAIConnection(api_key="$OPENAI_API_KEY"), model="gpt-4o", temperature=0.1)
# 定义代理
coding_agent = ReActAgent(
name="coding-agent",
llm=llm,
tools=[python_tool],
role="Expert agent with coding skills. Goal is to provide the solution to the input task using Python software engineering skills.",
max_loops=15,
)
planner_agent = ReflectionAgent(
name="planner-agent",
llm=llm,
role="Expert agent with planning skills. Goal is to analyze complex requests and provide a detailed action plan.",
)
search_agent = ReActAgent(
name="search-agent",
llm=llm,
tools=[search_tool],
role="Expert agent with web search skills. Goal is to provide the solution to the input task using web search and summarization skills.",
max_loops=10,
)
# 初始化自适应代理管理器
agent_manager = AdaptiveAgentManager(llm=llm)
# 创建编排器
orchestrator = AdaptiveOrchestrator(
name="adaptive-orchestrator",
agents=[coding_agent, planner_agent, search_agent],
manager=agent_manager,
)
# 定义输入任务
input_task = (
"Use coding skills to gather data about Nvidia and Intel stock prices for the last 10 years, "
"calculate the average per year for each company, and create a table. Then craft a report "
"and add a conclusion: what would have been better if I had invested $100 ten years ago?"
)
# 运行编排器
result = orchestrator.run(input_data={"input": input_task})
print(result.output.get("content"))
RAGドキュメントの索引付けと検索
DynamiqはRAG (Retrieval Augmentation Generation)をサポートしています:
- ドキュメントの前処理入力PDFファイルをベクトル埋め込みに変換し、ベクトルデータベースに格納します。
- 文書検索ユーザーのクエリに基づいて関連ドキュメントを取得し、回答を生成します。
以下はRAGワークフローの簡単な例である:
from io import BytesIO
from dynamiq import Workflow
from dynamiq.connections import OpenAI as OpenAIConnection, Pinecone as PineconeConnection
from dynamiq.nodes.converters import PyPDFConverter
from dynamiq.nodes.splitters.document import DocumentSplitter
from dynamiq.nodes.embedders import OpenAIDocumentEmbedder
from dynamiq.nodes.writers import PineconeDocumentWriter
# 初始化工作流
rag_wf = Workflow()
# PDF文档转换器
converter = PyPDFConverter(document_creation_mode="one-doc-per-page")
rag_wf.flow.add_nodes(converter)
# 文档拆分器
document_splitter = (
DocumentSplitter(split_by="sentence", split_length=10, split_overlap=1)
.inputs(documents=converter.outputs.documents)
.depends_on(converter)
)
rag_wf.flow.add_nodes(document_splitter)
# OpenAI向量嵌入
embedder = (
OpenAIDocumentEmbedder(connection=OpenAIConnection(api_key="$OPENAI_API_KEY"), model="text-embedding-3-small")
.inputs(documents=document_splitter.outputs.documents)
.depends_on(document_splitter)
)
rag_wf.flow.add_nodes(embedder)
# Pinecone向量存储
vector_store = (
PineconeDocumentWriter(connection=PineconeConnection(api_key="$PINECONE_API_KEY"), index_name="default", dimension=1536)
.inputs(documents=embedder.outputs.documents)
.depends_on(embedder)
)
rag_wf.flow.add_nodes(vector_store)
# 准备输入PDF文件
file_paths = ["example.pdf"]
input_data = {
"files": [BytesIO(open(path, "rb").read()) for path in file_paths],
"metadata": [{"filename": path} for path in file_paths],
}
# 运行RAG索引流程
rag_wf.run(input_data=input_data)
メモリー付きチャットボット
メモリ付きのシンプルなチャットボットの例です:
from dynamiq.connections import OpenAI as OpenAIConnection from dynamiq.memory import Memory from dynamiq.memory.backend.in_memory import InMemory from dynamiq.nodes.agents.simple import SimpleAgent from dynamiq.nodes.llms import OpenAI AGENT_ROLE = "helpful assistant, goal is to provide useful information and answer questions" llm = OpenAI( connection=OpenAIConnection(api_key="$OPENAI_API_KEY"), model="gpt-4o", temperature=0.1, ) memory = Memory(backend=InMemory()) agent = SimpleAgent( name="Agent", llm=llm, role=AGENT_ROLE, id="agent", memory=memory, ) def main(): print("Welcome to the AI Chat! (Type 'exit' to end)") while True: user_input = input("You: ") if user_input.lower() == "exit": break response = agent.run({"input": user_input}) response_content = response.output.get("content") print(f"AI: {response_content}") if __name__ == "__main__": main()