当前位置: 首页 > news >正文

AI Agents - 自动化项目:计划、评估和分配

Agents:

  • Role 角色
  • Goal 目标
  • Backstory 背景故事

Tasks:

  • Description 描述
  • Expected Output 期望输出
  • Agent 代理

Automated Project: Planning, Estimation, and Allocation

Initial Imports

1.本地文件helper.py

# Add your utilities or helper functions to this file.import os
from dotenv import load_dotenv, find_dotenvdef load_env():_ = load_dotenv(find_dotenv())def get_openai_api_key():load_env()openai_api_key = os.getenv("OPENAI_API_KEY")return openai_api_key

2. pip install crewai

3. 导入相应库

# Warning control
import warnings
warnings.filterwarnings('ignore')# Load environment variables
from helper import load_env
load_env()import os
import yaml
from crewai import Agent, Task, Crew

Set OpenAI Model

os.environ['OPENAI_MODEL_NAME'] = 'gpt-4o-mini'

Loading Tasks and Agents YAML files

# Define file paths for YAML configurations
files = {'agents': 'config/agents.yaml','tasks': 'config/tasks.yaml'
}# Load configurations from YAML files
configs = {}
for config_type, file_path in files.items():with open(file_path, 'r') as file:configs[config_type] = yaml.safe_load(file)# Assign loaded configurations to specific variables
agents_config = configs['agents']
tasks_config = configs['tasks']

Create Pydantic Models for Structured Output

from typing import List
from pydantic import BaseModel, Fieldclass TaskEstimate(BaseModel):task_name: str = Field(..., description="Name of the task")estimated_time_hours: float = Field(..., description="Estimated time to complete the task in hours")required_resources: List[str] = Field(..., description="List of resources required to complete the task")class Milestone(BaseModel):milestone_name: str = Field(..., description="Name of the milestone")tasks: List[str] = Field(..., description="List of task IDs associated with this milestone")class ProjectPlan(BaseModel):tasks: List[TaskEstimate] = Field(..., description="List of tasks with their estimates")milestones: List[Milestone] = Field(..., description="List of project milestones")

Create Crew, Agents and Tasks

# Creating Agents
project_planning_agent = Agent(config=agents_config['project_planning_agent']
)estimation_agent = Agent(config=agents_config['estimation_agent']
)resource_allocation_agent = Agent(config=agents_config['resource_allocation_agent']
)# Creating Tasks
task_breakdown = Task(config=tasks_config['task_breakdown'],agent=project_planning_agent
)time_resource_estimation = Task(config=tasks_config['time_resource_estimation'],agent=estimation_agent
)resource_allocation = Task(config=tasks_config['resource_allocation'],agent=resource_allocation_agent,output_pydantic=ProjectPlan # This is the structured output we want
)# Creating Crew
crew = Crew(agents=[project_planning_agent,estimation_agent,resource_allocation_agent],tasks=[task_breakdown,time_resource_estimation,resource_allocation],verbose=True
)

Crew's Inputs

from IPython.display import display, Markdownproject = 'Website'
industry = 'Technology'
project_objectives = 'Create a website for a small business'
team_members = """
- John Doe (Project Manager)
- Jane Doe (Software Engineer)
- Bob Smith (Designer)
- Alice Johnson (QA Engineer)
- Tom Brown (QA Engineer)
"""
project_requirements = """
- Create a responsive design that works well on desktop and mobile devices
- Implement a modern, visually appealing user interface with a clean look
- Develop a user-friendly navigation system with intuitive menu structure
- Include an "About Us" page highlighting the company's history and values
- Design a "Services" page showcasing the business's offerings with descriptions
- Create a "Contact Us" page with a form and integrated map for communication
- Implement a blog section for sharing industry news and company updates
- Ensure fast loading times and optimize for search engines (SEO)
- Integrate social media links and sharing capabilities
- Include a testimonials section to showcase customer feedback and build trust
"""# Format the dictionary as Markdown for a better display in Jupyter Lab
formatted_output = f"""
**Project Type:** {project}**Project Objectives:** {project_objectives}**Industry:** {industry}**Team Members:**
{team_members}
**Project Requirements:**
{project_requirements}
"""
# Display the formatted output as Markdown
display(Markdown(formatted_output))

Kicking off the crew

# The given Python dictionary
inputs = {'project_type': project,'project_objectives': project_objectives,'industry': industry,'team_members': team_members,'project_requirements': project_requirements
}# Run the crew
result = crew.kickoff(inputs=inputs
)

Usage Metrics and Costs

import pandas as pdcosts = 0.150 * (crew.usage_metrics.prompt_tokens + crew.usage_metrics.completion_tokens) / 1_000_000
print(f"Total costs: ${costs:.4f}")# Convert UsageMetrics instance to a DataFrame
df_usage_metrics = pd.DataFrame([crew.usage_metrics.dict()])
df_usage_metrics

Result

result.pydantic.dict()

Inspect further

tasks = result.pydantic.dict()['tasks']
df_tasks = pd.DataFrame(tasks)# Display the DataFrame as an HTML table
df_tasks.style.set_table_attributes('border="1"').set_caption("Task Details").set_table_styles([{'selector': 'th, td', 'props': [('font-size', '120%')]}]
)

Inspecting Milestones

milestones = result.pydantic.dict()['milestones']
df_milestones = pd.DataFrame(milestones)# Display the DataFrame as an HTML table
df_milestones.style.set_table_attributes('border="1"').set_caption("Task Details").set_table_styles([{'selector': 'th, td', 'props': [('font-size', '120%')]}]
)

相关文章:

AI Agents - 自动化项目:计划、评估和分配

Agents: Role 角色Goal 目标Backstory 背景故事 Tasks: Description 描述Expected Output 期望输出Agent 代理 Automated Project: Planning, Estimation, and Allocation Initial Imports 1.本地文件helper.py # Add your utilities or helper functions to…...

Git的.gitignore文件

一、各语言对应的.gitignore模板文件 项目地址:https://github.com/github/gitignore 二、.gitignore文件不生效 .gitignore文件只是ignore没有被追踪的文件,已被追踪的文件,要先删除缓存文件。 # 单个文件 git rm --cached file/path/to…...

网站安全,WAF网站保护暴力破解

雷池的核心功能 通过过滤和监控 Web 应用与互联网之间的 HTTP 流量,功能包括: SQL 注入保护:防止恶意 SQL 代码的注入,保护网站数据安全。跨站脚本攻击 (XSS):阻止攻击者在用户浏览器中执行恶意脚本。暴力破解防护&a…...

深度学习:梯度下降算法简介

梯度下降算法简介 梯度下降算法 我们思考这样一个问题,现在需要用一条直线来回归拟合这三个点,直线的方程是 y w ^ x b y \hat{w}x b yw^xb,我们假设斜率 w ^ \hat{w} w^是已知的,现在想要找到一个最好的截距 b b b。 一条…...

SparkSQL整合Hive后,如何启动hiveserver2服务

当spark sql与hive整合后,我们就无法启动hiveserver2的服务了,每次都要先启动hive的元数据服务(nohup hive --service metastore)才能启动hive,之前的beeline命令也用不了,hiveserver2的无法启动,这也导致我…...

前端路由如何从0开始配置?vue-router 的使用

在 Web 开发中,路由是指根据 URL 的不同部分将请求分发到不同的处理函数或页面的过程。路由是单页应用(SPA, Single Page Application)和服务器端渲染(SSR, Server-Side Rendering)应用中的一个重要概念。 在开发中如何…...

Java中的运算符【与C语言的区别】

目录 1. 算术运算符 1.0 赋值运算符: 1.1 四则运算符: - * / % 【取余与C有点不同】 1.2 增量运算符: - * / % * 【右侧运算结果会自动转换类型】 1.3 自增、自减:、-- 2. 关系运算符 3. 逻辑运算符 3.1 短路求值 3.2 【…...

二、基础语法

入门了解 注释 **作用:**在代码中加一些注释和说明,方便自己或者其他程序员阅读代码 两种格式: 单行注释:// 描述信息 通常放在一行代码的上方,或者一条语句的末尾,对该行代码进行说明 多行注释&#x…...

DB-GPT系列(一):DB-GPT能帮你做什么?

DB-GPT是一个开源的AI原生数据应用开发框架(AI Native Data App Development framework with AWEL and Agents),围绕大模型提供灵活、可拓展的AI原生数据应用管理与开发能力,可以帮助企业快速构建、部署智能AI数据应用,通过智能数据分析、洞察…...

【Python各个击破】numpy

简介 NumPy是一个开源的Python库,它提供了一个强大的N维数组对象和许多用于操作这些数组的函数。它是大多数Python科学计算的基础,包括Pandas、SciPy和scikit-learn等库都建立在NumPy之上。 安装 !pip install numpy导入 import numpy as np用法 # …...

【STM32 Blue Pill编程实例】-4位7段数码管使用

4位7段数码管使用 文章目录 4位7段数码管使用1、7段数码介绍2、硬件准备与接线3、模块配置4、代码实现在本文中,我们将介绍如何将 STM32 Blue Pill开发板与 4 位 7 段数码管连接,并在 STM32CubeIDE 中对其进行编程。 在文章中首先将介绍 4 位 7 段数码管及其与 STM32 Blue Pi…...

[进阶]java基础之集合(三)数据结构

文章目录 数据结构概述常见的数据结构数据结构(栈)数据结构(队列)数据结构(数组)数据结构(链表) 数据结构 概述 数据结构是计算机底层存储、组织数据的方式。是指数据相互之间是以什么方式排列在一起的。数据结构是为了更加方便的管理和使用数据,需要结合具体的业…...

《Apache Cordova/PhoneGap 使用技巧分享》

一、引言 在移动应用开发的领域中,Apache Cordova(也被称为 PhoneGap)是一个强大的工具,它允许开发者使用 HTML、CSS 和 JavaScript 等 Web 技术来构建跨平台的移动应用。这种方式不仅能够提高开发效率,还能降低开发成…...

SCP(Secure Copy

SCP(Secure Copy)‌是Linux系统下基于SSH协议的安全文件传输工具,用于在本地和远程主机间安全、快速地传输文件和目录。SCP命令通过加密传输确保数据的安全性,并且不占用过多系统资源‌。 SCP的基本用法 ‌基本语法‌&#xff1a…...

uniApp 省市区自定义数据

关于自定义省市区选择 其实也是用了 uniApp的内置组件 picker <picker mode"multiSelector" change"bindRegionChange" columnchange"bindMultiPickerColumnChange" :value"valueRegion" :range"multiArray"><v…...

图解Redis 06 | Hash数据类型的原理及应用场景

介绍 Hash 类型特别适合存储对象&#xff0c;例如用户信息等。 String类型也可以用于存储用户信息&#xff0c;Hash与String存储用户信息的区别如下图所示&#xff1a; 内部实现 Hash 类型 的底层数据结构是通过压缩列表&#xff08;Ziplist&#xff09;或哈希表&#xff…...

在 Windows 系统上设置 MySQL8.0以支持远程连接

在 Windows 系统上设置 MySQL8.0以支持远程连接的步骤如下&#xff1a; 步骤1: 修改 MySQL 配置文件1. 找到配置文件&#xff1a; MySQL 的配置文件通常为 my.ini&#xff0c;通常位于 C:\ProgramData\MySQL\MySQL Server8.0\&#xff08;确保查看隐藏文件和文件夹&#xff09…...

四种基本的编程命名规范

目前&#xff0c;共有四种基本的编程命名规范&#xff0c;分别是匈牙利命名法、驼峰式命名法、帕斯卡命名法和下划线命名法&#xff0c;其中前三种命名法较为流行。 例如&#xff1a;iMyData是一个匈牙利命名法&#xff1b;myData是一个驼峰式命名法&#xff1b;MyData是一个帕…...

【前端】在 TypeScript 中使用 AbortController 取消异步请求

在 TypeScript 中使用 AbortController 来取消异步请求&#xff0c;尤其是像 fetch 这样的请求&#xff0c;可以提供一种优雅的方式来中止长时间运行的操作。下面是一个详细的步骤说明&#xff0c;展示如何在 TypeScript 中使用 AbortController 取消 fetch 请求。 步骤 1&…...

k8s知识点总结

docker 名称空间 分类 Docker中的名称空间用于提供进程隔离&#xff0c;确保容器之间的资源相互独立。主要分类包括&#xff1a; PID Namespace&#xff1a;进程ID隔离&#xff0c;使每个容器有自己的进程树&#xff0c;容器内的进程不会干扰其他容器或主机上的进程。 NET Nam…...

RouterOS L2TP服务器搭建与安全优化指南

1. L2TP协议基础与RouterOS适配性 L2TP协议全称为Layer 2 Tunneling Protocol&#xff0c;是一种工作在OSI模型第二层的隧道协议。我第一次接触这个协议是在2015年为企业部署远程办公系统时&#xff0c;当时发现它相比PPTP有着明显的安全优势。简单来说&#xff0c;L2TP就像是在…...

多模态数据挖掘前沿:生物医学与情感分析领域论文深度解析

多模态数据挖掘前沿&#xff1a;生物医学与情感分析领域论文深度解析 在人工智能与大数据技术飞速发展的当下&#xff0c;多模态数据因能更全面、立体地刻画研究对象&#xff0c;已成为科研领域的核心研究方向。本文将深度解析两篇聚焦多模态数据挖掘的重磅论文——《多模态生物…...

如何用Python零依赖快速获取百度搜索结果?python-baidusearch深度解析

如何用Python零依赖快速获取百度搜索结果&#xff1f;python-baidusearch深度解析 【免费下载链接】python-baidusearch 自己手写的百度搜索接口的封装&#xff0c;pip安装&#xff0c;支持命令行执行。Baidu Search unofficial API for Python with no external dependencies …...

“超节点”的纷争开始了

3月26日&#xff0c;在“2026中关村论坛年会”上&#xff0c;中科曙光发布世界首个无线缆箱式超节点scaleX40。其单节点集成40张GPU&#xff0c;总算力超过28PFLOPS&#xff08;FP8精度&#xff09;&#xff0c;能够满足万亿参数大模型的训练与推理需求。产品采用标准19英寸箱式…...

Html2Pdf高性能转换引擎:PHP 7.2-8.4全版本兼容的企业级HTML转PDF解决方案

Html2Pdf高性能转换引擎&#xff1a;PHP 7.2-8.4全版本兼容的企业级HTML转PDF解决方案 【免费下载链接】html2pdf OFFICIAL PROJECT | HTML to PDF converter written in PHP 项目地址: https://gitcode.com/gh_mirrors/ht/html2pdf 在当今企业数字化转型浪潮中&#xf…...

用Python代码和蒙特卡洛方法,手把手教你估算强化学习中的状态价值(附完整代码)

用Python实现蒙特卡洛方法估算强化学习状态价值的实战指南 马尔可夫决策过程&#xff08;MDP&#xff09;是强化学习的数学基础框架&#xff0c;而状态价值函数则是评估策略优劣的核心指标。许多初学者在理解抽象的状态价值概念时会遇到困难——这些数字究竟是如何从实际交互中…...

不用命令行!Win11任务栏图标消失的图形化解决方案(Explorer重启神器推荐)

Win11任务栏图标消失&#xff1f;5种可视化修复方案与深度解析 每次切换虚拟桌面后&#xff0c;Win11任务栏图标集体"失踪"的毛病&#xff0c;堪称微软系统最顽固的"幽灵故障"之一。作为从Windows 95时代就存在的资源管理器痼疾&#xff0c;这个问题在Win1…...

彻底解决电脑噪音烦恼:FanControl风扇控制软件完全指南

彻底解决电脑噪音烦恼&#xff1a;FanControl风扇控制软件完全指南 【免费下载链接】FanControl.Releases This is the release repository for Fan Control, a highly customizable fan controlling software for Windows. 项目地址: https://gitcode.com/GitHub_Trending/f…...

MybatisPlus分页插件PaginationInnerInterceptor原理解析与实战配置指南

MybatisPlus分页插件PaginationInnerInterceptor深度剖析与高效实践 当你在Spring Boot项目中处理海量数据时&#xff0c;分页查询就像给数据装上精准导航——而MybatisPlus的PaginationInnerInterceptor正是这个导航系统的核心引擎。不同于简单配置就能用的工具类&#xff0c;…...

全向轮底盘运动控制:嵌入式PID与逆运动学实现

1. 全向轮底盘控制库&#xff08;omni_wheel&#xff09;技术解析与工程实践1.1 项目背景与工程定位omni_wheel是为B团队自主移动机器人开发的底层运动控制模块&#xff0c;最初版本发布于2018年7月10日。从其原始README描述“PIDかけて一方向に進むだけのプログラムでござんす…...