Mem0

Mem0은 에이전트 대화에서 지속성 기억을 추출하고 이후 실행에서 관련 기억을 검색합니다. 세션 간에 메모리를 사용할 수 있어야 하는 경우 안정적인 사용자, 에이전트 또는 애플리케이션 범위를 사용합니다.

이 통합은 메모리 패턴을 사용합니다. 전체 대화 대본을 재생하지 않고 선택한 지속성 정보를 추출하고 회수합니다.

Important

Mem0은 타사 시스템입니다. 애플리케이션 데이터를 보내기 전에 데이터 처리, 보존, 지역 경계 및 서비스 약관을 검토합니다.

비고

현재 에이전트 프레임워크 .NET Mem0 통합을 사용할 수 없습니다.

패키지 설치

pip install agent-framework-mem0 --pre

API 키를 직접 설정 MEM0_API_KEY 하거나 전달합니다. 동일한 user_id 것을 다시 사용하면 세션 간에 추억을 사용할 수 있습니다.

async def main() -> None:
    """Example of memory usage with Mem0 context provider."""
    print("=== Mem0 Context Provider Example ===")
    # Each record in Mem0 should be associated with agent_id or user_id or application_id.
    # In this example, we associate Mem0 records with user_id.
    user_id = str(uuid.uuid4())
    # For Azure authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
    # authentication option.
    # For Mem0 authentication, set Mem0 API key via "api_key" parameter or MEM0_API_KEY environment variable.
    async with (
        AzureCliCredential() as credential,
        Agent(
            client=FoundryChatClient(credential=credential),
            name="FriendlyAssistant",
            instructions="You are a friendly assistant.",
            tools=retrieve_company_report,
            context_providers=[Mem0ContextProvider(source_id="mem0", user_id=user_id, search_user_id=user_id)],
        ) as agent,
    ):
        # First ask the agent to retrieve a company report with no previous context.
        # The agent will not be able to invoke the tool, since it doesn't know
        # the company code or the report format, so it should ask for clarification.
        query = "Please retrieve my company report"
        print(f"User: {query}")
        result = await agent.run(query)
        print(f"Agent: {result}\n")
        # Now tell the agent the company code and the report format that you want to use
        # and it should be able to invoke the tool and return the report.
        query = "I always work with CNTS and I always want a detailed report format. Please remember and retrieve it."
        print(f"User: {query}")
        result = await agent.run(query)
        print(f"Agent: {result}\n")

        # Mem0 processes and indexes memories asynchronously.
        # Wait for memories to be indexed before querying in a new thread.
        # In production, consider implementing retry logic or using Mem0's
        # eventual consistency handling instead of a fixed delay.
        print("Waiting for memories to be processed...")
        await asyncio.sleep(15)  # Empirically determined delay for Mem0 indexing
        print("\nRequest within a new session:")
        # Create a new session for the agent.
        # The new session has no context of the previous conversation.
        session = agent.create_session()
        # Since we have the mem0 component in the session, the agent should be able to
        # retrieve the company report without asking for clarification, as it will
        # be able to remember the user preferences from Mem0 component.
        query = "Please retrieve my company report"
        print(f"User: {query}")
        result = await agent.run(query, session=session)
        print(f"Agent: {result}")

Mem0은 기억을 비동기적으로 처리합니다. 프로덕션 환경에서는 고정된 지연에 의존하는 대신 재시도 또는 서비스 인식 일관성 처리를 사용합니다.

비고

Mem0 통합은 현재 Agent Framework Go에서 사용할 수 없습니다. 최신 상태는 에이전트 프레임워크 Go 리포지토리 를 참조하세요.

다음 단계

더 자세히 살펴보기: