-
Notifications
You must be signed in to change notification settings - Fork 0
Dev #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This commit updates the `SimpleAgent` and `MemoryAgent` classes to accept `MazeObservation` and `MazeActionSpace` types for improved type safety and clarity. The action space parameter is now flexible, allowing both integer and `MazeActionSpace` inputs. Additionally, the `get_observation` method in `MazeEnvironment` is modified to return a `MazeObservation` object. Unused optimal path code in `main_demo.py` is commented out to streamline the demo setup. New agent base class and additional agent files are introduced for future implementations.
This commit introduces the `AlgoAgent` and `MemoryAlgoAgent` classes, which implement pathfinding algorithms (BFS and DFS) for navigating a maze environment. The `AlgoAgent` class handles action selection based on observations and maintains a demo path for scripted actions. The `MemoryAlgoAgent` extends this functionality by integrating memory management through a `MemorySpace`, allowing it to retrieve similar states and actions from memory. Both classes utilize `MazeObservation` and `MazeActionSpace` for improved type safety and flexibility in action handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request improves agents’ type safety, flexible action space handling, and memory management while cleaning up the module structure. Key changes include:
- Enhancements to type safety by replacing dict-based observations with the MazeObservation type and accepting both int and MazeActionSpace for the action_space parameter.
- Updates to memory management by renaming memory_space to memory and refactoring memory-related method calls.
- Code simplification in agent constructors and module structure improvements through updated init.py files.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| memory/space.py | Added a comment to mark future similarity search strategy updates; no functional changes. |
| memory/api/models.py | Introduced MazeObservation and MazeActionSpace models for improved type safety. |
| maze.py | Updated get_observation and added get_action_space method to return strongly typed models. |
| main_demo.py | Commented out obsolete demo path and optimal path calls. |
| agents/random_agent.py | Updated RandomAgent constructor to allow both int and MazeActionSpace; minor exception handling. |
| agents/q_agent.py | Refactored methods to use MazeObservation and updated Q-learning state key handling. |
| agents/deep_q_agent.py | Added DeepQAgent using PyTorch with updated type annotations and device flexibility. |
| agents/base.py | Minimal abstract class update for agents ensuring type consistency. |
| agents/algo_agent.py | Updated AlgoAgent to leverage MazeObservation and integrated memory-based techniques. |
| agents/init.py | Improved module structure by centralizing Agent import. |
| agents.py | Refactored SimpleAgent to integrate new observation types and updated memory method usage. |
| threshold: float = 0.6, | ||
| context_weights: Dict[str, float] = None, | ||
| ) -> List[Dict[str, Any]]: | ||
| #! Needs to be updated to use the SimilaritySearch strategy |
Copilot
AI
May 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider creating a tracking issue or ticket for implementing the SimilaritySearch strategy and remove or update this comment once done to avoid leaving temporary notes in production code.
| #! Why do I need this? | ||
| optimal_path = create_optimal_path_for_maze(maze_size) | ||
| # optimal_path = create_optimal_path_for_maze(maze_size) | ||
|
|
Copilot
AI
May 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the optimal_path and related demo path calls are no longer required, consider removing these commented-out lines to prevent confusion and improve code clarity.
| except Exception: | ||
| pass |
Copilot
AI
May 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of silently passing on all exceptions, consider logging the exception details to aid in debugging unexpected issues.
| except Exception: | |
| pass | |
| except Exception as e: | |
| logging.error("An error occurred while retrieving similar states from memory.", exc_info=True) |
This pull request introduces significant updates to the
agents.pyfile, focusing on enhancing type safety, improving flexibility for handling action spaces, and updating memory management. The changes also include minor updates to theagents/__init__.pyfile to improve module structure.Type Safety and Action Space Enhancements:
action_spaceparameter inSimpleAgent,MemoryAgent, andRandomAgentto accept either an integer or aMazeActionSpaceobject, improving flexibility. Relevant logic was added to handle both types. ([[1]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL30-R26),[[2]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL40-R77),[[3]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL170-R176),[[4]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL180-R186),[[5]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL478-R488))dict-based observations with theMazeObservationtype for better type safety and readability across methods like_get_state_key,select_action,act, andupdate_q_value. ([[1]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL40-R77),[[2]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL101-R117),[[3]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL137-R158),[[4]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL216-R242),[[5]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL254-R271),[[6]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL363-R387),[[7]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL400-R423))Memory Management Updates:
memory_spacewithmemoryinMemoryAgentto align with updated memory handling. Updated method calls likestore_state,retrieve_similar_states,store_action, andstore_interactionto use the newmemoryobject. ([[1]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL216-R242),[[2]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL254-R271),[[3]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL274-R291),[[4]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL363-R387),[[5]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL422-R446),[[6]](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL446-R456))Code Simplification and Refactoring:
agents.pyby collapsing multi-line imports and adding new imports forMazeActionSpaceandMazeObservation. ([agents.pyL15-R17](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL15-R17))SimpleAgentconstructor to dynamically set additional attributes fromkwargs, improving extensibility. ([agents.pyL40-R77](https://github.com/Dooders/AgentMemory/pull/163/files#diff-4a914501b35179c2753ed3fdba121c6aa2f772a6412d3d878192e3cffd89072fL40-R77))Module Structure Improvement:
Agenttoagents/__init__.pyto improve the module's import structure. ([agents/__init__.pyR1](https://github.com/Dooders/AgentMemory/pull/163/files#diff-e120a62e2e20403a2eaaab85d7ce62dc210fb4789776690058b959fc7a09fecbR1))