Skip to content
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

Enhance Agent Logging: Comprehensive Step, Tool, and Memory Tracking in JSON format #615

Merged
merged 23 commits into from
Oct 29, 2024

Conversation

sambhavnoobcoder
Copy link
Contributor

@sambhavnoobcoder sambhavnoobcoder commented Oct 27, 2024

Problem

The current Agent class lacks detailed logging of each step, tool usage, and memory consumption. This makes it difficult for users to debug and analyze the agent's behavior, especially when dealing with complex tasks.

Solution

We've implemented comprehensive logging for the Agent class, capturing detailed information about each step, tool usage, and memory consumption. The logging system now supports both string and JSON output formats, allowing users to choose the most suitable format for their needs.

Key changes include:

  1. Enhanced step logging in the log_step_metadata method
  2. Detailed tool usage tracking
  3. Memory usage monitoring for both short-term and long-term memory
  4. Option to switch between string and JSON output formats
  5. Updated documentation to reflect new logging capabilities
  6. New unit tests and integration tests to ensure logging functionality

Impact

These changes significantly improve the transparency and debuggability of the Agent class. Users can now:

  • Analyze each step of the agent's decision-making process
  • Track tool usage and effectiveness
  • Monitor memory consumption to optimize performance
  • Choose between human-readable string output or machine-parseable JSON format

Final Results

With these changes, users can now:

  1. Get detailed logs of each step in the agent's process
  2. Track tool usage and performance
  3. Monitor memory consumption
  4. Choose between string and JSON output formats
  5. Easily debug and analyze agent behavior

The enhanced logging system provides valuable insights into the agent's decision-making process, making it easier for developers to optimize and troubleshoot their AI applications.

Videos And Screenshots

You can find the video of the code explaination , walkthrough , demos , unittests etc here : https://drive.google.com/file/d/1IsL288KWy5IyZ6bKJiEKpWyDAbNomFvH/view?usp=sharing

A small glimpse of all testcases successfully passing including the integration test is as follows :
Screenshot 2024-10-28 at 12 00 51 AM
The first 5 here are indications of successful unittests and the 6th is the successful integration test .

Additional Notes

  • Documentation has been updated to reflect these changes
  • New unit tests and integration tests have been added to ensure the reliability of the logging system
  • The changes are backwards-compatible, allowing existing users to opt-in to the new logging features

📚 Documentation preview 📚: https://swarms--615.org.readthedocs.build/en/615/

- added asdict to turn things into json compatible output
- adding updated log methods to run
- make the run update for tools
- edit "run" return type with condition on how to return if output type is JSON .
- add newer methods to the log_step_metadata for logging
- update tool usage fn to add and account for tool usage metadata.
- minor refactor
- update correct libraries & dependencies .
- create class to execute modular unittests 
- def setup for modular setup 
- objective to keep setup minimal , so that tests aren't bloated and fast to run
- Since most param have a set default , init of necessary condition is a valid and supportive op wrt test speed .
- Implemented test_log_step_metadata_basic to verify the correct logging of step metadata including step_id, timestamp, tokens, and memory usage.
- Confirmed that the token counts for total are accurately logged.
- Implemented test_log_step_metadata_no_long_term_memory to ensure that when long-term memory is None, the memory_usage for long_term is an empty dictionary in the log result.
- Implemented test_log_step_metadata_timestamp to verify that a timestamp is included in the log result when logging step metadata.
- Implemented test_token_counting_integration to verify the correct total token count when using a mocked tokenizer, ensuring that prompt and response token counts are accurately aggregated.
- Implemented test_agent_output_updating to verify that logging step metadata correctly updates the total token count and ensures that the agent's output steps are properly tracked confirming only one step is recorded.
- apart of modular and small unittests , its time to put to test for larger and more wholesome integration test
- an end to end test , to check if this change in code causes any breaks in flow and normal functioning .
- add main to make this run
- Update the docs to return describe changes 
- Add lines specific to how to toggle between output types .
@github-actions github-actions bot added documentation Improvements or additions to documentation tests structs labels Oct 27, 2024
@kyegomez kyegomez merged commit 65977d5 into kyegomez:master Oct 29, 2024
4 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation structs tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants