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

agentscope1.0安装与测试

安装

# 从 GitHub 拉取源码
git clone https://github.com/agentscope-ai/agentscope.git# 以可编辑模式安装包
cd agentscope
source .venv/Scripts/activate
uv pip install -e . --index-url https://pypi.tuna.tsinghua.edu.cn/simple
uv pip install python-dotenv

测试

1. 环境变量
.env文件

  • DASHSCOPE_API_KEY=sk-xxxx

2. 示例代码
hello.py

from agentscope.agent import ReActAgent, UserAgent
from agentscope.model import DashScopeChatModel
from agentscope.formatter import DashScopeChatFormatter
from agentscope.memory import InMemoryMemory
from agentscope.tool import Toolkit, execute_python_code, execute_shell_command
import os, asynciofrom dotenv import load_dotenv
load_dotenv()async def main():toolkit = Toolkit()toolkit.register_tool_function(execute_python_code)toolkit.register_tool_function(execute_shell_command)agent = ReActAgent(name="Friday",sys_prompt="You're a helpful assistant named Friday.",model=DashScopeChatModel(model_name="qwen-turbo",api_key=os.environ["DASHSCOPE_API_KEY"],stream=True,),memory=InMemoryMemory(),formatter=DashScopeChatFormatter(),toolkit=toolkit,)user = UserAgent(name="user")msg = Nonewhile True:msg = await agent(msg)msg = await user(msg)if msg.get_text_content() == "exit":breakasyncio.run(main())

运行示例

uv run hello.py

输出结构

	(agentscope) PS D:\agent-llm\agentscope> uv run .\mytest\hello.pyFriday: Hello! How can I assist you today?User Input: tell me who you areuser: tell me who you areFriday: I am Qwen, a large-scale language model developed by Alibaba Cloud. I can help you with a wide range of tasks, including answering questions, generating text, and more. How can I assist you today?User Input: what's your abilityuser: what's your abilityFriday: I am capable of a wide range of tasks, including but not limited to: answering questions, generating text, creating stories, writing code, and providing explanations. I can also assist with language translation, summarization, and more. How can I help you today?User Input: 帮我写一个简单的Python函数来计算斐波那契数列user: 帮我写一个简单的Python函数来计算斐波那契数列Friday: {"type": "tool_use","id": "call_7be7de124fdc4e99bfb1f0","name": "execute_python_code","input": {"code": "def fibonacci(n):\n    if n <= 0:\n        return []\n    elif n == 1:\n        return [0]\n    \n    fib_sequence = [0, 1]\n    for i in range(2, n):\n        fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])\n    return fib_sequence\n\n# Example usage: print the first 10 Fibonacci numbers\nprint(fibonacci(10))","timeout": 300}}system: {"type": "tool_result","id": "call_7be7de124fdc4e99bfb1f0","name": "execute_python_code","output": [{"type": "text","text": "<returncode>0</returncode><stdout>[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]\r\n</stdout><stderr></stderr>"}]}Friday: 这里是一个简单的Python函数,用于计算斐波那契数列:```pythondef fibonacci(n):if n <= 0:return []elif n == 1:return [0]fib_sequence = [0, 1]for i in range(2, n):fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])return fib_sequence# 示例:打印前10个斐波那契数print(fibonacci(10))```运行结果是:```[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]```这个函数会返回一个包含前 `n` 个斐波那契数的列表。如果有其他问题或需要进一步的帮助,请告诉我!User Input: 创建一个名为 test.txt 的文件user: 创建一个名为 test.txt 的文件Friday: {"type": "tool_use","id": "call_490958d83b914e999e6211","name": "execute_shell_command","input": {"command": "touch test.txt","timeout": 300}}system: {"type": "tool_result","id": "call_490958d83b914e999e6211","name": "execute_shell_command","output": [{"type": "text","text": "Error: 'utf-8' codec can't decode byte 0xb2 in position 8: invalid start byte"}]}Friday: 可能由于编码问题导致错误。我们可以尝试使用不同的方法来创建文件。请告诉我您使用的操作系统,以便我提供更准确的解决方案。User Input: windowsuser: windowsFriday: {"type": "tool_use","id": "call_8c442c5a592d4bb5832d82","name": "execute_shell_command","input": {"command": "type nul > test.txt","timeout": 300}}system: {"type": "tool_result","id": "call_8c442c5a592d4bb5832d82","name": "execute_shell_command","output": [{"type": "text","text": "<returncode>0</returncode><stdout></stdout><stderr></stderr>"}]}Friday: 文件 `test.txt` 已成功在 Windows 系统中创建。如果需要进一步帮助,请随时告诉我!User Input: exituser: exit

文章转载自:

http://fRmJCLPN.hhqtq.cn
http://bPHq3NlN.hhqtq.cn
http://pO3rWzB3.hhqtq.cn
http://BTUp1w6R.hhqtq.cn
http://jK8UFjfm.hhqtq.cn
http://4YYo7XH2.hhqtq.cn
http://ylKvak4b.hhqtq.cn
http://GETYbjPM.hhqtq.cn
http://H8BxqgaU.hhqtq.cn
http://sM10ds9O.hhqtq.cn
http://ABfZFGIj.hhqtq.cn
http://l1vVp06Z.hhqtq.cn
http://CjP48FGm.hhqtq.cn
http://sJsqoikJ.hhqtq.cn
http://MzcJvVkg.hhqtq.cn
http://RG9pXGZe.hhqtq.cn
http://hpS9BVjX.hhqtq.cn
http://g4AiaFKF.hhqtq.cn
http://Lmz8Jkd5.hhqtq.cn
http://jLVvxZNc.hhqtq.cn
http://W8ToXhe5.hhqtq.cn
http://vYHUXEJw.hhqtq.cn
http://vPyNlhXB.hhqtq.cn
http://SERwwgdR.hhqtq.cn
http://UYCuKr3N.hhqtq.cn
http://49o6I80P.hhqtq.cn
http://fUX9WsUk.hhqtq.cn
http://IPGE281W.hhqtq.cn
http://HdbZEZnL.hhqtq.cn
http://9C5DP3Qh.hhqtq.cn
http://www.dtcms.com/a/372203.html

相关文章:

  • Shell 脚本自动安装 Nginx
  • 《探索C++11:现代语法的内存管理优化“性能指针”(下篇)》
  • Basic Pentesting: 1靶场渗透
  • NAS自建笔记服务leanote2
  • 对比Java学习Go——程序结构与变量
  • 【JavaWeb】一个简单的Web浏览服务程序
  • [C/C++学习] 7.“旋转蛇“视觉图形生成
  • webhook(Web 钩子)是什么?
  • 《2025年AI产业发展十大趋势报告》四十三
  • java面试小册(1)
  • NW506NW507美光固态闪存NW525NW539
  • [Maven 基础课程]再看下第一个 Maven 项目
  • Keil快捷键代码补全
  • 2024理想算法岗笔试笔记
  • Java面试-线程安全篇
  • 线程池深度解析:ThreadPoolExecutor底层实现与CompletableFuture异步编程实战
  • 计算机网络学习(七、网络安全)
  • 蓝奏云官方版不好用?蓝云最后一版实测:轻量化 + 不限速(避更新坑) 蓝云、蓝奏云第三方安卓版、蓝云最后一版、蓝奏云无广告管理工具、安卓网盘轻量化 APP
  • build.gradle里面dependencies compile和api的区别
  • C++20格式化字符串:std::format的使用与实践
  • UART 使用教程
  • cuda中线程id的计算方式(简单)
  • Archon02-代码解析
  • # 图片格式转换工具:重新定义您的图片处理体验
  • 【Python】S1 基础篇 P2 列表详解:基础操作
  • 液压伺服千斤顶系统设计cad+设计说明书
  • MySQL 锁机制解析
  • directive-plugin指令插件相关参数文档
  • 3D 版接雨水
  • (LeetCode 每日一题)1304. 和为零的 N 个不同整数(数组)