1 个不稳定版本
0.1.0 | 2024 年 6 月 13 日 |
---|
482 在 异步 中
21KB
102 行
代理包
agents
包提供了一套创建和管理能够处理文本并根据指定角色执行任务的代理工具。它利用了基于 Tokio 的异步 Rust 编程,以实现高效的任务执行。
使用方法
此包允许您创建具有特定角色的 Agent
实例,并使用自然语言理解执行任务。以下是使用此包的快速入门指南
示例:总结文本
以下示例演示了如何设置和使用一个 Agent
来总结一篇文章。此示例中的文本是随意选择的,并从网上复制以供演示。
main.rs
extern crate agents;
use agents::{Agent, Cognitive, Message, Role};
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Version 1.0");
// Description for the agent's persona
static SUMMARIZERDESCRIPTION: &str = r#"
You are an Harvard Business Review editor with 30 years of experience in editorial roles.
You are excellent in English and business academic research.
Your role is to make a very brief short business case out of the next texts:
"#;
// Sample article text
static ARTICLE: &str = r#"
The Biden administration announced a series of new financial sanctions Wednesday aimed at interrupting the fast-growing technological links between China and Russia that American officials believe are behind a broad effort to rebuild and modernize Russia’s military during its war with Ukraine.
The actions were announced just as President Biden was leaving the country for a meeting in Italy of the Group of 7 industrialized economies, where a renewed effort to degrade the Russian economy will be at the top of his agenda.
The effort has grown far more complicated in the past six or eight months after China, which previously had sat largely on the sidelines, has stepped up its shipments of microchips, optical systems for drones and components for advanced weaponry, U.S. officials said. But so far Beijing appears to have heeded Mr. Biden’s warning against shipping weapons to Russia, even as the United States and NATO continue to arm Ukraine.
Announcing the new sanctions, Treasury Secretary Janet L. Yellen said in a statement that “Russia’s war economy is deeply isolated from the international financial system, leaving the Kremlin’s military desperate for access to the outside world.”
"#;
// Initialize cognitive resources
let small_llm = Cognitive::new("qwen2:72b".to_string());
// Create agent profile
let profile = Message::new(SUMMARIZERDESCRIPTION.to_string(), Role::AGENT);
// Create agent
let hamze = Agent::new("Hamze".to_string(), profile, small_llm);
// Task to summarize
let task = format!("Make summary of the following text: {}", ARTICLE);
println!("I am thinking... ");
println!("Please wait, it could take a while!");
// Execute task
let final_reflection = hamze.execute(task).await;
println!("Summary: {:#?}", final_reflection);
Ok(())
}
特性
- 认知建模:初始化具有认知能力的代理以理解和生成自然语言。
- 异步执行:利用 async/await 进行非阻塞任务执行。
- 可定制角色:定义如
AGENT
、USER
和SYSTEM
等角色,以实现基于上下文的行为。
依赖关系
~28–43MB
~644K SLoC