npi-ai / npi

Action library for AI Agent
https://www.npi.ai
Apache License 2.0
191 stars 7 forks source link

feat(context): introduce memory layer #95

Closed idiotWu closed 3 months ago

idiotWu commented 3 months ago

This PR introduces the memory layer provided by mem0.

Usage

from typing import Annotated
from npiai import FunctionTool, function, FromContext

class MyTool(FunctionTool):
    @function
    def get_test_id(self, test_id: Annotated[int, FromContext(query="test id")]):
        ...

Workflow

Any tool parameter with Annotated[Type, FromContext("<query>", "<constraints">)] type hint will be regarded as a context variable. For such a variable, we will first search the memory using the given query and constraints. If no matches are found, we will invoke HITL to ask human for necessary information and save the result into memory, and then rerun the search process to retrieve memory.

If you use a string template as the query, e.g., "{user} id", we will fill in the templates using LLMs (e.g., "@alice id")

vercel[bot] commented 3 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
npi-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 30, 2024 7:19pm