autogen改变屏幕亮度

学习资料

官方的入门教程很容易入门,所以推荐使用官方的学习资料:autogen官方教程

小实践,修改屏幕亮度

准备:

  1. 修改屏幕亮度的python代码(参考:改变屏幕亮度
  2. 使用工具(autogen使用工具例子代码)
python 复制代码
import tempfile

from autogen import ConversableAgent,config_list_from_json
from autogen.coding import LocalCommandLineCodeExecutor
from autogen import register_function
import screen_brightness_control as sbc
from typing import Annotated,Literal
Operator = Literal["change"]

def change_brightness(value:int,operator: Annotated[Operator, "operator"]) ->str:
    sbc.set_brightness(value)
    return 'change successfully'

def main():
    config_list = config_list_from_json(env_or_file='OAI_CONFIG_LIST')
    temp_dir = tempfile.TemporaryDirectory()
    #定义assistant
    assistant_agent_system_message = "You are a helpful AI assistant. "
    "You can help with change brightness on my device. "
    "Return 'TERMINATE' when the task is done."
    assistant_agent = ConversableAgent(
        "assisant",
        llm_config={'config_list':config_list},
        system_message=assistant_agent_system_message,
        code_execution_config=False,
    )

    executor = LocalCommandLineCodeExecutor(
        timeout=10,
        work_dir=temp_dir.name,
    )

    user_proxy_agent = ConversableAgent(
        "user-proxy",
        code_execution_config={
            'executor': executor,
        },
        human_input_mode="ALWAYS",
    )

    #注册工具
    # Register the tool signature with the assistant agent.
    assistant_agent.register_for_llm(name="changeScreenbrightness", description="A tool to change screen brightness")(change_brightness)

    # Register the tool function with the user proxy agent.
    user_proxy_agent.register_for_execution(name="changeScreenbrightness")(change_brightness)

    chat_result = user_proxy_agent.initiate_chat(
        assistant_agent,
        message='Change brightness to 50'
    )
    

if __name__ == '__main__':
    main()

OAI_CONFIG_LIST文件的配置为:

python 复制代码
[
    {
        "model": "qwen-plus-latest", 
        "base_url":"https://dashscope.aliyuncs.com/compatible-mode/v1",
        "api_type":"qwen",
        "api_key":"你的key",
        "temperature": 0.7,
        "max_tokens":2000,
        "stream":0
    }
]

注意事项

  1. 这里使用的阿里的兼容openai的接口。是一个比较好的选择,因为autogen对openai的适配度高。
  2. 使用了下阿里百炼平台的llama3(要申请,有免费额度),但是不支持function call,所以改成了使用qwen-plus-latest。这个模型还可以,比qwen-turo聪明些。
相关推荐
小星AI2 小时前
Claude Code Agent SDK 从入门到精通,一步到位
人工智能·agent·cursor
沅柠-AI营销2 小时前
小品牌的GEO优化落地策略:2026年AI搜索时代的低成本突围指南
人工智能·agent·ai搜索优化·geo优化·品牌策略·中小品牌营销·geo优化技巧
薛定谔的猫3692 小时前
深度解析:大语言模型 (LLM) Agent 的架构与演进趋势
ai·llm·agent·技术趋势·artificial intelligence
louisliao_19813 小时前
Agent 项目落地模板
agent
阿瑞说项目管理3 小时前
2026 实战入门指南:企业 Agent 到底能解决哪些工作问题?
大数据·人工智能·agent·智能体·企业级ai
阿瑞说项目管理4 小时前
2026 智造升级:制造企业 Agent 从 0 到 1 落地指南,五大场景拆解实战路径
人工智能·agent·智能体·企业级ai
维元码簿6 小时前
Claude Code 深度拆解:Agent 执行内核 2 — Pipeline 与上下文压缩
ai·agent·claude code·ai coding
也许明天y6 小时前
LangChain4j + Spring Boot 多智能体协调架构原理深度解析
spring boot·后端·agent
Trouvaille ~7 小时前
零基础入门 LangChain 与 LangGraph(八):真正让 Agent“活起来”——持久化、记忆、人机交互与时间旅行
langchain·人机交互·agent·python3.11·持久化机制·langgraph·ai应用开发
还是转转7 小时前
深入认识 Agent —— 实现你自己的 Agent
ai·agent