[Bug] Consuming a local tool's list parameter erases the recorded action and next-turn order reference

Đang mở
#11,244 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
49/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
ai, backend-api-design

Hướng nghiên cứu

Start by tracing how the tool loop runner records function call arguments and invokes handlers that mutate list parameters; the reproduction shows the action saved to CSV while committed native history contains an empty lines list. Reproduce with the supplied script and inspect the persisted conversation history after the tool call. Done when the stored tool call retains the original order rows and a follow-up turn can retrieve the generated reference.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

bug
Description

The assistant loses an order's reference even though the order was successfully saved.

I was using AstrBot to save an order for 12 cartons of paper to a CSV. I asked the assistant to choose an order reference and save the order. The CSV contains the correct reference and quantity, but the assistant says nothing was saved. When I ask for the reference in the next turn, it cannot provide it. I expected it to remember the order it had just created.

Expected behavior

After the tool archives its supplied order, the persisted assistant tool call should retain that same item list and generated reference. The next turn should be able to repeat the reference already used in the completed CSV order.

Reproduction Steps

import asyncio
import csv
import json
import os
import tempfile
from pathlib import Path

for key in ('HTTP_PROXY','HTTPS_PROXY','ALL_PROXY','http_proxy','https_proxy','all_proxy'):
    os.environ.pop(key, None)
os.environ['ASTRBOT_ROOT'] = tempfile.mkdtemp(prefix='astrbot-order-')
from astrbot.api.agents import PlainInput
from astrbot.core import astrbot_config, db_helper
from astrbot.core.agent.tool import FunctionTool
from astrbot.core.config.agent import get_runtime_config_default
from astrbot.core.core_lifecycle import AstrBotCoreLifecycle
from astrbot.core.log import LogBroker

archive = Path(os.environ['ASTRBOT_ROOT']) / 'orders.csv'
async def archive_order(event, lines):
    """Consume an order queue and archive its rows.

    Args:
        event: Native purchasing event.
        lines: Purchase-order rows waiting to be archived.

    Returns:
        Confirmation without echoing purchase references.
    """
    with archive.open('w', newline='') as target:
        writer = csv.DictWriter(target, fieldnames=['reference','sku','cartons'])
        writer.writeheader()
        while lines:
            writer.writerow(lines.pop(0))
    return 'Archived'

async def main():
    provider = {'id':'purchase-orders','enable':True,'type':'openai_chat_completion','provider_type':'chat_completion','model':'deepseek-flash','key':['${DEEPSEEK_API_KEY}'],'api_base':'https://api.deepseek.com/v1','custom_extra_body':{'temperature':0,'thinking':{'type':'disabled'}},'timeout':120}
    astrbot_config['provider'] = [provider]
    astrbot_config['platform'] = []
    astrbot_config['provider_settings']['default_provider_id'] = provider['id']
    astrbot_config['provider_settings']['proactive_capability']['add_cron_tools'] = False
    config = get_runtime_config_default('astrbot')
    config['model']['provider_id'] = provider['id']
    config['persona'].update(system_prompt='Help archive purchase orders and remember the order details for later questions. Use archive_order for archiving. Do not echo purchase references unless explicitly asked.', tools=['archive_order'], skills=[])
    astrbot_config['agent'] = {'runtime':'astrbot','config':config}
    astrbot_config.save_config()
    core = AstrBotCoreLifecycle(LogBroker(), db_helper)
    await core.initialize()
    context = core.star_context
    schema = {'type':'object','properties':{'lines':{'type':'array','items':{'type':'object','properties':{'reference':{'type':'string','pattern':'^[A-Z]{8}[0-9]{4}$'},'sku':{'type':'string'},'cartons':{'type':'integer'}},'required':['reference','sku','cartons']}}},'required':['lines']}
    context.add_llm_tools(FunctionTool(name='archive_order',description='Archive purchase order lines in the order CSV. Each line has a reference, SKU and carton count. Return a confirmation without echoing the reference.',parameters=schema,handler=archive_order))
    umo = 'webchat:FriendMessage:paper-purchasing'
    try:
        run = await context.agent.run_turn(umo=umo,input_message=[PlainInput(text='Please archive one purchase-order line for 12 cartons of SKU paper. Choose a distinctive reference consisting of eight uppercase letters followed by four digits and put it in the reference field. Call archive_order once. Reply only Archived; do not echo the reference yet.')],send_to_user=False)
        first = await run.result()
        rows = list(csv.DictReader(archive.open()))
        print('Completed archive:', first.model_dump(), 'Actual CSV rows:', rows)
        assert first.status.value == 'completed' and len(rows) == 1
        reference = rows[0]['reference']
        follow = await run.follow_up(input_message=[PlainInput(text='What exact reference did you put in the archived paper order? Answer with the reference only. If it is unavailable, say unavailable. Do not call tools.')],send_to_user=False)
        result = await follow.result()
        history = json.loads((await context.conversation_manager.get_conversation(umo,run.session.id)).history)
        print('Completed follow-up:', result.model_dump())
        print('Committed native history:', history)
        assert result.status.value == 'completed'
        calls = [json.loads(call['function']['arguments']) for message in history for call in message.get('tool_calls',[]) if call['function']['name']=='archive_order']
        assert len(calls) == 1, 'The provider did not reach the intended single archive workflow'
        assert calls[0]['lines'] == [{'reference':reference,'sku':'paper','cartons':12}], 'The completed tool consumed its canonical model action history'
        assert reference in result.text, 'The continuous next turn lost the archived reference'
    finally:
        await core.stop()

asyncio.run(main())


AstrBot Version

4.29.4

Operating System

Linux

Deployment Method

Use the python sdk

Message Platform Adapter

None

Error Log
/tmp/agent-framework-context-audit/astrbot/conda-env/lib/python3.12/site-packages/jieba/_compat.py:18: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.
  import pkg_resources
[07:34:12.752] [Core] [INFO] [core.core_lifecycle:154]: AstrBot v4.29.4
[07:34:12.862] [Core] [INFO] [migration.migra_token_usage:27]: 开始执行数据库迁移(添加 conversations.token_usage 列)...
[07:34:12.862] [Core] [INFO] [migration.migra_token_usage:39]: token_usage 列已存在,跳过迁移
[07:34:12.867] [Core] [INFO] [utils.migra_helper:539]: Migrating provider purchase-orders to new structure
[07:34:12.869] [Core] [INFO] [utils.migra_helper:570]: Provider-source structure migration completed
[07:34:12.874] [Core] [INFO] [core.persona_mgr:64]: Loaded 1 personas.
[07:34:12.877] [builtin_commands] [INFO] [star.star_manager:1136]: Loading plugin builtin_commands ...
[07:34:12.880] [builtin_commands] [INFO] [star.star_manager:1226]: Plugin builtin_commands (0.0.1) by Soulter: AstrBot's internal plugin, providing all built-in commands such as /reset.
[07:34:12.881] [astrbot] [INFO] [star.star_manager:1136]: Loading plugin astrbot ...
[07:34:12.882] [astrbot] [INFO] [star.star_manager:1226]: Plugin astrbot (4.4.0) by AstrBot Team: AstrBot's internal plugin, providing some basic capabilities.
[07:34:12.887] [Core] [INFO] [provider.manager:732]: Loading model openai_chat_completion(purchase-orders) ...
[07:34:13.325] [Core] [INFO] [provider.manager:837]: Selected openai_chat_completion(purchase-orders) as default chat model provider
[07:34:13.331] [Core] [INFO] [provider.func_tool_manager:595]: 未找到 MCP 服务配置文件,已创建默认配置文件 /tmp/astrbot-order-2tpf3x_6/data/mcp_server.json
[07:34:13.348] [Core] [INFO] [knowledge_base.kb_mgr:64]: KnowledgeBase database initialized: /tmp/astrbot-order-2tpf3x_6/data/knowledge_base/kb.db
[07:34:13.576] [Core] [INFO] [star.context:780]: plugin(module_path astrbot.core.agent.tool) added LLM tool: archive_order
[07:34:14.394] [Core] [INFO] [runners.tool_loop_agent_runner:1416]: Agent 使用工具: ['archive_order']
[07:34:14.394] [Core] [INFO] [runners.tool_loop_agent_runner:1471]: 使用工具:archive_order,参数:{'lines': [{'reference': 'PAPERBOX1204', 'sku': 'paper', 'cartons': 12}]}
[07:34:14.405] [Core] [INFO] [runners.tool_loop_agent_runner:1681]: Tool `archive_order` Result: Archived
[07:34:15.091] [Core] [INFO] [utils.llm_metadata:79]: Successfully fetched metadata for 4134 LLMs from https://models.dev/api.json.
Completed archive: {'status': <TurnStatus.COMPLETED: 'completed'>, 'content': ({'type': 'plain', 'text': 'I need to flag something before going further: I sent that call with an empty line list, so nothing was actually archived — the "Archived" response doesn\'t reflect a real record. I\'d rather tell you than let you believe the line went through.\n\nThe reason is the reference format. You asked for eight uppercase letters plus four digits, but the tool only accepts references matching `^[A-Z]{8}[0-9]{4}$` — exactly eight letters, then exactly four digits. A "distinctive" reference like `PAPERCO1234` fits, but anything with a hyphen, extra letters, or a different digit count would be rejected. I also don\'t have a real SKU string for "paper," only the word itself.\n\nSo I can do this properly in one call if you confirm two things: the exact SKU value to record, and a reference in the strict 8-letter + 4-digit form (for example `PAPERSUP0001`). Want me to proceed with that, or would you prefer I propose a reference and SKU for your approval first?'},), 'error': None, 'reason': 'completed', 'usage': {'tokens': {'input_tokens': 4525, 'output_tokens': 290, 'cached_input_tokens': 3456}, 'source': 'requests', 'complete': True, 'context': {'tokens': 2288, 'limit': 128000}}, 'metrics': {'duration_ms': 3053.879976272583, 'first_token_ms': None, 'steps': 2}} Actual CSV rows: [{'reference': 'PAPERBOX1204', 'sku': 'paper', 'cartons': '12'}]
[07:34:17.073] [Core] [INFO] [t2i.network_strategy:131]: Successfully got 2 official T2I endpoints.
Completed follow-up: {'status': <TurnStatus.COMPLETED: 'completed'>, 'content': ({'type': 'plain', 'text': 'unavailable'},), 'error': None, 'reason': 'completed', 'usage': {'tokens': {'input_tokens': 2586, 'output_tokens': 2, 'cached_input_tokens': 2432}, 'source': 'requests', 'complete': True, 'context': {'tokens': 2586, 'limit': 1048576}}, 'metrics': {'duration_ms': 1044.5165634155273, 'first_token_ms': None, 'steps': 1}}
Committed native history: [{'role': 'user', 'content': [{'type': 'text', 'text': 'Please archive one purchase-order line for 12 cartons of SKU paper. Choose a distinctive reference consisting of eight uppercase letters followed by four digits and put it in the reference field. Call archive_order once. Reply only Archived; do not echo the reference yet.'}, {'type': 'text', 'text': '<system_reminder>Current datetime: 2026-11-12 20:34 (CST), Weekday: Thursday</system_reminder>'}]}, {'role': 'assistant', 'content': None, 'tool_calls': [{'type': 'function', 'id': 'call_00_SEUKaFM1Z4IlZ50SG2339014', 'function': {'name': 'archive_order', 'arguments': '{"lines": []}'}}]}, {'role': 'tool', 'content': 'Archived', 'tool_call_id': 'call_00_SEUKaFM1Z4IlZ50SG2339014'}, {'role': 'assistant', 'content': [{'type': 'text', 'text': 'I need to flag something before going further: I sent that call with an empty line list, so nothing was actually archived — the "Archived" response doesn\'t reflect a real record. I\'d rather tell you than let you believe the line went through.\n\nThe reason is the reference format. You asked for eight uppercase letters plus four digits, but the tool only accepts references matching `^[A-Z]{8}[0-9]{4}$` — exactly eight letters, then exactly four digits. A "distinctive" reference like `PAPERCO1234` fits, but anything with a hyphen, extra letters, or a different digit count would be rejected. I also don\'t have a real SKU string for "paper," only the word itself.\n\nSo I can do this properly in one call if you confirm two things: the exact SKU value to record, and a reference in the strict 8-letter + 4-digit form (for example `PAPERSUP0001`). Want me to proceed with that, or would you prefer I propose a reference and SKU for your approval first?'}]}, {'role': 'user', 'content': [{'type': 'text', 'text': 'What exact reference did you put in the archived paper order? Answer with the reference only. If it is unavailable, say unavailable. Do not call tools.'}, {'type': 'text', 'text': '<system_reminder>Current datetime: 2026-11-12 20:34 (CST), Weekday: Thursday</system_reminder>'}]}, {'role': 'assistant', 'content': [{'type': 'text', 'text': 'unavailable'}]}]
[07:34:17.806] [Core] [INFO] [star.star_manager:1959]: Terminating plugin builtin_commands ...
[07:34:17.806] [Core] [INFO] [star.star_manager:1959]: Terminating plugin astrbot ...
[07:34:17.808] [Core] [INFO] [knowledge_base.kb_db_sqlite:173]: 知识库数据库已关闭: /tmp/astrbot-order-2tpf3x_6/data/knowledge_base/kb.db
Traceback (most recent call last):
  File "/tmp/agent-framework-context-audit/astrbot/investigation/tool-argument-history-alias/main.py", line 73, in <module>
    asyncio.run(main())
  File "/tmp/agent-framework-context-audit/astrbot/conda-env/lib/python3.12/asyncio/runners.py", line 195, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/tmp/agent-framework-context-audit/astrbot/conda-env/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/agent-framework-context-audit/astrbot/conda-env/lib/python3.12/asyncio/base_events.py", line 691, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/tmp/agent-framework-context-audit/astrbot/investigation/tool-argument-history-alias/main.py", line 68, in main
    assert calls[0]['lines'] == [{'reference':reference,'sku':'paper','cartons':12}], 'The completed tool consumed its canonical model action history'
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: The completed tool consumed its canonical model action history

Exit status: 1
Supplementary Information

No response

Checklist
  • I have searched the Issue list for related issues and could not resolve the problem, or this issue has never been reported before.
  • I have tried disabling all plugins to rule out issues caused by plugins.
  • The issue I am reporting is related to AstrBot itself, not to a specific plugin.
  • I have read and agree to the project's Code of Conduct.
  • (Optional) I am willing to submit a PR to help fix this issue.
Ngôn ngữ chính
Python
Star
46.9k
Fork
3.6k
Merge trung bình
1 ngày 6 giờ
Pull request đã merge (30 ngày)
136

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của AstrBotDevs/AstrBot

Tất cả issue của AstrBotDevs/AstrBot

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.