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

agentic flow history use seperate collection {bot}_agent and routes c… #1802

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

hasinaxp
Copy link
Contributor

@hasinaxp hasinaxp commented Feb 12, 2025

…orresponding to fetching

Summary by CodeRabbit

  • New Features

    • Introduced new endpoints that allow users to retrieve conversation history related to agentic flows by date range and user identifier.
    • Enhanced conversation data organization for improved accuracy in data retrieval.
  • Tests

    • Expanded test coverage to ensure reliable operation of the new conversation retrieval features.

Copy link

coderabbitai bot commented Feb 12, 2025

Walkthrough

This pull request introduces new FastAPI endpoints for retrieving agentic flow conversation data. Both general and user-specific retrieval functions are added in two router modules. Updates ensure that date parameters are validated and the collection names in MongoDB now include an "_agent" suffix. Additionally, integration and unit tests have been extended to cover the new endpoints and modified collection access. These changes enhance the API's ability to serve agentic flow conversation histories without altering existing functionalities.

Changes

File(s) Change Summary
kairon/.../routers/history.py
kairon/.../router/conversations.py
Added new endpoints for agentic flow conversation retrieval (general and user-specific) with date range validation and dynamic collection naming.
kairon/.../agent/agent_flow.py Modified log_chat_history to append "_agent" to the MongoDB collection name for storing conversation data.
tests/integration_test/history_client_test.py
tests/integration_test/history_services_test.py
tests/unit_test/agentic_flow_test.py
Introduced new test functions to verify agentic flow endpoints and validate the updated collection naming and query behavior.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Router
    participant History_Server
    Client->>API_Router: GET /agentic_flow (from_date, to_date, collection)
    API_Router->>History_Server: Request flattened conversation data
    History_Server-->>API_Router: Return conversation data
    API_Router-->>Client: Respond with agentic flow conversations
Loading
sequenceDiagram
    participant Client
    participant API_Router
    participant History_Server
    Client->>API_Router: GET /agentic_flow/user/{sender} (from_date, to_date, collection)
    API_Router->>History_Server: Request user-specific conversation data
    History_Server-->>API_Router: Return user conversation data
    API_Router-->>Client: Respond with user agentic flow conversation history
Loading

Possibly related PRs

Suggested reviewers

  • sfahad1414

Poem

I hop through lines of vibrant code,
Where agentic flows in endpoints showed.
With "_agent" tags and tests in tow,
My bunny heart leaps as features grow.
Bugs are nibbled and bytes delight,
In a meadow of code by day and night!
🐰💻

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

kairon/history/router/conversations.py Dismissed Show dismissed Hide dismissed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
tests/integration_test/history_client_test.py (1)

135-138: Use context manager for file handling.

Use a context manager (with statement) to ensure proper file handling and resource cleanup.

-def history_conversations_agent(*args, **kwargs):
-    json_data = json.load(open("tests/testing_data/history/conversation_history_agent.json"))
-    return json_data, None
+def history_conversations_agent(*args, **kwargs):
+    with open("tests/testing_data/history/conversation_history_agent.json") as file:
+        json_data = json.load(file)
+    return json_data, None
🧰 Tools
🪛 Ruff (0.8.2)

136-136: Use a context manager for opening files

(SIM115)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e420b3d and 89725b0.

📒 Files selected for processing (6)
  • kairon/api/app/routers/history.py (1 hunks)
  • kairon/history/router/conversations.py (1 hunks)
  • kairon/shared/chat/agent/agent_flow.py (1 hunks)
  • tests/integration_test/history_client_test.py (2 hunks)
  • tests/integration_test/history_services_test.py (2 hunks)
  • tests/unit_test/agentic_flow_test.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • kairon/shared/chat/agent/agent_flow.py
🧰 Additional context used
🪛 Ruff (0.8.2)
kairon/api/app/routers/history.py

295-295: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


296-296: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


297-297: Do not perform function call Security in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


311-311: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


312-312: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


313-313: Do not perform function call Security in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)

kairon/history/router/conversations.py

31-31: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


32-32: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


44-44: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


45-45: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)

tests/integration_test/history_client_test.py

136-136: Use a context manager for opening files

(SIM115)

tests/integration_test/history_services_test.py

1139-1139: Use a context manager for opening files

(SIM115)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Python CI
  • GitHub Check: Analyze (python)
🔇 Additional comments (10)
kairon/history/router/conversations.py (2)

29-39: LGTM! Clean implementation of the agentic flow conversations endpoint.

The implementation follows the established pattern and correctly appends "_agent" to the collection name.

🧰 Tools
🪛 Ruff (0.8.2)

31-31: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


32-32: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


41-50: LGTM! Clean implementation of the user-specific agentic flow history endpoint.

The implementation follows the established pattern and correctly appends "_agent" to the collection name.

🧰 Tools
🪛 Ruff (0.8.2)

44-44: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


45-45: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)

tests/unit_test/agentic_flow_test.py (1)

455-456: Verify if removing the tag filter is intentional.

The test now retrieves all documents from the collection without filtering by "tag". Please confirm if this change is intentional and doesn't affect the test's validity.

kairon/api/app/routers/history.py (2)

293-306: LGTM! Clean implementation of the agentic flow conversations endpoint.

The implementation follows the established pattern and correctly validates date ranges before triggering the history server request.

🧰 Tools
🪛 Ruff (0.8.2)

295-295: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


296-296: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


297-297: Do not perform function call Security in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


308-322: LGTM! Clean implementation of the user-specific agentic flow history endpoint.

The implementation follows the established pattern and correctly validates date ranges before triggering the history server request.

🧰 Tools
🪛 Ruff (0.8.2)

311-311: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


312-312: Do not perform function call Depends in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


313-313: Do not perform function call Security in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)

tests/integration_test/history_services_test.py (3)

1144-1155: LGTM! Good test coverage for empty agentic flow conversations.

The test verifies the response structure and empty data case correctly.


1159-1171: LGTM! Good test coverage for agentic flow conversations.

The test verifies the response structure and data count correctly.


1175-1188: LGTM! Good test coverage for user-specific agentic flow conversations.

The test verifies the response structure, data count, and sender ID correctly.

tests/integration_test/history_client_test.py (2)

1556-1578: LGTM!

The test is well-structured and follows the established patterns. It properly mocks the HTTP response and includes comprehensive assertions to verify the response data.


1581-1602: LGTM!

The test is well-structured and follows the established patterns. It properly mocks the HTTP response and includes comprehensive assertions to verify both the response data and the sender ID.

Copy link
Collaborator

@sfahad1414 sfahad1414 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved

@sfahad1414 sfahad1414 merged commit 4fe713c into digiteinfotech:master Feb 12, 2025
7 checks passed
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.

2 participants