
ControlFlow เป็นเฟรมเวิร์ก Python สำหรับการสร้างเวิร์กโฟลว์ AIS ATHIC
ControlFlow จัดเตรียมกรอบการทำงานที่มีโครงสร้างและมุ่งเน้นไปที่การกำหนดเวิร์กโฟลว์และมอบหมายงานให้กับ LLM โดยไม่ต้องเสียสละการควบคุมหรือความโปร่งใส:
เวิร์กโฟลว์การควบคุมที่ง่ายที่สุดมีงานหนึ่งงานตัวแทนเริ่มต้นและการจัดการเธรดอัตโนมัติ:
import controlflow as cf
result = cf . run ( "Write a short poem about artificial intelligence" )
print ( result )ผลลัพธ์:
In circuits and code, a mind does bloom,
With algorithms weaving through the gloom.
A spark of thought in silicon's embrace,
Artificial intelligence finds its place.
ControlFlow กล่าวถึงความท้าทายในการสร้างแอปพลิเคชันที่ขับเคลื่อนด้วย AI ซึ่งมีประสิทธิภาพและคาดการณ์ได้:
ติดตั้ง ControlFlow ด้วย pip :
pip install controlflow ถัดไปกำหนดค่าผู้ให้บริการ LLM ของคุณ ผู้ให้บริการเริ่มต้นของ ControlFlow คือ OpenAI ซึ่งต้องใช้ตัวแปรสภาพแวดล้อม OPENAI_API_KEY :
export OPENAI_API_KEY=your-api-key
หากต้องการใช้ผู้ให้บริการ LLM อื่นดูเอกสารการกำหนดค่า LLM
นี่คือตัวอย่างที่เกี่ยวข้องมากขึ้นซึ่งแสดงให้เห็นถึงการโต้ตอบของผู้ใช้เวิร์กโฟลว์หลายขั้นตอนและเอาต์พุตที่มีโครงสร้าง:
import controlflow as cf
from pydantic import BaseModel
class ResearchProposal ( BaseModel ):
title : str
abstract : str
key_points : list [ str ]
@ cf . flow
def research_proposal_flow ():
# Task 1: Get the research topic from the user
user_input = cf . Task (
"Work with the user to choose a research topic" ,
interactive = True ,
)
# Task 2: Generate a structured research proposal
proposal = cf . run (
"Generate a structured research proposal" ,
result_type = ResearchProposal ,
depends_on = [ user_input ]
)
return proposal
result = research_proposal_flow ()
print ( result . model_dump_json ( indent = 2 ))การสนทนา:
Agent: Hello! I'm here to help you choose a research topic. Do you have any particular area of interest or field you would like to explore? If you have any specific ideas or requirements, please share them as well. User: Yes, I'm interested in LLM agentic workflowsข้อเสนอ:
{ "title" : " AI Agentic Workflows: Enhancing Efficiency and Automation " , "abstract" : " This research proposal aims to explore the development and implementation of AI agentic workflows to enhance efficiency and automation in various domains. AI agents, equipped with advanced capabilities, can perform complex tasks, make decisions, and interact with other agents or humans to achieve specific goals. This research will investigate the underlying technologies, methodologies, and applications of AI agentic workflows, evaluate their effectiveness, and propose improvements to optimize their performance. " , "key_points" : [ " Introduction: Definition and significance of AI agentic workflows, Historical context and evolution of AI in workflows " , " Technological Foundations: AI technologies enabling agentic workflows (e.g., machine learning, natural language processing), Software and hardware requirements for implementing AI workflows " , " Methodologies: Design principles for creating effective AI agents, Workflow orchestration and management techniques, Interaction protocols between AI agents and human operators " , " Applications: Case studies of AI agentic workflows in various industries (e.g., healthcare, finance, manufacturing), Benefits and challenges observed in real-world implementations " , " Evaluation and Metrics: Criteria for assessing the performance of AI agentic workflows, Metrics for measuring efficiency, accuracy, and user satisfaction " , " Proposed Improvements: Innovations to enhance the capabilities of AI agents, Strategies for addressing limitations and overcoming challenges " , " Conclusion: Summary of key findings, Future research directions and potential impact on industry and society " ] }
ในตัวอย่างนี้ ControlFlow จะจัดการ flow โดยอัตโนมัติหรือบริบทที่ใช้ร่วมกันสำหรับชุดของงาน คุณสามารถสลับระหว่างฟังก์ชั่น Python มาตรฐานและงานตัวแทนได้ตลอดเวลาทำให้ง่ายต่อการสร้างเวิร์กโฟลว์ที่ซับซ้อน
เพื่อดำน้ำลึกลงไปในการควบคุม: