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

firestore agent storage class #1978

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jeffbryner
Copy link

Description

  • Summary of changes: add a class for storing sessions in firestore
  • Related issues: [Feature Request] Firestore agent session storage #1977
  • Motivation and context: Allows the use of serverless firestore
  • Environment or dependencies: optional dependency on google-cloud-firestore
  • Impact on metrics: Should be minimal, firestore is extremely performant.

Fixes # (issue)
#1977

Type of change

Please check the options that are relevant:

  • New feature (non-breaking change which adds functionality)

Checklist

  • Adherence to standards: Code complies with Agno’s style guidelines and best practices.
  • Formatting and validation: You have run ./scripts/format.sh and ./scripts/validate.sh to ensure code is formatted and linted.
  • Self-review completed: A thorough review has been performed by the contributor(s).
  • Documentation: Docstrings and comments have been added or updated for any complex logic.
  • Examples and guides: Relevant cookbook examples have been included or updated (if applicable).
  • Tested in a clean environment: Changes have been tested in a clean environment to confirm expected behavior.
  • Tests (optional): Tests have been added or updated to cover any new or changed functionality.

@jeffbryner jeffbryner requested a review from a team as a code owner February 2, 2025 00:11
@manthanguptaa
Copy link
Contributor

Can you please add a corresponding cookbook and add the steps to setup firestore and get the required env variables at the top of the cookbook?

@jeffbryner
Copy link
Author

Sure! Should I use this mongo storage as an example?

@manthanguptaa
Copy link
Contributor

Sure! Please go ahead

@jeffbryner
Copy link
Author

jeffbryner commented Feb 6, 2025 via email

Comment on lines +1 to +7
"""
This recipe shows how to store agent sessions in a Firestore database.
Steps:
1. Run: `pip install openai google-cloud-firestore agno` to install dependencies
2. Make sure your gcloud project is set up and you have the necessary permissions to access Firestore
3. Run: `python cookbook/storage/firestore_storage.py` to run the agent
"""
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please add steps to set up gcloud?

Comment on lines +1 to +18
from datetime import datetime, timezone
from typing import List, Optional
from uuid import UUID

try:
from google.cloud import firestore
from google.cloud.firestore import Client
from google.cloud.firestore import CollectionReference
from google.cloud.firestore_v1.base_query import FieldFilter, BaseQuery

except ImportError:
raise ImportError(
"`firestore` not installed. Please install it with `pip install google-cloud-firestore`"
)

from agno.storage.agent.base import AgentStorage
from agno.storage.agent.session import AgentSession
from agno.utils.log import logger
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
from datetime import datetime, timezone
from typing import List, Optional
from uuid import UUID
try:
from google.cloud import firestore
from google.cloud.firestore import Client
from google.cloud.firestore import CollectionReference
from google.cloud.firestore_v1.base_query import FieldFilter, BaseQuery
except ImportError:
raise ImportError(
"`firestore` not installed. Please install it with `pip install google-cloud-firestore`"
)
from agno.storage.agent.base import AgentStorage
from agno.storage.agent.session import AgentSession
from agno.utils.log import logger
from datetime import datetime, timezone
from typing import List, Optional
from uuid import UUID
from agno.storage.agent.base import AgentStorage
from agno.storage.agent.session import AgentSession
from agno.utils.log import logger
try:
from google.cloud import firestore
from google.cloud.firestore import Client
from google.cloud.firestore import CollectionReference
from google.cloud.firestore_v1.base_query import FieldFilter, BaseQuery
except ImportError:
raise ImportError(
"`firestore` not installed. Please install it with `pip install google-cloud-firestore`"
)

def __init__(
self,
collection_name: str,
db_name: Optional[str] = "(default)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
db_name: Optional[str] = "(default)",
db_name: Optional[str] = "agno",

Comment on lines +46 to +54
def create(self) -> None:
"""Create necessary indexes for the collection"""
try:
logger.info(
f"Unnecessary call to create index for '{self.collection_name}'"
)
except Exception as e:
logger.error(f"Error creating indexes for collection: {e}")
raise
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems to be doing nothing at the moment. Is this intentional?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add function signature in all the docstrings

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