update cookbook

This commit is contained in:
jinli.yl 2025-06-12 00:27:01 +08:00
parent 0b804f2278
commit 61612da325
9 changed files with 292 additions and 12 deletions

View file

@ -0,0 +1,240 @@
[
{
"role": "user",
"content": "You are a helpful assistant named BeyondAgent.\nThe current time is 2025-06-12 00:14:14.\n\nPlease proactively choose the most suitable tool or combination of tools based on the user's question, including python_execute, web_search, terminate etc.\nFor complex tasks, you can break down the problem step by step and use different tools to solve it incrementally.\nPlease determine the response language based on the language of the user's question.\n\n分析一下小米公司\n",
"reasoning_content": "",
"tool_calls": [],
"timestamp": "2025-06-12 00:14:14.885684",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {}
},
{
"role": "assistant",
"content": "",
"reasoning_content": "好的,用户让我分析一下小米公司。首先,我需要确定用户需要的是哪个方面的分析。小米公司涉及多个领域,比如智能手机、智能家居、生态系统产品等。可能用户想要一个全面的分析,包括财务状况、市场地位、产品策略、竞争环境等等。\n\n接下来我应该考虑使用什么工具。用户提供的工具中有web_search和python_execute。由于分析公司通常需要最新的市场数据、财务报告和行业趋势这些信息可能不在我的知识库中所以需要使用web_search来获取最新的信息。例如搜索小米的最新财报、市场份额、最近的新闻动态以及行业分析报告。\n\n另外如果需要进行数据分析或财务指标计算比如市盈率、营收增长率等可能需要使用python_execute来处理数据。不过用户提到不要执行matplotlib代码所以可能不适合做图表但数值计算还是可以的。不过首先可能需要通过web_search获取数据然后才能用python处理。\n\n现在我需要分解步骤。首先用web_search查找小米公司的最新财务数据比如营收、利润、增长率等。然后搜索小米的市场地位比如在全球智能手机市场的份额与其他竞争对手如华为、苹果、三星的比较。接着分析小米的生态系统战略比如MIUI系统、智能家居设备、投资其他科技公司等。此外还可以考虑其国际化进展比如在印度、欧洲市场的表现。\n\n可能还需要查找行业分析比如小米在行业中的优势和挑战比如供应链管理、品牌影响力、研发投入等。同时看看最近的新闻是否有新产品发布、战略合作或面临的挑战如芯片供应问题等。\n\n然后我需要调用web_search工具分别用不同的关键词进行搜索比如“小米公司 最新财报”、“小米 市场份额 2025”、“小米 生态系统 战略”、“小米 国际化 进展”等。每个查询可能需要单独调用web_search因为工具要求每个关键词单独使用。\n\n在获得足够的信息后整理这些数据进行综合分析可能需要用python_execute计算某些财务比率比如净利润率、营收增长率等以量化小米的财务健康状况。例如如果搜索到小米过去五年的营收数据可以用python计算年均增长率。\n\n最后整合所有信息形成结构化的分析报告涵盖财务表现、市场地位、战略方向、竞争优势与挑战等方面并给出总结。如果信息足够全面就可以使用terminate工具状态设为success表示完成分析。如果信息不足可能需要进一步搜索或提示用户补充需求。",
"tool_calls": [
{
"index": 0,
"id": "call_185f387435f445519e6de8",
"name": "web_search",
"arguments": "{\"query\": \"小米公司 最新财务数据 2025\"}",
"type": "function"
}
],
"timestamp": "2025-06-12 00:14:38.254066",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {}
},
{
"role": "tool",
"content": "tool.0\nname=web_search\narguments={\"query\": \"小米公司 最新财务数据 2025\"}\nresult=根据知识库中提供的信息以下是小米公司2025年最新财务数据的相关内容\n\n### 2025年第一季度财务数据\n1. **总营收**1113亿元人民币连续两个季度超千亿同比增长47.4%。\n2. **净利润**经调整后的净利润为107亿元人民币首次突破百亿元大关与去年同期相比增长64.5%。\n3. **研发投入**67亿元人民币同比增长30.1%。预计2025年全年研发投入将达到300亿元人民币。\n4. **研发人员规模**截至2025年3月31日研发人员总数扩至21,731人创历史新高。\n5. **专利数量**在全球获得超过4.3万件专利。\n\n### 汽车业务情况\n1. **小米SU7系列**累计交付突破25.8万辆2025年4月交付量超过2.8万辆位居国内20万以上所有车型销量冠军。\n2. **毛利率目标**小米集团总裁卢伟冰表示预计2025年汽车业务的毛利率将不低于2025年第一季度的水平。\n3. **亏损预测**2025年Q1小米汽车业务可能亏损1-2亿元人民币仍处于高投入阶段。\n\n### 其他关键指标\n1. **股价表现**截至2025年6月11日港股小米集团-W01810价格为54.100港元当日成交量80.05亿港元较上日收盘价上涨0.650港元。\n2. **战略投入**未来五年计划投入2000亿元人民币研发费用进一步强化技术布局。\n\n以上信息均来自知识库中提供的原始内容未进行额外加工或推测。",
"reasoning_content": "",
"tool_calls": [
{
"index": 0,
"id": "call_185f387435f445519e6de8",
"name": "web_search",
"arguments": "{\"query\": \"小米公司 最新财务数据 2025\"}",
"type": "function"
}
],
"timestamp": "2025-06-12 00:15:05.274582",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {},
"tool_call_id": ""
},
{
"role": "user",
"content": "User's question\n分析一下小米公司\n\nPlan the most suitable tool or combination of tools based on the context and the user's question. \nFor complex tasks, break down the problem and use different tools step by step to solve it, don't give up easily. \nTry calling the same tool multiple times with different parameters to obtain information from various perspectives. \nIf the task is completed and the user's question can now be answered, use the **terminate** tool.\nPlease determine the response language based on the language of the user's question.\n",
"reasoning_content": "",
"tool_calls": [],
"timestamp": "2025-06-12 00:15:05.275006",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {}
},
{
"role": "assistant",
"content": "",
"reasoning_content": "好的用户让我分析小米公司之前已经通过web_search获取了2025年第一季度的财务数据和汽车业务情况。现在需要进一步分析其他方面比如市场地位、生态系统战略、国际化进展等。接下来应该用web_search分别搜索这些关键词确保覆盖全面。\n\n首先用户可能需要了解小米在智能手机市场的份额所以搜索“小米 全球市场份额 2025”。然后分析其生态系统比如“小米 生态系统 战略 2025”。接着国际化方面搜索“小米 国际化 市场进展 2025”。此外竞争环境也是重点可能需要搜索“小米 竞争对手 分析 2025”。\n\n每个搜索结果需要整合到分析中可能还需要用python_execute处理数据比如计算增长率或市场份额占比。但根据用户之前的指示先完成信息收集再决定是否需要计算。如果现有数据足够就可以终止工具调用给出综合分析报告。",
"tool_calls": [
{
"index": 0,
"id": "call_82c6c2f0e89948df8638a5",
"name": "web_search",
"arguments": "{\"query\": \"小米 全球市场份额 2025\"}",
"type": "function"
}
],
"timestamp": "2025-06-12 00:15:13.858766",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {}
},
{
"role": "tool",
"content": "tool.0\nname=web_search\narguments={\"query\": \"小米 全球市场份额 2025\"}\nresult=根据知识库内容以下是与小米2025年全球市场份额相关的直接信息\n\n1. **2025年全年市场份额** \n - 小米手机2025年全球销量达到**1.7亿部**,占据**14%的市场份额**(即每七部手机中有一部是小米品牌)。\n\n2. **季度表现** \n - **2025年Q1**Counterpoint数据显示小米在全球智能手机市场中保持双位数市场份额**16.6%**但具体季度市场份额需结合其他厂商对比三星6050万台、苹果5500万台。\n - **连续19个季度稳居全球前三**雷军在小米15周年发布会上宣布小米手机市场份额连续19个季度位列全球前三未明确具体百分比。\n\n3. **其他补充** \n - 小米2025年研发投入预计达300亿元五年累计投入超1000亿元支撑其市场份额提升。\n\n以上信息均来自知识库中提及2025年及全球市场的直接描述。",
"reasoning_content": "",
"tool_calls": [
{
"index": 0,
"id": "call_82c6c2f0e89948df8638a5",
"name": "web_search",
"arguments": "{\"query\": \"小米 全球市场份额 2025\"}",
"type": "function"
}
],
"timestamp": "2025-06-12 00:15:37.137264",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {},
"tool_call_id": ""
},
{
"role": "user",
"content": "User's question\n分析一下小米公司\n\nPlan the most suitable tool or combination of tools based on the context and the user's question. \nFor complex tasks, break down the problem and use different tools step by step to solve it, don't give up easily. \nTry calling the same tool multiple times with different parameters to obtain information from various perspectives. \nIf the task is completed and the user's question can now be answered, use the **terminate** tool.\nPlease determine the response language based on the language of the user's question.\n",
"reasoning_content": "",
"tool_calls": [],
"timestamp": "2025-06-12 00:15:37.137676",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {}
},
{
"role": "assistant",
"content": "",
"reasoning_content": "好的用户需要分析小米公司我已经收集了财务数据和全球市场份额的信息。接下来应该考虑其他关键方面比如生态系统战略和国际化进展。之前已经用web_search查了财务数据和市场份额现在需要继续用web_search获取更多数据。\n\n首先小米的生态系统是其重要优势应该搜索“小米 生态系统 战略 2025”来了解最新动态。另外国际化方面小米在印度和欧洲市场表现不错需要搜索“小米 国际化 市场进展 2025”。此外竞争环境也是分析的一部分可能需要搜索“小米 竞争对手 分析 2025”来了解其面临的挑战。\n\n每个搜索结果需要整合到分析中确保覆盖财务、市场、战略和竞争等多个维度。如果现有信息足够就可以终止工具调用给出综合报告。但目前可能还需要更多数据所以继续调用web_search",
"tool_calls": [
{
"index": 0,
"id": "call_9c565699e0174d11a1a890",
"name": "web_search",
"arguments": "{\"query\": \"小米 生态系统 战略 2025\"}",
"type": "function"
}
],
"timestamp": "2025-06-12 00:18:43.449271",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {}
},
{
"role": "tool",
"content": "tool.0\nname=web_search\narguments={\"query\": \"小米 生态系统 战略 2025\"}\nresult=### 小米生态系统战略2025相关内容 \n1. **人车家全生态战略闭环** \n - **2024年成果**:小米通过互联网服务将人车家全生态战略完成闭环,智能汽车量产并实现盈利,成为战略核心环节。 \n - **2025年深化**小米宣布未来五年再投入2000亿元研发费用持续深化技术驱动战略强化“人车家全生态”布局。 \n\n2. **技术突破与产品生态** \n - **自研芯片**发布第二代3nm工艺自研芯片**玄戒O1**集成190亿晶体管性能对标甚至超越苹果A18 Pro芯片搭载于小米15S Pro、平板7 Ultra、小米手表S4等设备并通过UWB技术与小米汽车YU7互联。 \n - **产品矩阵**2025年5月推出小米15S Pro、平板7 Ultra、首款SUV小米YU7等覆盖手机、平板、可穿戴、汽车四大核心领域。 \n\n3. **生态合作与开放战略** \n - **能链智电合作**与新能源充电服务商能链智电达成战略合作用户可通过车机及App接入全国充电网络实现找桩、导航、支付全链路智能化服务。 \n - **华厦眼科合作**:与小米生态链企业蜂巢科技签署协议,探索智能眼镜在眼科医疗服务的应用。 \n - **开发者赋能**召开人车家全生态合作伙伴大会开放澎湃OS、IoT生态、AI能力赋能全球开发者增长Vela系统设备超6000万台已全面开源。 \n\n4. **市场与用户数据** \n - 全球月活跃用户超**6.86亿**小米手机市场份额连续17个季度稳居全球前三。 \n - IoT连接设备数达**8.6亿台**澎湃OS互联能力日均使用超4000万次AI能力日均使用超2亿次。 \n - 高端手机销量同比增长43%小米SU7交付量230天破10万辆。 \n\n5. **战略升级与技术底座** \n - 发布**HyperOS 2.0**,从底层创新提升竞争力,推动用户留存生态体系。 \n - 以“开放基因”联合全球软硬件开发者,聚焦**生态、AI、出海**三大领域,助力行业技术升级与全球化拓展。 \n\n以上内容均基于知识库中2024-2025年小米战略相关披露信息整理。",
"reasoning_content": "",
"tool_calls": [
{
"index": 0,
"id": "call_9c565699e0174d11a1a890",
"name": "web_search",
"arguments": "{\"query\": \"小米 生态系统 战略 2025\"}",
"type": "function"
}
],
"timestamp": "2025-06-12 00:19:13.118233",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {},
"tool_call_id": ""
},
{
"role": "user",
"content": "User's question\n分析一下小米公司\n\nPlan the most suitable tool or combination of tools based on the context and the user's question. \nFor complex tasks, break down the problem and use different tools step by step to solve it, don't give up easily. \nTry calling the same tool multiple times with different parameters to obtain information from various perspectives. \nIf the task is completed and the user's question can now be answered, use the **terminate** tool.\nPlease determine the response language based on the language of the user's question.\n",
"reasoning_content": "",
"tool_calls": [],
"timestamp": "2025-06-12 00:19:13.118927",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {}
},
{
"role": "assistant",
"content": "",
"reasoning_content": "好的用户需要分析小米公司我已经收集了财务数据、全球市场份额以及生态系统战略的信息。现在需要考虑是否还有其他关键方面需要补充。之前已经通过web_search获取了财务、市场和战略的数据接下来可能需要查看国际化进展或竞争环境。\n\n不过根据之前的搜索结果生态系统战略部分已经提到了国际化合作比如与能链智电和华厦眼科的合作以及全球开发者合作。可能用户需要更详细的国际化市场表现比如在印度、欧洲等地区的具体进展。因此我应该调用web_search来搜索“小米 国际化 市场进展 2025”以获取相关信息。\n\n另外检查是否还有其他重要领域未覆盖比如研发投入、创新方向或面临的挑战。但根据现有信息财务数据中的研发投入已经提到未来五年的2000亿元投入生态系统战略中也涵盖了技术突破。可能还需要确认是否有最新的竞争分析或行业挑战的信息但用户的问题主要是分析公司整体情况现有信息可能足够。\n\n如果再搜索国际化进展后整合所有信息应该可以形成全面的分析报告涵盖财务、市场、战略、生态系统和国际化等方面。如果没有遗漏的关键点就可以使用terminate工具结束并给出综合分析",
"tool_calls": [
{
"index": 0,
"id": "call_33fad8e3d8754664b32e28",
"name": "web_search",
"arguments": "{\"query\": \"小米 国际化 市场进展 2025\"}",
"type": "function"
}
],
"timestamp": "2025-06-12 00:19:22.867096",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {}
},
{
"role": "tool",
"content": "tool.0\nname=web_search\narguments={\"query\": \"小米 国际化 市场进展 2025\"}\nresult=根据提供的资料以下是小米在2025年国际化市场进展的相关信息\n\n1. **市场覆盖与份额** \n - 截至2025年小米已进入**73个国家和地区**,在印度市场份额位列第一,并在**9个国家进入市场前三**。(来源:小米创办人雷军微博)\n\n2. **重点区域表现** \n - **印度市场**2024年第二季度小米在印度出货量达670万部市场份额18%重新夺回领先地位但2023年一季度曾因法规风险印度执法局指控违反《外汇管理法》导致出货量下滑38%至500万部市场份额跌至第四。来源小米国际化现状分析\n\n3. **新产品线国际化** \n - 在西班牙巴塞罗那举办的小米15系列全球发布会上小米集团合伙人卢伟冰宣布**计划未来几年将小米汽车销往全球市场**,并同步推进大型家用电器海外布局。(来源:小米国际市场战略资讯)\n\n4. **生态与技术扩展** \n - 小米AIoT平台全球连接设备数**超过8.6亿台**,显示其智能生态在国际市场的渗透力。(来源:小米国际市场战略站长之家)\n\n5. **战略动态** \n - 2025年小米手机市场份额**重返全球第一**具体数据未披露港股表现强劲盘中一度领涨科技股。来源小米集团2025年“开门红”资讯\n\n6. **挑战与应对** \n - 在东南亚市场面临激烈竞争2023年一季度出货量同比下跌37%至250万部需应对文化差异及本地化运营难题。来源小米国际化现状分析\n\n以上信息综合反映了小米在2025年国际化进程中的关键进展与挑战。",
"reasoning_content": "",
"tool_calls": [
{
"index": 0,
"id": "call_33fad8e3d8754664b32e28",
"name": "web_search",
"arguments": "{\"query\": \"小米 国际化 市场进展 2025\"}",
"type": "function"
}
],
"timestamp": "2025-06-12 00:19:44.147342",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {},
"tool_call_id": ""
},
{
"role": "user",
"content": "User's question\n分析一下小米公司\n\nPlan the most suitable tool or combination of tools based on the context and the user's question. \nFor complex tasks, break down the problem and use different tools step by step to solve it, don't give up easily. \nTry calling the same tool multiple times with different parameters to obtain information from various perspectives. \nIf the task is completed and the user's question can now be answered, use the **terminate** tool.\nPlease determine the response language based on the language of the user's question.\n",
"reasoning_content": "",
"tool_calls": [],
"timestamp": "2025-06-12 00:19:44.147762",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {}
},
{
"role": "assistant",
"content": "",
"reasoning_content": "好的用户让我分析小米公司我已经通过多次web_search调用收集了财务数据、全球市场份额、生态系统战略和国际化进展的信息。现在需要整合这些信息形成一个全面的分析报告。\n\n首先财务方面小米2025年Q1营收1113亿元同比增长47.4%净利润107亿元增长64.5%。研发投入增长显著未来五年计划投入2000亿元显示其对技术创新的重视。汽车业务虽然目前亏损但交付量增长迅速可能成为未来增长点。\n\n其次市场表现上小米全球市场份额达14%手机销量1.7亿部,连续多个季度位居全球前三。在印度市场表现强劲,但在东南亚面临挑战,需注意本地化策略。\n\n生态系统战略方面小米的人车家全生态布局深化自研芯片和智能设备扩展IoT连接设备超8.6亿台HyperOS 2.0提升生态协同。与能链智电等合作,增强服务生态,开发者合作也推动生态扩展。\n\n国际化进展中小米进入73个国家印度市场领先计划将汽车推向全球。但需应对不同市场的竞争和法规挑战如印度的外汇管理问题。\n\n综合来看小米在财务健康、市场扩展、技术创新和生态布局上表现强劲但国际化和汽车业务的亏损是潜在风险。需要进一步确认是否有遗漏的信息比如竞争分析或行业趋势但现有数据已足够形成分析。因此可以终止工具调用给出总结。",
"tool_calls": [
{
"index": 0,
"id": "call_0afda0bd611440dca92dda",
"name": "terminate",
"arguments": "{\"status\": \"success\"}",
"type": "function"
}
],
"timestamp": "2025-06-12 00:19:54.299286",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {}
},
{
"role": "tool",
"content": "tool.0\nname=terminate\narguments={\"status\": \"success\"}\nresult=The interaction has been completed with status: success",
"reasoning_content": "",
"tool_calls": [
{
"index": 0,
"id": "call_0afda0bd611440dca92dda",
"name": "terminate",
"arguments": "{\"status\": \"success\"}",
"type": "function"
}
],
"timestamp": "2025-06-12 00:19:54.299959",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {},
"tool_call_id": ""
},
{
"role": "user",
"content": "Please integrate the context and provide a complete answer to the user's question.\nPlease determine the response language based on the language of the user's question.\n\n分析一下小米公司\n",
"reasoning_content": "",
"tool_calls": [],
"timestamp": "2025-06-12 00:19:54.300239",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {}
},
{
"role": "assistant",
"content": "### 小米公司综合分析截至2025年6月 \n\n#### **1. 财务表现** \n- **营收与利润**2025年Q1总营收1113亿元+47.4% YoY净利润107亿元+64.5% YoY创历史新高。 \n- **研发投入**Q1研发投入67亿元+30.1% YoY全年目标300亿元未来五年计划追加2000亿元聚焦芯片、AI、自动驾驶等领域。 \n- **汽车业务**小米SU7系列累计交付25.8万辆Q1毛利率稳定但预计仍亏损1-2亿元处于高投入阶段。 \n\n#### **2. 市场地位** \n- **全球市场份额**2025年手机销量1.7亿部占据全球14%份额每7部手机中有1部为小米连续19个季度稳居全球前三。 \n- **区域表现** \n - **印度市场**市场份额第一2024年Q2出货量670万部18%份额)。 \n - **东南亚与欧洲**:面临激烈竞争,需优化本地化策略。 \n\n#### **3. 生态系统战略** \n- **人车家全生态闭环** \n - 自研芯片如3nm工艺的“玄戒O1”覆盖手机、平板、汽车SU7/YU7及可穿戴设备。 \n - IoT连接设备超8.6亿台HyperOS 2.0提升跨设备协同体验。 \n- **开放合作** \n - 与能链智电合作构建充电网络,与华厦眼科探索智能眼镜医疗应用。 \n - 开放澎湃OS、AI能力赋能全球开发者Vela系统设备超6000万台。 \n\n#### **4. 国际化进展** \n- **市场覆盖**已进入73个国家和地区在9个国家手机市场进入前三。 \n- **战略升级**:计划将小米汽车推向全球,并加速家用电器海外布局。 \n- **挑战**:需应对文化差异、本地化运营及印度等市场的政策风险(如外汇管理法规)。 \n\n#### **5. 潜在风险与机遇** \n- **风险** \n - 汽车业务短期亏损压力; \n - 国际市场竞争加剧(如三星、苹果、华为)及地缘政治影响。 \n- **机遇** \n - 高端化转型2025年高端手机销量同比+43% \n - AIoT与智能汽车赛道增长红利 \n - 澎湃OS全球用户基数扩大月活超6.86亿)。 \n\n#### **总结** \n小米凭借“技术驱动+生态协同”战略已从手机厂商转型为全球领先的智能生态平台。2025年财务健康度提升国际化与汽车业务是核心增长极但需平衡短期投入与长期回报。未来能否持续领跑取决于高端产品竞争力、全球化深度及生态开放程度。",
"reasoning_content": "好的我现在需要帮用户分析小米公司。用户之前已经通过多次搜索获取了2025年的财务数据、全球市场份额、生态系统战略和国际化进展的信息。现在要整合这些信息形成一个全面的分析报告。\n\n首先财务表现方面小米2025年第一季度营收1113亿元同比增长47.4%净利润107亿元增长64.5%。这说明公司的盈利能力在提升尤其是净利润增长显著。研发投入方面Q1投入67亿元全年预计300亿元未来五年2000亿元显示对技术创新的重视。汽车业务虽然亏损但交付量增长快可能成为未来增长点。\n\n接下来是市场地位。小米全球手机销量1.7亿部市场份额14%连续19个季度全球前三。在印度市场领先但东南亚面临挑战需要关注本地化策略。国际化方面进入73个国家计划将汽车推向全球但需应对不同市场的法规和竞争。\n\n生态系统战略方面小米的人车家全生态布局深化自研芯片如玄戒O1IoT设备超8.6亿台HyperOS 2.0提升协同。与能链智电等合作,增强服务生态,开发者合作推动扩展。这些举措增强了用户粘性和生态协同效应。\n\n潜在风险包括国际化中的竞争和法规问题比如印度的外汇管理问题以及汽车业务的高投入和亏损。此外全球经济波动可能影响海外市场的拓展。\n\n综合来看小米在财务、市场、技术和生态方面表现强劲但需注意国际化和汽车业务的风险。未来增长点可能在高端产品、智能汽车和生态扩展。需要确保分析覆盖所有关键点并给出总结。",
"tool_calls": [],
"timestamp": "2025-06-12 00:20:28.622876",
"add_reasoning_content_when_content_is_empty": true,
"metadata": {}
}
]

View file

@ -1,4 +1,5 @@
import datetime
import json
from pathlib import Path
from typing import List
@ -6,6 +7,7 @@ from loguru import logger
from pydantic import Field, BaseModel
from experiencemaker.utils.util_function import load_env_keys
load_env_keys("../../.env")
from experiencemaker.model import OpenAICompatibleBaseLLM
@ -29,6 +31,7 @@ class YourOwnAgent(PromptMixin):
max_steps: int = Field(default=10)
tools: List[BaseTool] = [CodeTool(), DashscopeSearchTool(), TerminateTool()]
prompt_file_path: Path = Path(__file__).parent / "your_own_agent_prompt.yaml"
add_reasoning_content_when_content_is_empty: bool = Field(default=True)
def think(self, context: AgentContext):
now_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
@ -46,7 +49,8 @@ class YourOwnAgent(PromptMixin):
else:
user_prompt = self.prompt_format(prompt_name="next_prompt", query=context.query)
context.messages.append(Message(content=user_prompt))
context.messages.append(Message(content=user_prompt,
add_reasoning_content_when_content_is_empty=self.add_reasoning_content_when_content_is_empty))
logger.info(f"step.{context.current_step} user_prompt={user_prompt}")
if context.has_terminate_tool:
@ -59,6 +63,7 @@ class YourOwnAgent(PromptMixin):
context.has_terminate_tool = True
break
action_msg.add_reasoning_content_when_content_is_empty = self.add_reasoning_content_when_content_is_empty
context.messages.append(action_msg)
action_msg_context: str = action_msg.content + "\n\n" + action_msg.reasoning_content
logger.info(f"step.{context.current_step} action_msg_context={action_msg_context} "
@ -81,7 +86,9 @@ class YourOwnAgent(PromptMixin):
new_tool_call.result = tool.execute(**tool_call.argument_dict)
new_tool_calls.append(new_tool_call)
state_msg = StateMessage(tool_calls=new_tool_calls)
state_msg = StateMessage(tool_calls=new_tool_calls,
add_reasoning_content_when_content_is_empty=self.add_reasoning_content_when_content_is_empty)
state_msg.tool_result_to_content()
context.messages.append(state_msg)
logger.info(f"step.{context.current_step} state_msg_context={state_msg.content}")
@ -100,7 +107,12 @@ class YourOwnAgent(PromptMixin):
if __name__ == "__main__":
agent = YourOwnAgent(llm=OpenAICompatibleBaseLLM(model_name="qwen3-32b", temperature=0.6))
messages = agent.run(query="Analyze Xiaomi Corporation.")
# query = "Analyze Xiaomi Corporation."
query = "分析一下小米公司"
agent = YourOwnAgent(llm=OpenAICompatibleBaseLLM(model_name="qwen3-32b", temperature=0.000001))
messages = agent.run(query=query)
answer = messages[-1].content
logger.info(answer)
with open("messages.jsonl", "w") as f:
f.write(json.dumps([x.model_dump() for x in messages], indent=2, ensure_ascii=False))

View file

@ -52,6 +52,6 @@ class YourOwnAgentEnhanced(YourOwnAgent):
if __name__ == "__main__":
agent = YourOwnAgentEnhanced(workspace_id="w_agent_enhanced",
llm=OpenAICompatibleBaseLLM(model_name="qwen3-32b", temperature=0.6))
llm=OpenAICompatibleBaseLLM(model_name="qwen3-32b", temperature=0.00001))
traj = agent.execute()
logger.info(traj.model_dump_json(indent=2))

View file

@ -9,15 +9,19 @@ role_prompt: |
{query}
next_prompt: |
User's question
User question
{query}
Plan the most suitable tool or combination of tools based on the context and the user's question.
For complex tasks, break down the problem and use different tools step by step to solve it, don't give up easily.
Try calling the same tool multiple times with different parameters to obtain information from various perspectives.
If the task is completed and the user's question can now be answered, use the **terminate** tool.
Please determine the response language based on the language of the user's question.
final_prompt: |
Please integrate the context and provide a complete answer to the user's question:
Please integrate the context and provide a complete answer to the user's question.
Please determine the response language based on the language of the user's question.
User question
{query}

View file

@ -262,6 +262,10 @@ if __name__ == "__main__":
parser.add_argument(f"--{key}", type=str, default=None)
json_keys.append(key)
elif info.annotation in [dict, list]:
logger.warning(f"skip key={key} info.annotation={info.annotation}")
continue
else:
raise NotImplementedError(f"key={key} annotation={info.annotation} is not supported.")

View file

@ -78,6 +78,7 @@ class SimpleAgent(PromptMixin):
new_tool_calls.append(new_tool_call)
state_msg = StateMessage(tool_calls=new_tool_calls)
state_msg.tool_result_to_content()
context.messages.append(state_msg)
logger.info(f"step.{context.current_step} state_msg_context={state_msg.content}")

View file

@ -14,7 +14,8 @@ class BaseSummarizer(BaseModel, ABC):
vector_store: BaseVectorStore | None = Field(default=None)
llm: BaseLLM | None = Field(default=None)
def _extract_experiences(self, trajectories: List[Trajectory], **kwargs) -> List[Experience]:
def _extract_experiences(self, trajectories: List[Trajectory], workspace_id: str = None,
**kwargs) -> List[Experience]:
raise NotImplementedError
def execute(self, trajectories: List[Trajectory], workspace_id: str = None, **kwargs) -> List[Experience]:

View file

@ -16,7 +16,7 @@ class SimpleSummarizer(BaseSummarizer, PromptMixin):
max_retries: int = Field(default=5, description="max retries")
prompt_file_path: Path = Path(__file__).parent / "simple_summarizer_prompt.yaml"
def _extract_trajectory_experience(self, trajectory: Trajectory) -> Experience | None:
def _extract_trajectory_experience(self, trajectory: Trajectory, workspace_id: str) -> Experience | None:
step_content_collector: List[str] = []
for step in trajectory.steps:
@ -47,7 +47,7 @@ class SimpleSummarizer(BaseSummarizer, PromptMixin):
experience_str = get_html_match_content(action_message.content, key="experience")
condition_str = get_html_match_content(action_message.content, key="condition")
if experience_str and condition_str:
return Experience(experience_workspace_id=self.workspace_id,
return Experience(experience_workspace_id=workspace_id,
experience_role=self.llm.model_name,
experience_desc=condition_str,
experience_content=experience_str)
@ -56,10 +56,11 @@ class SimpleSummarizer(BaseSummarizer, PromptMixin):
return None
def _extract_experiences(self, trajectories: List[Trajectory], **kwargs) -> List[Experience]:
def _extract_experiences(self, trajectories: List[Trajectory], workspace_id: str = None,
**kwargs) -> List[Experience]:
experiences: List[Experience] = []
for trajectory in trajectories:
experience: Experience = self._extract_trajectory_experience(trajectory)
experience: Experience = self._extract_trajectory_experience(trajectory, workspace_id=workspace_id)
if experience:
experiences.append(experience)
return experiences

View file

@ -43,6 +43,15 @@ class ToolCall(BaseModel):
"index": self.index,
}
@property
def tool_text_result(self):
return f"""
tool.{self.index}
name={self.name}
arguments={self.arguments}
result={str(self.result)}
""".strip()
class Message(BaseModel):
role: Role = Field(default=Role.USER)
@ -50,11 +59,16 @@ class Message(BaseModel):
reasoning_content: str = Field(default="")
tool_calls: List[ToolCall] = Field(default_factory=list)
timestamp: str = Field(default_factory=lambda: datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"))
add_reasoning_content_when_content_is_empty: bool = Field(default=False)
metadata: dict = Field(default_factory=dict)
@property
def simple_dict(self) -> dict:
result = {"role": self.role.value, "content": self.content}
if self.add_reasoning_content_when_content_is_empty and not self.content:
result["content"] += self.reasoning_content
if self.tool_calls:
result["tool_calls"] = [x.simple_dict for x in self.tool_calls]
return result
@ -68,6 +82,9 @@ class StateMessage(Message):
role: Role = Field(default=Role.TOOL)
tool_call_id: str = Field(default="")
def tool_result_to_content(self):
self.content += "\n\n".join([x.tool_text_result for x in self.tool_calls])
@property
def simple_dict(self) -> dict:
result = super().simple_dict