神仙姐姐的“战场”:刘亦菲《刺激战场》B站播放量揭秘,数据背后藏着什么?

核心内容摘要

粉色ABB苏州:2024,解锁晶体结构的浪漫密码
当心跳与呼吸交织:探索青春的懵懂与美好

探索未知的精彩,91pron在线,您的数字娱乐新维度

基于AgentScope框架你可以创建一个带有长期记忆功能的定时循环Agent。

不过需要说明的是当前代码库中没有直接的VLM视觉语言模型实现你需要自己集成视觉处理功能。

基本实现方案

创建带长期记忆的ReActAgentfromagentscope.agentimportReActAgentfromagentscope.memoryimportMem0LongTermMemory,InMemoryMemoryfromagentscope.modelimportDashScopeChatModelfromagentscope.formatterimportDashScopeChatFormatterfromagentscope.embeddingimportDashScopeTextEmbeddingfromagentscope.toolimportToolkitimportosimportasyncioimporttime# 创建长期记忆实例long_term_memoryMem0LongTermMemory(agent_nameVLM_Agent,user_nameuser_001,modelDashScopeChatModel(model_nameqwen-max-latest,api_keyos.environ.get(DASHSCOPE_API_KEY),streamFalse,),embedding_modelDashScopeTextEmbedding(model_nametext-embedding-v2,api_keyos.environ.get(DASHSCOPE_API_KEY),),on_diskFalse,)# 创建带记忆的AgentagentReActAgent(nameVLM_Agent,sys_prompt你是一个具有视觉处理能力和长期记忆的助手。

,modelDashScopeChatModel(model_nameqwen-max-latest,api_keyos.environ.get(DASHSCOPE_API_KEY),),formatterDashScopeChatFormatter(),toolkitToolkit(),memoryInMemoryMemory(),long_term_memorylong_term_memory,long_term_memory_modeagent_control,# 让agent自主管理记忆)

添加定时循环机制asyncdefperiodic_vlm_agent():每分钟执行一次的VLM Agent循环whileTrue:try:# 这里添加你的VLM处理逻辑# 例如获取图像、分析、记录到记忆等# 模拟VLM任务task_msgMsg(namesystem,content执行定时视觉分析任务,roleuser)# 执行agent任务responseawaitagent(task_msg)print(fAgent响应:{response.get_text_content()})# 等待1分钟awaitasyncio.sleep(

exceptExceptionase:print(f执行出错:{e})awaitasyncio.sleep(

# 启动定时循环asyncio.run(periodic_vlm_agent())

集成VLM功能需要自定义实现由于当前代码库没有VLM实现你需要创建自定义工具defanalyze_image(image_path:str)-str:分析图像内容的自定义工具# 这里集成你的VLM模型# 例如调用OpenAI GPT-4V、Google Gemini Vision等return图像分析结果# 注册到工具包toolkitToolkit()toolkit.register_tool_function(analyze_image)关键组件说明长期记忆配置Mem0LongTermMemory提供基于向量的长期记忆存储 1agent_control模式让Agent通过工具调用自主管理记忆 2ReActAgent记忆管理Agent会在每次回复时自动检索相关记忆 3支持记忆压缩功能防止记忆无限增长 4

注意事项VLM集成需要额外实现视觉处理工具可以调用外部API如GPT-4V、Gemini Vision等资源管理定时循环要注意内存和API调用限制记忆持久化设置on_diskTrue可以持久化记忆到磁盘错误处理添加适当的异常处理确保循环稳定运行Notes当前AgentScope框架主要专注于文本对话AgentVLM功能需要自定义实现长期记忆支持Mem0和ReMe两种实现可根据需求选择定时循环建议在生产环境中使用更完善的任务调度系统如Celery或APSchedulerWiki pages you might want to explore:Quick Start: Building Your First Agent (agentscope-ai/agentscope)Message System and Formatting (agentscope-ai/agentscope)CitationsFile:src/agentscope/memory/_long_term_memory/_mem0/_mem0_long_term_memory.py (L72-

classMem0LongTermMemory(LongTermMemoryBase):A class that implements the LongTermMemoryBase interface using mem

def__init__(self,agent_name:str|NoneNone,user_name:str|NoneNone,run_name:str|NoneNone,model:ChatModelBase|NoneNone,embedding_model:EmbeddingModelBase|NoneNone,vector_store_config:VectorStoreConfig|NoneNone,mem0_config:MemoryConfig|NoneNone,default_memory_type:str|NoneNone,**kwargs:Any,)-None:Initialize the Mem0LongTermMemory instance Args: agent_name (str | None, optional): The name of the agent. Default is None. user_name (str | None, optional): The name of the user. Default is None. run_name (str | None, optional): The name of the run/session. Default is None. .. note::

At least one of agent_name, user_name, or run_name is required.

During memory recording, these parameters become metadata for the stored memories.

**Important**: mem0 will extract memories from messages containing role of user by default. If you want to extract memories from messages containing role of assistant, you need to provide agent_name.

During memory retrieval, only memories with matching metadata values will be returned. model (ChatModelBase | None, optional): The chat model to use for the long-term memory. If mem0_config is provided, this will override the LLM configuration. If mem0_config is None, this is required. embedding_model (EmbeddingModelBase | None, optional): The embedding model to use for the long-term memory. If mem0_config is provided, this will override the embedder configuration. If mem0_config is None, this is required. vector_store_config (VectorStoreConfig | None, optional): The vector store config to use for the long-term memory. If mem0_config is provided, this will override the vector store configuration. If mem0_config is None and this is not provided, defaults to Qdrant with on_diskTrue. mem0_config (MemoryConfig | None, optional): The mem0 config to use for the long-term memory. If provided, individual model/embedding_model/vector_store_config parameters will override the corresponding configurations in mem0_config. If None, a new MemoryConfig will be created using the provided parameters. default_memory_type (str | None, optional): The type of memory to use. Default is None, to create a semantic memory. Raises: ValueError: If mem0_config is None and either model or embedding_model is None. super().__init__()File:docs/tutorial/zh_CN/src/task_long_term_memory.py (L78-

# 与 ReAct 智能体集成# ----------------------------------------# AgentScope 中的 ReActAgent 在构造函数中包含 long_term_memory 和 long_term_memory_mode 两个参数# 其中 long_term_memory 用于指定长期记忆实例long_term_memory_mode 的取值为 agent_control, static_control 或 both。

## 当 long_term_memory_mode 设置为 agent_control 或 both 时在 ReActAgent 的构造函数中将# 注册两个工具函数record_to_memory 和 retrieve_from_memory。

# 从而使智能体能够自主的管理长期记忆。

## .. note:: 为了达到最好的效果agent_control 模式可能还需要在系统提示system prompt中添加相应的说明。

## 创建带有长期记忆的 ReAct 智能体agentReActAgent(nameFriday,sys_prompt你是一个具有长期记忆功能的助手。

,modelDashScopeChatModel(api_keyos.environ.get(DASHSCOPE_API_KEY),model_nameqwen-max-latest,),formatterDashScopeChatFormatter(),toolkitToolkit(),memoryInMemoryMemory(),long_term_memorylong_term_memory,long_term_memory_modestatic_control,# 使用 static_control 模式)File:src/agentscope/agent/_react_agent.py (L870-

asyncdef_retrieve_from_long_term_memory(self,msg:Msg|list[Msg]|None,)-None:Insert the retrieved information from the long-term memory into the short-term memory as a Msg object. Args: msg (Msg | list[Msg] | None): The input message to the agent. ifself._static_controlandmsg:# Retrieve information from the long-term memory if availableretrieved_infoawaitself.long_term_memory.retrieve(msg)ifretrieved_info:retrieved_msgMsg(namelong_term_memory,contentlong_term_memoryThe content below are retrieved from long-term memory, which maybe fuseful:\n{retrieved_info}/long_term_memory,roleuser,)ifself.print_hint_msg:awaitself.print(retrieved_msg,True)awaitself.memory.add(retrieved_msg)File:docs/tutorial/zh_CN/src/task_agent.py (L129-

# compression_configReActAgent.CompressionConfig(# enableTrue,# agent_token_counterCharTokenCounter(), # 智能体的 token 计数器# trigger_threshold10000, # 超过 10000 个 token 时触发压缩# keep_recent3, # 保持最近 3 条消息不被压缩# ),# )## 启用记忆压缩后智能体会监控其记忆中的 token 数量。

# 一旦超过 trigger_threshold智能体会自动##

识别尚未被压缩的消息通过 exclude_mark#

保持最近 keep_recent 条消息不被压缩以保留最近的上下文#

将较早的消息发送给 LLM 生成结构化摘要#

使用 MemoryMark.COMPRESSED 标记已压缩的消息通过 update_messages_mark#

将摘要存储在记忆中通过 update_compressed_summary## .. important:: 压缩采用**标记机制**而非替换消息。

旧消息被标记为已压缩并通过 exclude_markMemoryMark.COMPRESSED 在后续检索中被排除而生成的摘要则单独存储在需要时检索。

这种方式保留了原始消息允许灵活的记忆管理。

关于标记功能的更多详情请参考 :ref:memory。

## 默认情况下压缩摘要被结构化为五个关键字段## - **task_overview**用户的核心请求和成功标准# - **current_state**到目前为止已完成的工作包括文件和输出# - **important_discoveries**技术约束、决策、错误和失败的尝试# - **next_steps**完成任务所需的具体操作# - **context_to_preserve**用户偏好、领域细节和做出的承诺## **自定义压缩**## 可以通过指定 summary_schema、summary_template 和 compression_prompt 参数来自定义压缩的工作方式。

我想看B站直播-我想看B站直播应用

百度百家号客服电话人工服务

123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123 123