Skip to content

wilsonsergio2500/mem0-agent-fastapi

Repository files navigation

Memory Pipeline for AI Agents - Restful API

Imagine an AI agent as a traveler navigating an endless road of conversations and tasks. Without memory, each step it takes is like walking in a fog, forgetting every landmark passed, every lesson learned. But with a memory pipeline, the fog lifts, revealing a well-worn path filled with the wisdom of past journeys. Like a seasoned storyteller who recalls every tale ever told, an AI with memory understands context, adapts to familiarity, and weaves together past interactions to form a richer, more meaningful dialogue. It no longer repeats itself like an amnesiac caught in an eternal loop; instead, it learns, evolves, and refines its responses, making every engagement feel more natural, intelligent, and attuned to the user’s needs.

A memory pipeline could be seamlessly implemented using Mem0, a powerful library designed to enhance AI models by equipping them with recall and contextual awareness. Mem0 acts as the cognitive backbone of rational AI systems, allowing them to store, retrieve, and dynamically update information over time. By integrating Mem0, AI agents transcend from mere pattern-matching machines to context-aware entities capable of meaningful, long-term interactions.

The Ask API in this project serves as a crucial integration point for both chatbots and voice AI agents. Its streamlined configuration ensures a seamless, responsive, and highly interactive AI persona, enabling effortless and frictionless user engagement.

Features

  • Add memory data associated with specific users.
  • Query stored memory data.
  • Ask a question and induce a response from AI agents based on memory data.
  • Remove memories associated with a specific user.

Authorization

API requests require an API Key for security purposes. Include the X-API-KEY header in your requests. Example:

Authorization: X-API-KEY: <your_api_key>

Running the Project Locally

  1. Clone the repository:

    git clone <repository_url>
    cd <repository_name>
  2. Install dependencies:

    pip install -r requirements.txt
  3. Start the server:

    uvicorn main:app --reload
  4. Set up environment variables by creating a .env file:

    OPENAI_API_KEY=your_openai_api_key
    PG_DB=your_postgres_db
    PG_USER=your_postgres_user
    PG_PASSWORD=your_postgres_password
    PG_HOST=your_postgres_host
    AGENT_PERSONA=your_agent_persona
    X_API_KEY=your_api_key
  5. Access the API documentation at http://127.0.0.1:8000/docs.

  6. Replace Docker variables to Deploy the application into Azure App Service (optional).

variables:
   ...
   azureWebAppName: '<<WebAppName>>'
   azureContainerRegistry: '<<ContainerRegistryName>>'
   dockerRegistryServiceConnection: '<<ServiceConnectionName>>'
   azureContainerServer: '<<ContainerServerName>>'
   resourceGroupName: '<<ResourceGroupName>>'
   azureSubscription: '<<SubscriptionName>>'
   tag: '$(Build.BuildId)'
   ...

Tools and Technologies

  • FastAPI for building the REST API.
  • Python as the programming language.
  • PostgreSQL or similar database systems (if applicable).
  • Requests for making API calls during testing or development.
  • Pydantic for request and response data validation.

License

This project is licensed under the MIT License. You are free to use, modify, and distribute it, provided that proper credit is given.


Note: Update the {{baseUrl}} with the actual API base URL.

About

FastAPI-based RESTful API layer for integrating Mem0 agents into applications.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published