Skip to content

fix(agent): wire up agent persistence and fix broken logger import - #235

Open
rhiannalitchfield wants to merge 1 commit into
TuGraph-family:masterfrom
rhiannalitchfield:fix/agent-persistence-wiring
Open

fix(agent): wire up agent persistence and fix broken logger import#235
rhiannalitchfield wants to merge 1 commit into
TuGraph-family:masterfrom
rhiannalitchfield:fix/agent-persistence-wiring

Conversation

@rhiannalitchfield

Copy link
Copy Markdown

Summary

Closes #40.

#234 added the AgentDao/AgentDo persistence layer to address #40, but two gaps meant agents were still never actually persisted in practice:

  1. The DAO was never wired into AgentService. set_agent_dao() is defined on AgentService/LeaderState, but nothing in the application ever calls it — AgentWrapper.build(), the actual entry point used to construct Leader/Expert agents, only calls agent_service.set_leadder() / agent_service.add_expert(). So AgentService._agent_dao was always None, and save_agent_config() was never reached.
  2. A broken import. builtin_leader_state.py, agent_dao.py, agent_service.py, reasoner_factory.py, and workflow_factory.py all do from app.utils.logger import logger, but no app/utils/logger.py module exists in this codebase (the rest of the project uses app.core.common.logger.Chat2GraphLogger). This raises ModuleNotFoundError the moment any of these modules are imported, so the persistence code path couldn't even be exercised, tested, or run.

Changes

  • agent_service.py: AgentService.__init__ now grabs the already-initialized AgentDao.instance (the DaoFactory initializes all DAOs before ServiceFactory initializes the services, so it's available by construction time). set_leadder() and add_expert() now call AgentDao.save_agent_config() so agents created via the normal SDK path (AgentWrapper.build()) are actually persisted.
  • Fixed the app.utils.logger import in the 5 affected files to use Chat2GraphLogger.get_logger(__name__), matching the rest of the codebase.
  • Added test/unit/test_agent_persistence.py covering:
    • AgentService.set_leadder() persists the leader via AgentDao
    • AgentService.add_expert() persists the expert via AgentDao
    • AgentDao.save_agent_config() / get_agent_config() round-trip
    • AgentDao.get_leader()

Test plan

  • pytest test/unit/test_agent_persistence.py passes (4/4)
  • Ran the broader test/unit suite (excluding tests that were already broken on master due to the optional/commented-out dbgpt dependency and external services like MemFuse/LLM API access) — no new failures introduced
  • ruff check on the touched files — no new issues (cleaned up the import-sort warnings introduced by this change; pre-existing lint issues in agent_dao.py/workflow_factory.py/reasoner_factory.py from feat(dal): implement persistence for Agent instances in database #234 are left untouched as out of scope for this fix)

Note: I'm a first-time contributor to this project (see discussion on #40) — happy to adjust based on review feedback.

…uGraph-family#40)

PR TuGraph-family#234 added the AgentDao/AgentDo persistence layer for issue TuGraph-family#40, but
left two gaps that meant agents were still never actually persisted:

- AgentService never received the AgentDao instance (set_agent_dao()
  was never called from anywhere in the real app), so _agent_dao was
  always None and set_leadder()/add_expert() never persisted anything.
- builtin_leader_state.py, agent_dao.py, agent_service.py,
  reasoner_factory.py, and workflow_factory.py all import a
  `app.utils.logger` module that does not exist in this codebase,
  raising ModuleNotFoundError as soon as any of them are imported.

This change auto-wires the already-initialized AgentDao singleton into
AgentService on construction, persists the leader/expert configuration
when set_leadder()/add_expert() are called (the path used by
AgentWrapper.build(), the real agent-creation entry point), and fixes
the logger imports to use the existing Chat2GraphLogger.

Adds test/unit/test_agent_persistence.py covering AgentDao
save/round-trip/get_leader behavior and the new AgentService wiring.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@CLAassistant

CLAassistant commented Jun 18, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(dal): implement persistence for Agent instances in database

2 participants