Skip to content

Commit 16fb96c

Browse files
github-actions[bot]MervinPraisonclaude
committed
fix: Add missing increment_state method and improve chat history persistence
- Add increment_state method (lines 356-359) for numeric state management - Fix empty chat history save condition to track agent existence properly - Improve robustness by checking agent is not None before accessing chat_history - Enhance memory persistence by saving even empty chat histories to track agent state 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Mervin Praison <MervinPraison@users.noreply.github.com> Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1861d9f commit 16fb96c

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/praisonai-agents/praisonaiagents/session.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,11 @@ def _save_agent_chat_histories(self) -> None:
325325

326326
for agent_key, agent_data in self._agents.items():
327327
agent = agent_data["agent"]
328-
if hasattr(agent, 'chat_history') and agent.chat_history:
328+
if agent is not None and hasattr(agent, 'chat_history'):
329329
# Update the tracked chat history
330330
agent_data["chat_history"] = agent.chat_history
331331

332-
# Save to memory
332+
# Save to memory (save even if empty to track agent existence)
333333
history_text = f"Agent chat history for {agent_key}"
334334
self.memory.store_short_term(
335335
text=history_text,
@@ -353,6 +353,11 @@ def set_state(self, key: str, value: Any) -> None:
353353
current_state[key] = value
354354
self.save_state(current_state)
355355

356+
def increment_state(self, key: str, increment: int = 1, default: int = 0) -> None:
357+
"""Increment a numeric state value"""
358+
current_value = self.get_state(key, default)
359+
self.set_state(key, current_value + increment)
360+
356361
def add_memory(self, text: str, memory_type: str = "long", **metadata) -> None:
357362
"""
358363
Add information to session memory.

0 commit comments

Comments
 (0)