Skip to content

fix(agent): bound data assistant memory usage#3088

Open
weijiandev wants to merge 17 commits into
eosphoros-ai:mainfrom
weijiandev:codex-bound-data-assistant-memory
Open

fix(agent): bound data assistant memory usage#3088
weijiandev wants to merge 17 commits into
eosphoros-ai:mainfrom
weijiandev:codex-bound-data-assistant-memory

Conversation

@weijiandev

Copy link
Copy Markdown

Summary

  • Replace the data assistant ReAct memory cache with a bounded TTL/LRU cache.
  • Protect active streaming conversations from being evicted during SSE responses.
  • Release cached GptsMemory state and executor resources on eviction.
  • Close the Excel data assistant ExcelReader in finally blocks to avoid delayed DuckDB cleanup.

Why

The data assistant previously stored one GptsMemory object per conversation in a process-wide dict without eviction. On long-running deployments with many conversations, this could cause process memory to grow until restart.

The Excel data assistant also relied on __del__() for some cleanup paths, which can delay DuckDB connection release.

Validation

  • ruff check packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/agentic_data_api.py packages/dbgpt-app/src/dbgpt_app/scene/chat_data/chat_excel/excel_analyze/chat.py
  • ruff format --check packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/agentic_data_api.py packages/dbgpt-app/src/dbgpt_app/scene/chat_data/chat_excel/excel_analyze/chat.py
  • python3 -m py_compile packages/dbgpt-app/src/dbgpt_app/openapi/api_v1/agentic_data_api.py packages/dbgpt-app/src/dbgpt_app/scene/chat_data/chat_excel/excel_analyze/chat.py
  • git diff --check

@github-actions github-actions Bot added agent Module: agent fix Bug fixes labels May 27, 2026
weijiandev added 13 commits June 1, 2026 10:43
- Set terminate=True after successful html_interpreter to prevent agent
  from continuing unnecessary work after report is generated
- Lower sql_query todo advance threshold from 3 to 2 calls
- Add more completion markers for sql_query advancement
- Add safety net to force advance after 8 SQL rounds
- Improve fallback output when loop ends without terminate: summarize
  all completed steps instead of showing raw SQL from last step
- All report data must come from sql_query results
- If query returns empty, state '暂无数据' instead of fabricating
- code_interpreter must not hardcode sample/dummy data
- Derived metrics must be labeled as '计算值' with formula
- Emphasize all fields (Thought + Action + Action Input) are REQUIRED
- Add concrete correct/incorrect examples
- Explicitly forbid continuing natural language after Thought
- Clarify Action must be bare tool name without backticks
- Addresses 50% step failure rate due to format errors
The prompt template uses f-string, so curly braces in examples must be
doubled ({{ }}) to avoid ValueError: Invalid format specifier
- Add instruction to always use /tmp/ for html_interpreter file_path
- If other paths needed, create directory first with os.makedirs
- Created /root/.dbgpt/workspace/reports/ on server as backup
When the LLM outputs Action/Action Input mid-line (not at line start),
the strict parser fails with 'No correct response found'. Added a
fallback that:
1. Tries lenient regex match for Action anywhere in text
2. Falls back to lenient match for Action Input extraction
3. Only triggers when strict line-start matching fails

This handles common LLM output patterns like:
'让我查询数据... Action: sql_query Action Input: {...}'
When the agent generates HTML in code_interpreter but forgets to call
html_interpreter to render it, the terminate handler now:
1. Detects HTML content in the final result
2. Checks if html_interpreter was already called
3. If not, writes HTML to /tmp/auto_report.html and renders it
4. Returns the rendered result instead of raw HTML
- Increase max_retry_count from 30 to 50 to give agent more steps
- Add prominent format reminder at the very top of both prompts
- Show forbidden patterns that cause errors (e.g. thinking without Action)
- Show correct pattern example
- Emphasize Chinese output requirement
The agent was outputting 5 sql_query calls in one response, but only
the first one gets executed. Added explicit rule:
- ONE action per response, NEVER output multiple Actions
- After calling todowrite or sql_query, STOP and wait for Observation
- Do NOT write natural language after Action (Observation is system-generated)
The agent's generated code uses os in nested functions/closures, but
os is only imported at module level. Python's closure scoping rules
prevent accessing module-level variables from nested scopes.

Fix: inject os into builtins so it's accessible from any scope.
Same closure scoping issue as code_interpreter - nested functions cannot
access module-level 'os' import. Added 'import os' inside both functions.
@chenliang15405

Copy link
Copy Markdown
Collaborator

Thank you for your contribution. However, the content of the changes significantly deviates from the title of the PR. There are too many changes code, which does not make it a good PR. Please close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Module: agent fix Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants